<commit_before><?php

namespace Northstar\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Contracts\Auth\Factory as Auth;
use Northstar\Auth\Registrar;
use Northstar\Exceptions\NorthstarValidationException;
use Northstar\Models\User;

class WebController extends BaseController
{
    use ValidatesRequests;

    /**
     * The authentication factory.
     *
     * @var \Illuminate\Contracts\Auth\Factory
     */
    protected $auth;

    /**
     * The registrar.
     *
     * @var Registrar
     */
    protected $registrar;

    /**
     * Make a new WebController, inject dependencies,
     * and set middleware for this controller's methods.
     *
     * @param \Illuminate\Contracts\Auth\Factory $auth
     * @param Registrar $registrar
     */
    public function __construct(Auth $auth, Registrar $registrar)
    {
        $this->auth = $auth;
        $this->registrar = $registrar;

        $this->middleware('auth:web', ['only' => ['home']]);
        $this->middleware('guest:web', ['except' => ['home', 'getLogout']]);
    }

    /**
     * Show the homepage.
     *
     * @return \Illuminate\Http\Response
     */
    public function home()
    {
        return view('home', ['user' => auth()->guard('web')->user()]);
    }

    /**
     * Show the login form.
     *
     * @return \Illuminate\Http\Response
     */
    public function getLogin()
    {
        return view('login');
    }

    /**
     * Handle submissions of the login form.
     *
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function postLogin(Request $request)
    {
        $this->validate($request, [
            'username' => 'required',
            'password' => '<PASSWORD>',
        ]);

        $credentials = $request->only('username', 'password');
        if (! $this->auth->guard('web')->attempt($credentials, true)) {
            return redirect()->back()
                ->withInput($request->only('username'))
                ->withErrors(['username' => 'These credentials do not match our records.']);
        }

        // If we had stored a destination name, reset it.
        session()->pull('destination');

        return redirect()->intended('/');
    }

    /**
     * Log a user out from Northstar, preventing one-click
     * sign-ons to other DoSomething.org websites.
     *
     * @param Request $request
     * @return \Illuminate\Http\Response
     */
    public function getLogout(Request $request)
    {
        // A custom post-logout redirect can be specified with `/logout?redirect=`
        $redirect = $request->query('redirect', 'login');

        $this->auth->guard('web')->logout();

        return redirect($redirect);
    }

    /**
     * Display the registration form.
     *
     * @return \Illuminate\Http\Response
     */
    public function getRegister()
    {
        return view('register');
    }

    /**
     * Handle submissions of the registration form.
     *
     * @param Request $request
     * @return \Illuminate\Http\Response
     * @throws NorthstarValidationException
     */
    public function postRegister(Request $request)
    {
        // If a user exists but has not set a password yet, allow them to
        // "register" to set a new password on their account.
        $existing = $this->registrar->resolve($request);
        if ($existing && $existing->hasPassword()) {
            throw new NorthstarValidationException(['email' => 'A user with that email or mobile has already been registered.']);
        }

        $this->registrar->validate($request, $existing, [
            'first_name' => 'required',
            'birthdate' => 'required|date',
            'password' => '<PASSWORD>',
        ]);

        // Register and login the user.
        $user = $this->registrar->register($request->except(User::$internal), $existing);
        $this->auth->guard('web')->login($user, true);

        return redirect()->intended('/');
    }
}<commit_msg>Cleaning up and moving profile related methods to dedicated Web\UsersController.<commit_after><?php

namespace Northstar\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Contracts\Auth\Factory as Auth;
use Northstar\Auth\Registrar;
use Northstar\Exceptions\NorthstarValidationException;
use Northstar\Models\User;

class WebController extends BaseController
{
    use ValidatesRequests;

    /**
     * The authentication factory.
     *
     * @var \Illuminate\Contracts\Auth\Factory
     */
    protected $auth;

    /**
     * The registrar.
     *
     * @var Registrar
     */
    protected $registrar;

    /**
     * Make a new WebController, inject dependencies,
     * and set middleware for this controller's methods.
     *
     * @param \Illuminate\Contracts\Auth\Factory $auth
     * @param Registrar $registrar
     */
    public function __construct(Auth $auth, Registrar $registrar)
    {
        $this->auth = $auth;
        $this->registrar = $registrar;

        $this->middleware('auth:web', ['only' => ['show', 'edit']]);
        $this->middleware('guest:web', ['only' => ['getLogin', 'postLogin', 'getRegister', 'postRegister']]);
    }

    /**
     * Show the login form.
     *
     * @return \Illuminate\Http\Response
     */
    public function getLogin()
    {
        return view('auth.login');
    }

    /**
     * Handle submissions of the login form.
     *
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function postLogin(Request $request)
    {
        $this->validate($request, [
            'username' => 'required',
            'password' => '<PASSWORD>',
        ]);

        $credentials = $request->only('username', 'password');
        if (! $this->auth->guard('web')->attempt($credentials, true)) {
            return redirect()->back()
                ->withInput($request->only('username'))
                ->withErrors(['username' => 'These credentials do not match our records.']);
        }

        // If we had stored a destination name, reset it.
        session()->pull('destination');

        return redirect()->intended('/');
    }

    /**
     * Log a user out from Northstar, preventing one-click
     * sign-ons to other DoSomething.org websites.
     *
     * @param Request $request
     * @return \Illuminate\Http\Response
     */
    public function getLogout(Request $request)
    {
        // A custom post-logout redirect can be specified with `/logout?redirect=`
        $redirect = $request->query('redirect', 'login');

        $this->auth->guard('web')->logout();

        return redirect($redirect);
    }

    /**
     * Display the registration form.
     *
     * @return \Illuminate\Http\Response
     */
    public function getRegister()
    {
        return view('auth.register');
    }

    /**
     * Handle submissions of the registration form.
     *
     * @param Request $request
     * @return \Illuminate\Http\Response
     * @throws NorthstarValidationException
     */
    public function postRegister(Request $request)
    {
        // If a user exists but has not set a password yet, allow them to
        // "register" to set a new password on their account.
        $existing = $this->registrar->resolve($request);
        if ($existing && $existing->hasPassword()) {
            throw new NorthstarValidationException(['email' => 'A user with that email or mobile has already been registered.']);
        }

        $this->registrar->validate($request, $existing, [
            'first_name' => 'required',
            'birthdate' => 'required|date',
            'password' => '<PASSWORD>',
        ]);

        // Register and login the user.
        $user = $this->registrar->register($request->except(User::$internal), $existing);
        $this->auth->guard('web')->login($user, true);

        return redirect()->intended('/');
    }
}
{'fraction_non_alphanumeric': 0.14058060531192093, 'fraction_numerical': 0.0, 'mean_word_length': 2.38744769874477, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 90, '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': '3417129', 'n_tokens_mistral': 2212, 'n_tokens_neox': 2218, 'n_words': 550}