<commit_before><?php
namespace App\Controller;

use App\Lib\Status;
use App\Model\Entity\User;
use Cake\Event\EventManager;
use Cake\Routing\Router;

class LoginController extends AppController
{
    /**
     * beforeFilter event
     *
     * @param Event $event cake event
     * @return void
     */
    public function beforeFilter(\Cake\Event\Event $event)
    {
        $this->loadModel('Users');
        parent::beforeFilter($event);
    }

    /**
     * login method
     *
     * @return \Cake\Network\Response|void Redirects on successful login, renders view otherwise.
     */
    public function login()
    {
        $this->viewBuilder()->layout('plain');
        if (!$this->request->session()->started()) {
            $this->request->session()->start();
        }
        if (!empty($this->request->query('redirectUrl'))) {
            $this->request->session()->write('Auth.redirect', $this->request->query('redirectUrl'));
        }
        $user = $this->Users->newEntity();
        if ($this->request->is('post')) {
            $userData = $this->Auth->identify();
            if ($userData) {
                if ($this->request->data['cookie']) {
                    $this->AuthUtils->addRememberMeCookie($userData['id']);
                }
                $this->Auth->setUser($userData);
                return $this->redirect($this->Auth->redirectUrl());
            } elseif ($this->Users->hasLoginRetriesLock($this->request->data)) {
                $this->Flash->error(__('login.login_retries_lock'));
            } else {
                $this->Users->increaseLoginRetries($this->request->data);
                $this->Flash->error(__('login.wrong_credentials'));
            }
        }
        $this->set('user', $user);
    }

    /**
     * logout method
     *
     * @return \Cake\Network\Response|void Redirects on logout.
     */
    public function logout()
    {
        $this->Flash->success(__('login.you_have_been_logged_out'));
        if ($this->request->session()->started()) {
            $this->request->session()->destroy();
        }
        $this->AuthUtils->destroyRememberMeCookie();

        return $this->redirect($this->Auth->logout());
    }

    /**
     * new password for users
     *
     * @return \Cake\Network\Response|void Redirects when email was passed, renders view otherwise.
     */
    public function forgotPassword()
    {
        $this->viewBuilder()->layout('plain');
        if ($this->request->is('post')) {
            if (!empty($this->request->data['email'])) {
                $user = $this->Users->getUserByEmail($this->request->data['email']);

                if (!empty($user)) {
                    $this->Users->sendForgotPasswordEmail($user);<commit_msg>added email format validation to forget password<commit_after><?php
namespace App\Controller;

use App\Lib\Status;
use App\Model\Entity\User;
use Cake\Event\EventManager;
use Cake\Routing\Router;
use Cake\Validation\Validation;

class LoginController extends AppController
{
    /**
     * beforeFilter event
     *
     * @param Event $event cake event
     * @return void
     */
    public function beforeFilter(\Cake\Event\Event $event)
    {
        $this->loadModel('Users');
        parent::beforeFilter($event);
    }

    /**
     * login method
     *
     * @return \Cake\Network\Response|void Redirects on successful login, renders view otherwise.
     */
    public function login()
    {
        $this->viewBuilder()->layout('plain');
        if (!$this->request->session()->started()) {
            $this->request->session()->start();
        }
        if (!empty($this->request->query('redirectUrl'))) {
            $this->request->session()->write('Auth.redirect', $this->request->query('redirectUrl'));
        }
        $user = $this->Users->newEntity();
        if ($this->request->is('post')) {
            $userData = $this->Auth->identify();
            if ($userData) {
                if ($this->request->data['cookie']) {
                    $this->AuthUtils->addRememberMeCookie($userData['id']);
                }
                $this->Auth->setUser($userData);
                return $this->redirect($this->Auth->redirectUrl());
            } elseif ($this->Users->hasLoginRetriesLock($this->request->data)) {
                $this->Flash->error(__('login.login_retries_lock'));
            } else {
                $this->Users->increaseLoginRetries($this->request->data);
                $this->Flash->error(__('login.wrong_credentials'));
            }
        }
        $this->set('user', $user);
    }

    /**
     * logout method
     *
     * @return \Cake\Network\Response|void Redirects on logout.
     */
    public function logout()
    {
        $this->Flash->success(__('login.you_have_been_logged_out'));
        if ($this->request->session()->started()) {
            $this->request->session()->destroy();
        }
        $this->AuthUtils->destroyRememberMeCookie();

        return $this->redirect($this->Auth->logout());
    }

    /**
     * new password for users
     *
     * @return \Cake\Network\Response|void Redirects when email was passed, renders view otherwise.
     */
    public function forgotPassword()
    {
        $this->viewBuilder()->layout('plain');
        if ($this->request->is('post')) {
            if (!empty($this->request->data['email']) && Validation::email($this->request->data['email'])) {
                $user = $this->Users->getUserByEmail($this->request->data['email']);

                if (!empty($user)) {
                    $this->Users->sendForgotPasswordEmail($user);
{'fraction_non_alphanumeric': 0.1742545973933226, 'fraction_numerical': 0.0, 'mean_word_length': 2.2213916043703277, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 143, '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': '6065553', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1523, 'n_words': 244}