<commit_before><?php
class UsersController extends AppController {
    public $scaffold;
    public $components = array(
        'Auth' => array(
            'authenticate' => array(
                'Form' => array(
                    'passwordHasher' => '<PASSWORD>',
                    'fields' => array('username','password')
                )
            )
    ));

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('login');
    }

    public function isAuthorized($user){
        if($this->action === 'logout'){
            return parent::isAuthorized();
        }
        return false;
    }

    public function login() {
        App::uses('SimplePasswordHasher', 'Controller/Component/Auth');
        if ($this->request->is('post')) {
            if ($this->Auth->login()) {
                $this->Session->write('name', $this->Auth->user('username'));
                $this->redirect('/');
            } else {
                $this->Session->setFlash(__('ユーザ名かパスワードが間違っています.'));
            }
        }
    }

    public function logout() {
        $this->Session->delete('name');
        $this->redirect($this->Auth->logout());
    }<commit_msg>fix redirect after login<commit_after><?php
class UsersController extends AppController {
    public $scaffold;
    public $components = array(
        'Auth' => array(
            'authenticate' => array(
                'Form' => array(
                    'passwordHasher' => '<PASSWORD>',
                    'fields' => array('username','password')
                )
            )
    ));

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('login');
    }

    public function isAuthorized($user){
        if($this->action === 'logout'){
            return parent::isAuthorized();
        }
        return false;
    }

    public function login() {
        App::uses('SimplePasswordHasher', 'Controller/Component/Auth');
        if ($this->request->is('post')) {
            if ($this->Auth->login()) {
                $this->Session->write('name', $this->Auth->user('username'));
                $url = $this->Session->read('url');
                if(preg_match("/\\/user\\/login$/", $url)){
                    $url='/';
                }
                $this->Session->delete('url');
                $this->redirect($url);
                
            } else {
                $this->Session->setFlash(__('ユーザ名かパスワードが間違っています.'));
            }
        }else{
            $this->Session->write('url', $this->request->referer(null,true));
        }
    }

    public function logout() {
        $this->Session->delete('name');
        $this->redirect($this->Auth->logout());
    }
{'fraction_non_alphanumeric': 0.17305585980284777, 'fraction_numerical': 0.0, 'mean_word_length': 1.7182539682539681, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 61, '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': '2743955', 'n_tokens_mistral': 768, 'n_tokens_neox': 735, 'n_words': 118}