<commit_before><?php

namespace app\controllers;

use app\models\RegistrationModel;
use app\models\LoginModel;
use app\models\User;

class AuthController extends \jsonrpc\Controller
{

    /**
     * Registers a new user
     * 
     * @param RegistrationModel $data
     * @return array New user token
     */
    public function rpcRegister(RegistrationModel $data)
    {
        $user = new User;
        $user->setAttribute('username', $data->email);
        $user->setAttribute('password', $data->password);
        $user->save();
        
        \Yii::$app->user->login($user);
        
        return [ 'token' => $user->access_token ];
    }<commit_msg>Added correct exception of existing email on registration<commit_after><?php

namespace app\controllers;

use app\models\RegistrationModel;
use app\models\LoginModel;
use app\models\User;

class AuthController extends \jsonrpc\Controller
{

    /**
     * Registers a new user
     * 
     * @param RegistrationModel $data
     * @return array New user token
     */
    public function rpcRegister(RegistrationModel $data)
    {
        try {
            $user = new User;
            $user->setAttribute('username', $data->email);
            $user->setAttribute('password', $<PASSWORD>);
            $user->save();
        } catch(\yii\db\IntegrityException $ex) {
            throw new \jsonrpc\ValidationException('Email already used', 0, [ 'email' => 'Email already used' ]);
        }
        
        \Yii::$app->user->login($user);
        
        return [ 'token' => $user->access_token ];
    }
{'fraction_non_alphanumeric': 0.13329081632653061, 'fraction_numerical': 0.0006377551020408163, 'mean_word_length': 2.4559471365638768, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 22, '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': '99509', 'n_tokens_mistral': 443, 'n_tokens_neox': 441, 'n_words': 102}