<commit_before><?php

namespace Stevebauman\Maintenance\Http\Controllers;

use Stevebauman\Maintenance\Http\Requests\Auth\RegisterRequest;
use Stevebauman\Maintenance\Http\Requests\Auth\LoginRequest;
use Stevebauman\Maintenance\Services\ConfigService;
use Stevebauman\Maintenance\Services\SentryService;
use Stevebauman\Maintenance\Services\UserService;
use Stevebauman\Maintenance\Services\LdapService;
use Stevebauman\Maintenance\Services\AuthService;

/**
 * Class AuthController.
 */
class AuthController extends Controller
{
    /**
     * @var ConfigService
     */
    protected $config;

    /**
     * @var SentryService
     */
    protected $sentry;

    /**
     * @var UserService
     */
    protected $user;

    /**
     * @var AuthService
     */
    protected $auth;

    /**
     * @var LdapService
     */
    protected $ldap;

    /**
     * Constructor.
     *
     * @param ConfigService     $config
     * @param SentryService     $sentry
     * @param UserService       $user
     * @param AuthService       $auth
     * @param LdapService       $ldap
     */
    public function __construct(
        ConfigService $config,
        SentryService $sentry,
        UserService $user,
        AuthService $auth,
        LdapService $ldap
    ) {
        $this->config = $config->setPrefix('maintenance');
        $this->sentry = $sentry;
        $this->user = $user;
        $this->auth = $auth;
        $this->ldap = $ldap;
    }

    /**
     * Displays the login page.
     *
     * @return \Illuminate\View\View
     */
    public function getLogin()
    {
        return view('maintenance::auth.login.index');
    }

    /**
     * Processes logging in a user.
     *
     * @param LoginRequest $request
     *
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
     */
    public function postLogin(LoginRequest $request)
    {
        $credentials = $request->all();

        // Check if LDAP authentication is enabled
        if ($this->config->get('site.ldap.enabled') === true) {
            $user = $this->ldapAuthenticate($credentials);

            if(is_a($user, 'Cartalyst\Sentry\Users\Eloquent\User')) {
                $credentials['email'] = $user->email;
            }
        }

        // Authenticate with sentry
        $response = $this->auth->sentryAuthenticate(
            array_only($credentials, ['email', 'password']),
            (array_key_exists('remember', $credentials) ? $credentials['remember'] : null)
        );

        // Check the authenticated response
        if ($response['authenticated'] === true) {
            // Successfully logged in
            $message = 'Successfully logged in.';<commit_msg>Small auth tweaks<commit_after><?php

namespace Stevebauman\Maintenance\Http\Controllers;

use Stevebauman\Maintenance\Models\User;
use Stevebauman\Maintenance\Http\Requests\Auth\RegisterRequest;
use Stevebauman\Maintenance\Http\Requests\Auth\LoginRequest;
use Stevebauman\Maintenance\Services\ConfigService;
use Stevebauman\Maintenance\Services\SentryService;
use Stevebauman\Maintenance\Services\UserService;
use Stevebauman\Maintenance\Services\LdapService;
use Stevebauman\Maintenance\Services\AuthService;

class AuthController extends Controller
{
    /**
     * @var ConfigService
     */
    protected $config;

    /**
     * @var SentryService
     */
    protected $sentry;

    /**
     * @var UserService
     */
    protected $user;

    /**
     * @var AuthService
     */
    protected $auth;

    /**
     * @var LdapService
     */
    protected $ldap;

    /**
     * Constructor.
     *
     * @param ConfigService     $config
     * @param SentryService     $sentry
     * @param UserService       $user
     * @param AuthService       $auth
     * @param LdapService       $ldap
     */
    public function __construct(
        ConfigService $config,
        SentryService $sentry,
        UserService $user,
        AuthService $auth,
        LdapService $ldap
    ) {
        $this->config = $config->setPrefix('maintenance');
        $this->sentry = $sentry;
        $this->user = $user;
        $this->auth = $auth;
        $this->ldap = $ldap;
    }

    /**
     * Displays the login page.
     *
     * @return \Illuminate\View\View
     */
    public function getLogin()
    {
        return view('maintenance::auth.login.index');
    }

    /**
     * Processes logging in a user.
     *
     * @param LoginRequest $request
     *
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
     */
    public function postLogin(LoginRequest $request)
    {
        $credentials = $request->only(['email', 'password', 'remember']);

        // Check if LDAP authentication is enabled
        if ($this->config->get('site.ldap.enabled') === true) {
            $user = $this->ldapAuthenticate($credentials);

            if($user instanceof User) {
                $credentials['email'] = $user->email;
            }
        }

        // Authenticate with sentry
        $response = $this->auth->sentryAuthenticate(
            array_only($credentials, ['email', 'password']),
            (array_key_exists('remember', $credentials) ? $credentials['remember'] : null)
        );

        // Check the authenticated response
        if ($response['authenticated'] === true) {
            // Successfully logged in
            $message = 'Successfully logged in.';
{'fraction_non_alphanumeric': 0.1246301775147929, 'fraction_numerical': 0.0, 'mean_word_length': 2.2486486486486488, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2543566', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1560, 'n_words': 304}