<commit_before><?php

namespace VojtaSvoboda\CodeLogin\Components;

use Auth;
use Event;
use Flash;
use Input;
use Redirect;
use Validator;
use ValidationException;
use ApplicationException;
use Cms\Classes\Page;
use Cms\Classes\ComponentBase;
use VojtaSvoboda\CodeLogin\Repositories\UserRepository;

class CodeLogin extends ComponentBase
{
	public function componentDetails()
	{
		return [
			'name'        => 'vojtasvoboda.codelogin::lang.logincomponent.name',
			'description' => 'vojtasvoboda.codelogin::lang.logincomponent.description'
		];
	}

	public function defineProperties()
	{
		return [
			'redirect' => [
				'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.title',
				'description' => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.description',
				'type'        => 'dropdown',
				'default'     => ''
			],
            'visible' => [
                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.visible.title',
                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.visible.description',
                'type'        => 'checkbox',
                'default'     => false
            ],
            'button' => [
                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.button.title',
                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.button.description',
                'type'        => 'string',
                'default'     => 'enter'
            ]
		];
	}

	public function getRedirectOptions()
	{
        $default = [
            '' => '- none -'
        ];
        $pages = Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName');

		return $default + $pages;
	}

	/**
	 * Executed when this component is bound to a page or layout.
	 */
	public function onRun()
	{
		$this->page['visible'] = $this->property('visible');
        $this->page['button'] = $this->property('button');
	}

	/**
	 * Sign in the user
	 */
	public function onCodesignin()
	{
		/*
		 * Validate input
		 */
		$data = post();

		$rules = [];
		$rules['code'] = 'required|min:2';

		$messages = [];
		$messages['required'] = trans('vojtasvoboda.codelogin::lang.form.required');

		$validation = Validator::make($data, $rules, $messages);
		if ($validation->fails()) {
			throw new ValidationException($validation);
		}

		/*
		 * Find user by password
		 */
		$users = new UserRepository();
		$userToLog = $users->getUserByPassword(array_get($data, 'code'));
		if ($userToLog === null) {
			$exception = new ValidationException([trans('vojtasvoboda.codelogin::lang.form.wrong_code')]);
			throw $exception;
		}

		/*
		 * Authenticate user
		 */
		$remember = true;
		$user = Auth::authenticate([
			'login' => $userToLog->email,
			'password' => array_get($data, 'code')
		], $remember);

		/*
		 * After login event
		 */
		Event::fire('vojtasvoboda.codelogin.afterlogin', [$user]);

		/*
		 * Redirect to the intended page after successful sign in
		 */
		$redirectUrl = $this->pageUrl($this->property('redirect'));

		if ($redirectUrl = post('redirect', $redirectUrl)) {
			return Redirect::intended($redirectUrl);
		}
	}

}<commit_msg>Fix file format<commit_after><?php

namespace VojtaSvoboda\CodeLogin\Components;

use Auth;
use Event;
use Flash;
use Input;
use Redirect;
use Validator;
use ValidationException;
use ApplicationException;
use Cms\Classes\Page;
use Cms\Classes\ComponentBase;
use VojtaSvoboda\CodeLogin\Repositories\UserRepository;

class CodeLogin extends ComponentBase
{
    public function componentDetails()
    {
        return [
            'name'        => 'vojtasvoboda.codelogin::lang.logincomponent.name',
            'description' => 'vojtasvoboda.codelogin::lang.logincomponent.description'
        ];
    }

    public function defineProperties()
    {
        return [
            'redirect' => [
                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.title',
                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.description',
                'type'        => 'dropdown',
                'default'     => ''
            ],
            'visible' => [
                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.visible.title',
                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.visible.description',
                'type'        => 'checkbox',
                'default'     => false
            ],
            'button' => [
                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.button.title',
                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.button.description',
                'type'        => 'string',
                'default'     => 'enter'
            ]
        ];
    }

    public function getRedirectOptions()
    {
        $default = [
            '' => '- none -'
        ];
        $pages = Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName');

        return $default + $pages;
    }

    /**
     * Executed when this component is bound to a page or layout.
     */
    public function onRun()
    {
        $this->page['visible'] = $this->property('visible');
        $this->page['button'] = $this->property('button');
    }

    /**
     * Sign in the user
     */
    public function onCodesignin()
    {
        /*
         * Validate input
         */
        $data = post();

        $rules = [];
        $rules['code'] = 'required|min:2';

        $messages = [];
        $messages['required'] = trans('vojtasvoboda.codelogin::lang.form.required');

        $validation = Validator::make($data, $rules, $messages);
        if ($validation->fails()) {
            throw new ValidationException($validation);
        }

        /*
         * Find user by password
         */
        $users = new UserRepository();
        $userToLog = $users->getUserByPassword(array_get($data, 'code'));
        if ($userToLog === null) {
            $exception = new ValidationException([trans('vojtasvoboda.codelogin::lang.form.wrong_code')]);
            throw $exception;
        }

        /*
         * Authenticate user
         */
        $remember = true;
        $user = Auth::authenticate([
            'login' => $userToLog->email,
            'password' => array_get($data, 'code')
        ], $remember);

        /*
         * After login event
         */
        Event::fire('vojtasvoboda.codelogin.afterlogin', [$user]);

        /*
         * Redirect to the intended page after successful sign in
         */
        $redirectUrl = $this->pageUrl($this->property('redirect'));

        if ($redirectUrl = post('redirect', $redirectUrl)) {
            return Redirect::intended($redirectUrl);
        }
    }

}
{'fraction_non_alphanumeric': 0.14962372731297033, 'fraction_numerical': 0.00029511583296443856, 'mean_word_length': 2.316046966731898, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, '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': '5361362', 'n_tokens_mistral': 2137, 'n_tokens_neox': 2011, 'n_words': 350}