<commit_before><?php

class DefaultController extends Controller
{
    public function actionIndex()
    {
        if (Yii::app()->user->isGuest) {
            $this->render('login', array(
                    'loginForm' => new LoginForm,
                    'registerForm' => new RegisterForm,
                )
            );
        } else {

            $twitter_cache = new TwitterCache();
            $twitter_cache->refreshCache();

            $dataProvider = new CActiveDataProvider('Contact', array(
                'criteria' => array(
                    'order' => 'last_name DESC',
                ),
                'pagination' => array(
                    'pageSize' => 20,
                ),
            ));

            $this->render('index', array(
                    'dataProvider' => $dataProvider,
                    'newContact' => new Contact
                )
            );
        }
    }

    public function actionLogin()
    {
        $loginForm = new LoginForm;
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
            echo CActiveForm::validate($loginForm);
            Yii::app()->end();
        }

        if (isset($_POST['LoginForm'])) {
            $loginForm->attributes = $_POST['LoginForm'];
            if ($loginForm->validate() && $loginForm->login()) {
                Yii::app()->user->setFlash('success', 'Welcome ' . Yii::app()->user->name);
            } else {
                foreach ($loginForm->getErrors() as $error) {
                    Yii::app()->user->setFlash('error', $error);
                }

            }
        }

        $this->redirect(Yii::app()->user->returnUrl);
    }

    public function actionRegister()
    {
        $registerForm = new RegisterForm;
        if (isset($_POST['ajax']) && $_POST['ajax'] == 'registration-form') {
            echo CActiveForm::validate($registerForm);
            Yii::app()->end();
        }

        if (isset($_POST['RegisterForm'])) {
            $registerForm->attributes = $_POST['RegisterForm'];

            if ($registerForm->validate()) {
                if (User::model()->findByAttributes(array('email' => $registerForm->email)) === null) {
                    $user = $registerForm->register();
                    if (!$user->hasErrors()) {
                        Yii::app()->user->setFlash('success', "Welcome, $user->name!");
                        $loginForm = new LoginForm();
                        $loginForm->email = $registerForm->email;
                        $loginForm->password = $registerForm->password;
                        $loginForm->login();
                    } else {
                        foreach ($user->getErrors() as $error) {
                            Yii::app()->user->setFlash('error', $error);
                        }
                    }
                } else {
                    Yii::app()->user->setFlash('error', "The user already exists");
                }
            } else {
                Yii::app()->user->setFlash('error', "The form has errors, please fix them");
            }
        } else {
            Yii::app()->user->setFlash('error', "Nothing was submitted");
        }

        $this->redirect(Yii::app()->user->returnUrl);

    }

    public function actionLogout()
    {
        Yii::app()->user->logout();
        $this->redirect(Yii::app()->homeUrl);
    }

    public function actions()
    {
        return array(
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
            'page' => array(
                'class' => 'CViewAction',
            ),
        );
    }
}<commit_msg>fix issue that would show all contacts (without respect to user)<commit_after><?php

class DefaultController extends Controller
{
    public function actionIndex()
    {
        if (Yii::app()->user->isGuest) {
            $this->render('login', array(
                    'loginForm' => new LoginForm,
                    'registerForm' => new RegisterForm,
                )
            );
        } else {

            $twitter_cache = new TwitterCache();
            $twitter_cache->refreshCache();

            $dataProvider = new CActiveDataProvider('Contact', array(
                'criteria' => array(
                    'condition' => 'user_id = ' . Yii::app()->user->id,
                    'order' => 'last_name DESC',
                ),
                'pagination' => array(
                    'pageSize' => 20,
                ),
            ));

            $this->render('index', array(
                    'dataProvider' => $dataProvider,
                    'newContact' => new Contact
                )
            );
        }
    }

    public function actionLogin()
    {
        $loginForm = new LoginForm;
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
            echo CActiveForm::validate($loginForm);
            Yii::app()->end();
        }

        if (isset($_POST['LoginForm'])) {
            $loginForm->attributes = $_POST['LoginForm'];
            if ($loginForm->validate() && $loginForm->login()) {
                Yii::app()->user->setFlash('success', 'Welcome ' . Yii::app()->user->name);
            } else {
                foreach ($loginForm->getErrors() as $error) {
                    Yii::app()->user->setFlash('error', $error);
                }

            }
        }

        $this->redirect(Yii::app()->user->returnUrl);
    }

    public function actionRegister()
    {
        $registerForm = new RegisterForm;
        if (isset($_POST['ajax']) && $_POST['ajax'] == 'registration-form') {
            echo CActiveForm::validate($registerForm);
            Yii::app()->end();
        }

        if (isset($_POST['RegisterForm'])) {
            $registerForm->attributes = $_POST['RegisterForm'];

            if ($registerForm->validate()) {
                if (User::model()->findByAttributes(array('email' => $registerForm->email)) === null) {
                    $user = $registerForm->register();
                    if (!$user->hasErrors()) {
                        Yii::app()->user->setFlash('success', "Welcome, $user->name!");
                        $loginForm = new LoginForm();
                        $loginForm->email = $registerForm->email;
                        $loginForm->password = $<PASSWORD>->password;
                        $loginForm->login();
                    } else {
                        foreach ($user->getErrors() as $error) {
                            Yii::app()->user->setFlash('error', $error);
                        }
                    }
                } else {
                    Yii::app()->user->setFlash('error', "The user already exists");
                }
            } else {
                Yii::app()->user->setFlash('error', "The form has errors, please fix them");
            }
        } else {
            Yii::app()->user->setFlash('error', "Nothing was submitted");
        }

        $this->redirect(Yii::app()->user->returnUrl);

    }

    public function actionLogout()
    {
        Yii::app()->user->logout();
        $this->redirect(Yii::app()->homeUrl);
    }

    public function actions()
    {
        return array(
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
            'page' => array(
                'class' => 'CViewAction',
            ),
        );
    }
}
{'fraction_non_alphanumeric': 0.1603358656537385, 'fraction_numerical': 0.0007996801279488205, 'mean_word_length': 1.4245557350565428, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 135, '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': '5893034', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1857, 'n_words': 333}