<commit_before><?php
/**
 *
 */

namespace Login;

use Mvc5\Plugins;
use Mvc5\Request\Request;
use Mvc5\Response\HttpResponse;
use Mvc5\View;

class Controller
{
    /**
     *
     */
    use Plugins\Log;
    use Plugins\Messages;
    use Plugins\Response;
    use Plugins\Service;
    use Plugins\Url;
    use Plugins\User;
    use View\Model;

    /**
     *
     */
    const TEMPLATE = 'login/index';

    /**
     * @param Request $request
     * @return mixed
     */
    function __invoke(Request $request)
    {
        $user = $this->user();

        if ($user->authenticated()) {
            $this->warning('Already logged in!');
            return $this->redirect($this->url(['dashboard', 'user' => $user->username()]));
        }

        if (!$request->isPost()) {
            $this->warning('Demo Login', 'login');
            return $this->model(['params' => $request->params()]);
        }

        if ('home' !== $request->data('password')) {
            $this->danger('Invalid Login');
            return new HttpResponse($this->view(), 422);
        }

        $user['authenticated'] = true;
        $user['username'] = $request->data('username');

        $this->success('Login successful!');
        //throws the exception when debug is enabled
        //$this->log(new \Exception('Login successful!'));

        return $this->redirect($this->url(['dashboard', 'user' => $user->username()]));
    }
}<commit_msg>example regenerate session id and CSRF token<commit_after><?php
/**
 *
 */

namespace Login;

use Mvc5\Plugins;
use Mvc5\Request\Request;
use Mvc5\Response\HttpResponse;
use Mvc5\Session\CSRFToken;
use Mvc5\View;

class Controller
{
    /**
     *
     */
    use Plugins\Log;
    use Plugins\Messages;
    use Plugins\Response;
    use Plugins\Service;
    use Plugins\Url;
    use Plugins\User;
    use View\Model;

    /**
     *
     */
    const TEMPLATE = 'login/index';

    /**
     * @param Request $request
     * @return mixed
     */
    function __invoke(Request $request)
    {
        $user = $this->user();

        if ($user->authenticated()) {
            $this->warning('Already logged in!');
            return $this->redirect($this->url(['dashboard', 'user' => $user->username()]));
        }

        if (!$request->isPost()) {
            $this->warning('Demo Login', 'login');
            return $this->model(['params' => $request->params()]);
        }

        if ('home' !== $request->data('password')) {
            $this->danger('Invalid Login');
            return new HttpResponse($this->view(), 422);
        }

//        $request['session']->regenerate() &&
//            (new CSRFToken\Generate)($request['session'], true);

        $user['authenticated'] = true;
        $user['username'] = $request->data('username');

        $this->success('Login successful!');
        //throws the exception when debug is enabled
        //$this->log(new \Exception('Login successful!'));

        return $this->redirect($this->url(['dashboard', 'user' => $user->username()]));
    }
}
{'fraction_non_alphanumeric': 0.18277449046679817, 'fraction_numerical': 0.004930966469428008, 'mean_word_length': 2.2826321467098167, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 48, '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': '6240836', 'n_tokens_mistral': 926, 'n_tokens_neox': 898, 'n_words': 184}