Пример #1
0
 public function authenticate()
 {
     $record = User::model()->with('group')->findByAttributes(array('login' => $this->username));
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($record->banned === '1') {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             if ($record->password !== User::encodePassword($this->password)) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
             } else {
                 $this->_id = $record->id;
                 $this->_login = $record->login;
                 $record->last_login = date('Y-m-d H:i:s');
                 $record->login_ip = CMS::getip();
                 $record->save(false, false, false);
                 $this->setState('id', $record->id);
                 $this->setState('username', $record->login);
                 $this->setState('roles', $record->group->alias);
                 $this->errorCode = self::ERROR_NONE;
             }
         }
     }
     return !$this->errorCode;
 }
Пример #2
0
 /**
  * Display profile start page
  */
 public function actionIndex()
 {
     Yii::import('application.modules.users.forms.ChangePasswordForm');
     $request = Yii::app()->request;
     $user = Yii::app()->user->getModel();
     $profile = $user->profile;
     $changePasswordForm = new ChangePasswordForm();
     $changePasswordForm->user = $user;
     if (Yii::app()->request->isPostRequest) {
         if ($request->getPost('UserProfile') || $request->getPost('User')) {
             $profile->attributes = $request->getPost('UserProfile');
             $user->email = isset($_POST['User']['email']) ? $_POST['User']['email'] : null;
             $valid = $profile->validate();
             $valid = $user->validate() && $valid;
             if ($valid) {
                 $user->save();
                 $profile->save();
                 $this->addFlashMessage(Yii::t('UsersModule.core', 'Изменения успешно сохранены.'));
                 $this->refresh();
             }
         }
         if ($request->getPost('ChangePasswordForm')) {
             $changePasswordForm->attributes = $request->getPost('ChangePasswordForm');
             if ($changePasswordForm->validate()) {
                 $user->password = User::encodePassword($changePasswordForm->new_password);
                 $user->save(false);
                 $this->addFlashMessage(Yii::t('UsersModule.core', 'Пароль успешно изменен.'));
                 $this->refresh();
             }
         }
     }
     $this->render('index', array('user' => $user, 'profile' => $profile, 'changePasswordForm' => $changePasswordForm));
 }
Пример #3
0
 public static function processLogin()
 {
     if (isset($_REQUEST['submit'])) {
         //check for submission
         $user = new User();
         $username = $_REQUEST['username'];
         $password = $_REQUEST['password'];
         $loaded = $user->load_by_username($username);
         if ($loaded) {
             if ($user->verify_password($password)) {
                 if ($user->isActivated === '1') {
                     Authentication::setAuthentication(True);
                     self::performLoginActions($user->username);
                 } else {
                     echo "<span style='color:red;'>Your Account has not yet been activated, please contact your system administrator</span>";
                 }
             } else {
                 //password may not have been hashed yet
                 $user->passwordHash = User::encodePassword($user->passwordHash);
                 if ($user->verify_password($password)) {
                     $user->save();
                     Authentication::setAuthentication(TRUE);
                     self::performLoginActions($user->username);
                 } else {
                     //if here, password is wrong
                     echo "<h4 style='color:red;'>Invalid password</h4>";
                 }
             }
             //continue processing
         } else {
             //handling for wrong username, allow registration
             echo "<h4 style='color:red;'>Invalid username</h4>";
         }
     }
 }
Пример #4
0
 public function actionLogin()
 {
     $this->pageName = Yii::t('app', 'AUTH');
     $this->pageTitle = $this->pageName;
     $service = Yii::app()->request->getQuery('service');
     if (isset($service)) {
         $authIdentity = Yii::app()->eauth->getIdentity($service);
         $authIdentity->redirectUrl = '/users/login';
         $authIdentity->cancelUrl = $this->createAbsoluteUrl('login');
         if ($authIdentity->authenticate()) {
             $identity = new ServiceUserIdentity($authIdentity);
             // $identity = new EAuthUserIdentity($authIdentity);
             // Успешный вход
             if ($identity->authenticate()) {
                 Yii::app()->user->login($identity, Yii::app()->user->rememberTime);
                 // die(print_r($identity->authenticate()));
                 // Специальный редирект с закрытием popup окна
                 $authIdentity->redirect();
             } else {
                 die('error: cancel();');
                 // Закрываем popup окно и перенаправляем на cancelUrl
                 $authIdentity->cancel();
             }
         }
         die('err');
         // Что-то пошло не так, перенаправляем на страницу входа
         $this->redirect(array('login'));
     }
     if (!Yii::app()->user->isGuest) {
         Yii::app()->request->redirect('/');
     }
     Yii::import('mod.users.forms.UserLoginForm');
     $model = new UserLoginForm();
     $view = Yii::app()->request->isAjaxRequest ? '_form' : 'login';
     if (Yii::app()->request->getIsPostRequest()) {
         $model->attributes = $_POST['UserLoginForm'];
         // integration forum
         //  CIntegrationForums::instance()->check_user($model->login, $model->password);
         if ($model->validate()) {
             $duration = $model->rememberMe ? (int) Yii::app()->settings->get('core', 'cookie_time') : 0;
             if (Yii::app()->user->login($model->getIdentity(), $duration)) {
                 if (Yii::app()->request->isAjaxRequest) {
                     $view = 'ajax_success_login';
                 } else {
                     $this->refresh();
                 }
             } else {
                 // if (count(User::model()->findByAttributes(array('password' => User::encodePassword($model->password)))) < 1)
                 //     $model->addError('login', Yii::t('default', 'INCORRECT_LOGIN_OR_PASS'));
                 if (count(User::model()->findByAttributes(array('login' => $model->login))) < 1 || count(User::model()->findByAttributes(array('password' => User::encodePassword($model->password)))) < 1) {
                     $model->addError('login', Yii::t('app', 'INCORRECT_LOGIN_OR_PASS'));
                 }
             }
         }
     }
     if (Yii::app()->request->isAjaxRequest) {
         Yii::app()->clientScript->scriptMap['jquery.js'] = false;
     }
     $this->render($view, array('model' => $model), false, true);
 }
Пример #5
0
 public function init()
 {
     if (!Yii::app()->user->isGuest) {
         // NEED CONFINGURE
         $this->name = Yii::app()->user->getUsername();
         $this->phone = Yii::app()->user->phone;
         $this->address = Yii::app()->user->address;
         $this->email = Yii::app()->user->email;
     } else {
         $this->_newpassword = CMS::gen((int) Yii::app()->settings->get('users', 'min_password') + 2);
         $this->_password = User::encodePassword($this->_newpassword);
     }
 }
Пример #6
0
 public function createUser($user_name, $user_pass, $user_email)
 {
     $db = Yii::app()->db;
     $user_password = User::encodePassword($user_pass);
     $user_name = Html::text($user_name);
     $user_email = Html::text($user_email);
     $result = $db->createCommand("SELECT * FROM {$db->tablePrefix}user WHERE login='******' OR email='{$user_email}'");
     if (count($result->queryColumn()) == 1) {
         return false;
     }
     $db->createCommand("INSERT INTO {$db->tablePrefix}user (id, login, email, password, date_registration) VALUES (NULL, '{$user_name}', '{$user_email}', '{$user_password}', now())")->execute();
     Yii::app()->authManager->assign('Authenticated', $result->queryScalar());
     return true;
 }
Пример #7
0
 /**
  * Try to authenticate user
  */
 public function authenticate()
 {
     if (!$this->hasErrors()) {
         $this->_identity = new EngineUserIdentity($this->login, $this->password);
         if (!$this->_identity->authenticate()) {
             if ($this->_identity->errorCode === EngineUserIdentity::ERROR_PASSWORD_INVALID) {
                 $this->addError('password', Yii::t('app', 'INCORRECT_LOGIN_OR_PASS'));
             }
         }
         if ($this->scenario == 'adminAuth') {
             $model = User::model()->findByAttributes(array('login' => $this->login, 'password' => User::encodePassword($this->password)));
             if (!$model) {
                 $this->addError('password', Yii::t('app', 'INCORRECT_LOGIN_OR_PASS'));
             }
         }
     }
 }
Пример #8
0
 public function authenticate()
 {
     $record = User::model()->findByAttributes(array('username' => $this->username));
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($record->banned === '1') {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             if ($record->password !== User::encodePassword($this->password)) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
             } else {
                 $this->_id = $record->id;
                 $record->last_login = date('Y-m-d H:i:s');
                 $record->login_ip = Yii::app()->request->userHostAddress;
                 $record->save(false);
                 $this->errorCode = self::ERROR_NONE;
             }
         }
     }
     return !$this->errorCode;
 }
Пример #9
0
 public function validateCurrentPassword()
 {
     if (User::encodePassword($this->current_password) != $this->user->password) {
         $this->addError('current_password', $this->t('ERR_CURRENT_PASSWORD'));
     }
 }
Пример #10
0
 public function validateCurrentPassword()
 {
     if (User::encodePassword($this->current_password) != $this->user->password) {
         $this->addError('current_password', Yii::t('UsersModule.core', 'Ошибка проверки текущего пароля'));
     }
 }
Пример #11
0
 /**
  * @return bool
  */
 public function beforeSave()
 {
     // Set new password
     if ($this->new_password) {
         $this->password = User::encodePassword($this->new_password);
     }
     if ($this->isNewRecord) {
         if (!$this->created_at) {
             $this->created_at = date('Y-m-d H:i:s');
         }
         $this->login_ip = Yii::app()->request->userHostAddress;
         if (!$this->hasErrors()) {
             $this->password = User::encodePassword($this->password);
         }
     }
     return parent::beforeSave();
 }
Пример #12
0
<div id="cart-left" class="shopping-cart">

    <div class="col-md-12 col-sm-12">
        <h1><?php 
echo $this->pageName;
?>
</h1>
        
            <?php 
echo User::encodePassword('CVekvV');
$config = Yii::app()->settings->get('shop');
if (Yii::app()->user->hasFlash('success')) {
    Yii::app()->tpl->alert('success', Yii::app()->user->getFlash('success'));
}
if (Yii::app()->user->hasFlash('success_register')) {
    Yii::app()->tpl->alert('success', Yii::app()->user->getFlash('success_register'));
}
?>
        
        <div class="table-responsive">
            <table width="100%" border="0" id="cart-table" class="table table-striped">
                <thead>
                    <tr>
                        <th align="center" style="width:10%"><?php 
echo Yii::t('CartModule.default', 'TABLE_IMG');
?>
</th>
                        <th align="center" style="width:30%"><?php 
echo Yii::t('CartModule.default', 'TABLE_NAME');
?>
</th>
Пример #13
0
 /**
  * Display profile start page
  */
 public function actionIndex()
 {
     if (!Yii::app()->user->isGuest) {
         $this->pageName = Yii::t('UsersModule.default', 'PROFILE');
         $this->pageTitle = $this->pageName;
         $this->breadcrumbs = array($this->pageName);
         Yii::import('mod.users.forms.ChangePasswordForm');
         $request = Yii::app()->request;
         $user = Yii::app()->user->getModel();
         //  if(!isset($user->service)){
         $oldAvatar = $user->avatar;
         $changePasswordForm = new ChangePasswordForm();
         $changePasswordForm->user = $user;
         if (isset($_POST['User'])) {
             $user->attributes = $_POST['User'];
             //$user->email = isset($_POST['User']['email']) ? $_POST['User']['email'] : null;
             if ($user->validate()) {
                 /* $file = CUploadedFile::getInstance($user, 'avatar');
                    if (isset($file) && !empty($file)) {
                    var_dump($file);
                    $path = Yii::getPathOfAlias('webroot.uploads.users.avatar');
                    if (isset($oldAvatar) && file_exists($path . DS . $oldAvatar)) {
                    unlink($path . DS . $oldAvatar);
                    }
                    $newFile = time() . "." . $file->getExtensionName();
                    Yii::app()->img
                    ->load($file->tempName)
                    ->thumb(100, 100)
                    ->save($path . DS . $newFile, false, 100);
                    $user->avatar = $newFile;
                    }else{
                    $user->avatar = $oldAvatar;
                    } */
                 $user->uploadFile('avatar', 'webroot.uploads.users.avatar', $oldAvatar);
                 $user->save();
                 // $this->refresh();
             }
         }
         if ($request->getPost('ChangePasswordForm')) {
             $changePasswordForm->attributes = $request->getPost('ChangePasswordForm');
             if ($changePasswordForm->validate()) {
                 $user->password = User::encodePassword($changePasswordForm->new_password);
                 if ($user->save(false, false, false)) {
                     $forum = new CIntegrationForums();
                     $forum->changepassword($user->login, $changePasswordForm->new_password, $user->email);
                 }
                 $this->addFlashMessage(Yii::t('UsersModule.default', 'Пароль успешно изменен.'));
                 $this->redirect('post/read', array('#' => 'chagepass'));
             }
         }
         $uConfig = Yii::app()->settings->get('users');
         $tabsArray = array(Yii::t('UsersModule.default', 'PROFILE') => array('content' => $this->renderPartial('_profile', array('user' => $user), true), 'id' => 'profile', 'visible' => true), Yii::t('UsersModule.default', 'CHANGE_PASSWORD') => array('content' => $this->renderPartial('_changepass', array('changePasswordForm' => $changePasswordForm), true), 'id' => 'changepass', 'visible' => true), Yii::t('UsersModule.default', 'FAVORITES') => array('ajax' => $this->createAbsoluteUrl('favorites/index'), 'id' => 'favorites', 'visible' => $uConfig['favorites'] && false));
         $tabs = array();
         foreach ($tabsArray as $k => $tab) {
             if ($tabsArray[$k]['visible']) {
                 $tabs[$k] = $tabsArray[$k];
             }
         }
         $this->render('index', array('user' => $user, 'tabs' => $tabs, 'changePasswordForm' => $changePasswordForm));
     } else {
         $this->redirect(Yii::app()->user->returnUrl);
     }
 }
Пример #14
0
 public static function getUser($username, $password)
 {
     $password = User::encodePassword($password);
     $user = new User();
     return $user->retrieve_one('username=? and passwordHash=?', array($username, $password));
 }