<commit_before><?php

namespace Nestor\Http\Controllers;

use \Auth;
use \Validator;

use Illuminate\Http\Request;

use Illuminate\Foundation\Auth\AuthenticatesUsers;

use Dingo\Api\Routing\Helpers;

use Nestor\Http\Controllers\Controller;
use Nestor\Repositories\UsersRepository;

class UsersController extends Controller
{
    use AuthenticatesUsers, Helpers;

    /**
     * The field used as username to authenticate the user.
     *
     * @var string
     */
    protected $username = 'username';

    /**
     * To where redirect users once they have logged in.
     *
     * @var string
     */
    protected $redirectTo = '/#/projects';

    /**
     * @var UsersRepository
     */
    protected $usersRepository;

    public function __construct(UsersRepository $usersRepository)
    {
        $this->usersRepository = $usersRepository;
    }

    /**
     * Creates a new user.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function doSignUp(Request $request)
    {
        $payload = $request->only('username', 'name', 'email', 'password');
        $validator = Validator::make($payload, [ 
                'username' => 'required|max:50',
                'name' => 'required|max:255',
                'email' => 'required|email|max:255|unique:users',
                'password' => '<PASSWORD>' 
        ]);
        
        if ($validator->fails())
        {
            $this->throwValidationException($request, $validator);
        }
        
        $payload['password'] = <PASSWORD>($payload['password']);
        
        $entity = $this->usersRepository->create($payload);
        
        Auth::loginUsingId($entity['id'], $request->has('remember'));
        
        return $entity;
    }
    
    /**
     * Checks if the request contains valid credentials.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function doCheckLogin(Request $request)
    {
        $user = Auth::user();
        return $user;
    }

    /**
     * Logs out a user.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function doLogout(Request $request)
    {
        Auth::logout();
        return $this->response->array(array('success' => 'User successfully logged out.'));
    }

    /**
     * Logs in a user.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function doLogin(Request $request)
    {
        $validator = Validator::make($request->all(), [ 
            'username' => 'required|max:50',
            'password' => '<PASSWORD>' 
        ]);
        
        if ($validator->fails())
        {
            $this->throwValidationException($request, $validator);
        }
        
        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        $throttles = $this->isUsingThrottlesLoginsTrait();
        
        if ($throttles && $this->hasTooManyLoginAttempts($request)) {
            return $this->sendLockoutResponse($request);
        }
        
        $credentials = $this->getCredentials($request);
        
        if (Auth::attempt($credentials, $request->has('remember'))) {
            return $this->handleUserWasAuthenticated($request, $throttles);
        }
        
        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        if ($throttles) {
            $this->incrementLoginAttempts($request);
        }
        
        $user = Auth::user();
        if ($user)
            return $user;
        return $this->response->error('Invalid username or password.', 401);
    }

    /**
     * Called once a user successfully logs in to the system.
     *
     * @param Request $request HTTP request
     * @param \Nestor\Entities\User $user DB user returned
     */
    protected function authenticated(Request $request, \Nestor\Entities\User $user)
    {
        if ($user)
            return $user;
        return NULL;
    }

}
<commit_msg>Make user name unique, and email not<commit_after><?php

namespace Nestor\Http\Controllers;

use \Auth;
use \Validator;

use Illuminate\Http\Request;

use Illuminate\Foundation\Auth\AuthenticatesUsers;

use Dingo\Api\Routing\Helpers;

use Nestor\Http\Controllers\Controller;
use Nestor\Repositories\UsersRepository;

class UsersController extends Controller
{
    use AuthenticatesUsers, Helpers;

    /**
     * The field used as username to authenticate the user.
     *
     * @var string
     */
    protected $username = 'username';

    /**
     * To where redirect users once they have logged in.
     *
     * @var string
     */
    protected $redirectTo = '/#/projects';

    /**
     * @var UsersRepository
     */
    protected $usersRepository;

    public function __construct(UsersRepository $usersRepository)
    {
        $this->usersRepository = $usersRepository;
    }

    /**
     * Creates a new user.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function doSignUp(Request $request)
    {
        $payload = $request->only('username', 'name', 'email', 'password');
        $validator = Validator::make($payload, [ 
                'username' => 'required|max:50|unique:users',
                'name' => 'required|max:255',
                'email' => 'required|email|max:255',
                'password' => '<PASSWORD>' 
        ]);
        
        if ($validator->fails())
        {
            $this->throwValidationException($request, $validator);
        }
        
        $payload['password'] = <PASSWORD>($payload['password']);
        
        $entity = $this->usersRepository->create($payload);
        
        Auth::loginUsingId($entity['id'], $request->has('remember'));
        
        return $entity;
    }
    
    /**
     * Checks if the request contains valid credentials.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function doCheckLogin(Request $request)
    {
        $user = Auth::user();
        return $user;
    }

    /**
     * Logs out a user.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function doLogout(Request $request)
    {
        Auth::logout();
        return $this->response->array(array('success' => 'User successfully logged out.'));
    }

    /**
     * Logs in a user.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function doLogin(Request $request)
    {
        $validator = Validator::make($request->all(), [ 
            'username' => 'required|max:50',
            'password' => '<PASSWORD>' 
        ]);
        
        if ($validator->fails())
        {
            $this->throwValidationException($request, $validator);
        }
        
        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        $throttles = $this->isUsingThrottlesLoginsTrait();
        
        if ($throttles && $this->hasTooManyLoginAttempts($request)) {
            return $this->sendLockoutResponse($request);
        }
        
        $credentials = $this->getCredentials($request);
        
        if (Auth::attempt($credentials, $request->has('remember'))) {
            return $this->handleUserWasAuthenticated($request, $throttles);
        }
        
        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        if ($throttles) {
            $this->incrementLoginAttempts($request);
        }
        
        $user = Auth::user();
        if ($user)
            return $user;
        return $this->response->error('Invalid username or password.', 401);
    }

    /**
     * Called once a user successfully logs in to the system.
     *
     * @param Request $request HTTP request
     * @param \Nestor\Entities\User $user DB user returned
     */
    protected function authenticated(Request $request, \Nestor\Entities\User $user)
    {
        if ($user)
            return $user;
        return NULL;
    }

}

{'fraction_non_alphanumeric': 0.12272066226647275, 'fraction_numerical': 0.002908602751985681, 'mean_word_length': 2.111729899060216, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 65, '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': '7575792', 'n_tokens_mistral': 2472, 'n_tokens_neox': 2461, 'n_words': 616}