/**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $user = Users::model()->findByAttributes(array('username' => $this->username));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($user->password !== $user->encrypt($this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->_id = $user->id;
             $lastLogin = time();
             $this->setState('lastLoginTime', $lastLogin);
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
     /*
     
     		$users=array(
     			// username => password
     			'demo'=>'demo',
     			'admin'=>'admin',
     		);
     		if(!isset($users[$this->username]))
     			$this->errorCode=self::ERROR_USERNAME_INVALID;
     		else if($users[$this->username]!==$this->password)
     			$this->errorCode=self::ERROR_PASSWORD_INVALID;
     		else
     			$this->errorCode=self::ERROR_NONE;
     		return !$this->errorCode;*/
 }
 public function authenticate()
 {
     $model = Users::model()->find("user_name=:user_name and user_password=:user_password and user_type = 'Administrator'", array(':user_name' => $this->username, ':user_password' => md5($this->password)));
     //        echo $model->user_name;exit;
     //        $users = array(
     //            // username => password
     //            'demo' => 'demo',
     //            'admin' => 'admin',
     //        );
     //        echo "<pre>";
     //        print_r($model);
     //        echo "</pre>";
     //        exit;
     if (!$model) {
         throw new CHttpException('503: Forbidden or Login Failed!', 'Username or Password is invalid or you\'re not registered');
         exit;
     }
     if ($model->user_name !== $this->username) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($model->user_password !== md5($this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->user_id = $model->user_id;
         }
     }
     $this->errorCode = self::ERROR_NONE;
     return !$this->errorCode;
 }
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     //$user=Users::model()->findByAttributes(array('email'=>$this->email));
     $user = Users::model()->findByAttributes(array('email' => $this->username));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($user->activate == 0) {
             $this->errorCode = 100;
         } else {
             if (!Users::model()->validatePassword($this->password, $user->password)) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
             } else {
                 $this->_id = $user->id;
                 $this->username = $user->name;
                 $this->setState('name', $this->username);
                 $this->setState('photo', $user->photo);
                 $this->setState('member', $user->member);
                 $this->setState('role', $user->occupation_id);
                 if ($user->member_type == '') {
                     $user->member_type = 'client';
                 }
                 $this->setState('member_type', $user->member_type);
                 $this->setState('freefoto', $user->freefoto);
                 $this->setState('isCrm', $user->crm == 1 ? true : false);
                 $this->errorCode = self::ERROR_NONE;
             }
         }
     }
     return $this->errorCode == self::ERROR_NONE;
 }
Example #4
0
 /**
  * Displays the login page
  */
 public function actionLogin()
 {
     $model = new LoginForm();
     // var_dump($_POST);
     // die;
     // if it is ajax validation request
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     // collect user input data
     if (isset($_POST['LoginForm'])) {
         // var_dump($_POST);
         // die;
         $model->attributes = $_POST['LoginForm'];
         // validate user input and redirect to the previous page if valid
         if ($model->validate() && $model->login()) {
             // Yii::app()->user->returnUrl = Yii::app()->request->urlReferrer;
             // echo Yii::app()->request->urlReferrer;
             // die;
             // $this->redirect(Yii::app()->user->returnUrl);
             $record = Users::model()->findByAttributes(array('username' => $_POST['LoginForm']['username']));
             // echo "ssss";
             // var_dump($record);
             // die;
             Yii::app()->session['uid'] = $record['id'];
             Yii::app()->session['username'] = $record['username'];
             $this->redirect('/index.php?r=posts/index');
         }
     }
     // display the login form
     $this->render('login', array('model' => $model));
 }
 /**
  * Проверка Логина и Email
  *
  * @param $attr
  * @param $params
  */
 public function loginIsExists($attr, $params)
 {
     if (!$this->hasErrors()) {
         /** @var Users $user */
         $user = Users::model()->find('login = :login AND email = :email', array(':login' => $this->login, ':email' => $this->email));
         if ($user === NULL) {
             $this->addError(__FUNCTION__, Yii::t('main', 'Аккаунт не найден.'));
         } elseif ($user->isBanned()) {
             $this->addError(__FUNCTION__, Yii::t('main', 'Аккаунт заблокирован, восстановление пароля невозможно'));
         } elseif (!$user->isActivated()) {
             $this->addError(__FUNCTION__, Yii::t('main', 'Аккаунт не активирован, восстановление пароля невозможно'));
         } else {
             // Ищю аккаунт на сервере
             try {
                 $l2 = l2('ls', $this->gs_list[$this->gs_id]['login_id'])->connect();
                 $res = $l2->getDb()->createCommand("SELECT * FROM {{accounts}} WHERE login = :login LIMIT 1")->bindParam('login', $this->login, PDO::PARAM_STR)->queryScalar();
                 if (!$res) {
                     $this->addError(__FUNCTION__, Yii::t('main', 'Аккаунт не найден.'));
                 }
             } catch (Exception $e) {
                 $this->addError(__FUNCTION__, $e->getMessage());
             }
         }
     }
 }
 protected function loadUser()
 {
     if ($this->_model === null) {
         $this->_model = Users::model()->findByPk($this->id);
     }
     return $this->_model;
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     //        echo Yii::app()->session['roles'];
     if (!isset(Yii::app()->session['roles']) || !isset(Yii::app()->session['type'])) {
         Yii::log("You must choose roles first!");
         throw new CHttpException("You must choose roles first!");
         return;
     }
     $roles = Yii::app()->session['roles'];
     if (Yii::app()->session['type'] == 'ActionsUsers') {
         $user = Users::model()->find("username like '{$roles}'");
         if (!$user) {
             Yii::log("Wrong username!");
             throw new CHttpException("Wrong username!");
             return;
         }
     }
     $model = $this->loadModel($id);
     $array_action = array_map('trim', explode(",", trim($model->actions)));
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Actions'])) {
         if (Yii::app()->session['type'] == 'ActionsUsers') {
             $model->addUserRoles($_POST['Actions']);
             $this->redirect(array('user'));
         } else {
             $model->addGroupRoles($_POST['Actions']);
             $this->redirect(array('group'));
         }
     }
     $this->render('update', array('model' => $model, 'actions' => $this->listActionsCanAccess, 'actions_controller' => $array_action));
 }
Example #8
0
 private function getModel()
 {
     if (!$this->isGuest && $this->_model === null) {
         $this->_model = Users::model()->findByPk($this->id);
     }
     return $this->_model;
 }
Example #9
0
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $username = strtolower($this->username);
     $user = Users::model()->find('LOWER(NOMER_SAKTI)=?', array($username));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!$user->validatePassword($this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             if ($user->STATUS == 0) {
                 $this->errorCode = self::ERROR_USERNAME_INVALID;
             } else {
                 $this->_id = $user->ID_USERS;
                 $this->username = $user->NOMER_SAKTI;
                 $this->setState('role', $user->ID_JENIS);
                 $this->errorCode = self::ERROR_NONE;
             }
         }
     }
     return $this->errorCode == self::ERROR_NONE;
     // $users=array(
     // 	// username => password
     // 	'demo'=>'demo',
     // 	'admin'=>'admin',
     // );
     // if(!isset($users[$this->username]))
     // 	$this->errorCode=self::ERROR_USERNAME_INVALID;
     // elseif($users[$this->username]!==$this->password)
     // 	$this->errorCode=self::ERROR_PASSWORD_INVALID;
     // else
     // 	$this->errorCode=self::ERROR_NONE;
     // return !$this->errorCode;
 }
Example #10
0
 public function authenticate()
 {
     $userIp = userIp();
     $this->_user = Users::model()->with('profile')->find('login = :login AND role = :role', array('login' => $this->username, 'role' => Users::ROLE_ADMIN));
     if ($this->_user === NULL) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } elseif (Users::validatePassword($this->password, $this->_user->password) === FALSE) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
         // Сохраняю неудачную попытку входа
         UsersAuthLogs::model()->addErrorAuth($this->_user->getPrimaryKey());
     } elseif ($this->_user->activated == Users::STATUS_INACTIVATED) {
         $this->errorCode = self::ERROR_STATUS_INACTIVE;
     } elseif ($this->_user->role == Users::ROLE_BANNED) {
         $this->errorCode = self::ERROR_STATUS_BANNED;
     } elseif ($this->_user->profile->protected_ip && !in_array($userIp, $this->_user->profile->protected_ip)) {
         $this->errorCode = self::ERROR_STATUS_IP_NO_ACCESS;
     } else {
         $this->_id = $this->_user->getPrimaryKey();
         $this->_user->auth_hash = Users::generateAuthHash();
         $this->setState('auth_hash', $this->_user->auth_hash);
         $this->_user->save(FALSE, array('auth_hash', 'updated_at'));
         // Запись в лог
         UsersAuthLogs::model()->addSuccessAuth($this->_user->getPrimaryKey());
         $this->errorCode = self::ERROR_NONE;
     }
     return !$this->errorCode;
 }
Example #11
0
 /**
  * Check unique rule
  */
 public function check_unique() {
         $user = Users::model()->find('User_Login=:login',
             array(':login'=>$this->User_Login));
         if($user != null) {
             $this->addError('User_Login','Login exists');
         }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new UsersActions('create');
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['UsersActions']) && isset($_POST['Username'])) {
         $name = Helper::toRegularString($_POST['Username']);
         $user = Users::model()->find("username like '{$name}'");
         if ($user) {
             //Check controller name, action name - PDQuang
             if ($_POST['UsersActions']['module'] == null) {
                 $checkController = ControllerActionsName::checkControllerActionsExist($_POST['UsersActions']['controller'], $_POST['UsersActions']['actions']);
             } else {
                 $checkController = ControllerActionsName::checkControllerActionsExist($_POST['UsersActions']['controller'], $_POST['UsersActions']['actions'], $_POST['UsersActions']['module']);
             }
             if (!$checkController) {
                 Yii::log('Controller, Module or Actions is wrong!');
                 throw new CHttpException('Controller, Module or Actions is wrong!');
             }
             $model->user_id = $user->id;
             $model->attributes = $_POST['UsersActions'];
             if ($model->save()) {
             }
             //$this->redirect(array('view','id'=>$model->id));
         }
         //
         //
         MyDebug::output($_POST);
         MyDebug::output($name);
         //
         //
         //
     }
     $this->render('create', array('model' => $model, 'actions' => $this->listActionsCanAccess));
 }
Example #13
0
 public function authenticate()
 {
     $record = Users::model()->findByAttributes(array('username' => $this->username));
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!$this->enc && $record->password !== $record->generateHash($this->password) || $this->enc && $record->password !== $this->password) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             if ($record->active == UserActiveStates::EMAIL_ACTIVATION) {
                 $this->errorCode = self::ERROR_NOT_ACTIVATED;
             } elseif ($record->active == UserActiveStates::BLOCKED) {
                 $this->errorCode = self::ERROR_BLOCKED;
             } else {
                 $this->_id = $record->id;
                 $this->errorCode = self::ERROR_NONE;
                 $log = new UsersSiteLogins();
                 $log->user_id = $record->id;
                 $log->when = new CDbExpression("NOW()");
                 $log->userIP = $_SERVER['REMOTE_ADDR'];
                 $log->save();
             }
         }
     }
     return !$this->errorCode;
 }
Example #14
0
 /**
  * @return object - Members AR Object
  */
 private function getModel()
 {
     if (!$this->isGuest && $this->_model === null) {
         $this->_model = Users::model()->findByPk($this->id, array('select' => 'role'));
     }
     return $this->_model;
 }
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     if (preg_match('/@/', $this->username)) {
         //$this->username can filled by username or email
         $record = Users::model()->findByAttributes(array('email' => $this->username));
     } else {
         $record = Users::model()->findByAttributes(array('username' => $this->username));
     }
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($record->password !== Users::hashPassword($record->salt, $this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->_id = $record->user_id;
             $this->setState('level', $record->level_id);
             $this->setState('profile', $record->profile_id);
             $this->setState('language', $record->language_id);
             $this->email = $record->email;
             $this->setState('username', $record->username);
             $this->setState('displayname', $record->displayname);
             $this->setState('creation_date', $record->creation_date);
             $this->setState('lastlogin_date', $record->lastlogin_date);
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
 /**
  * Lists all models.
  */
 public function actionFeedback()
 {
     $model = new SupportMails();
     if (!Yii::app()->user->isGuest) {
         $user = Users::model()->findByPk(Yii::app()->user->id, array('select' => 'user_id, email, displayname, photo_id'));
     }
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['SupportMails'])) {
         $model->attributes = $_POST['SupportMails'];
         $model->scenario = 'contactus';
         if ($model->save()) {
             if ($model->user_id != 0) {
                 $url = Yii::app()->controller->createUrl('feedback', array('email' => $model->email, 'name' => $model->displayname));
             } else {
                 $url = Yii::app()->controller->createUrl('feedback', array('email' => $model->email, 'name' => $model->displayname));
             }
             $this->redirect($url);
             /*
             echo CJSON::encode(array(
             	'type' => 5,
             	'get' => $url,
             ));
             */
         }
     }
     $this->pageTitleShow = true;
     $this->pageTitle = isset($_GET['email']) ? 'Kontak Kami Berhasil Dikirim' : 'Kontak Kami';
     $this->pageDescription = isset($_GET['email']) ? isset($_GET['name']) ? Phrase::trans(23123, 1, array($_GET['name'], $_GET['email'])) : Phrase::trans(23122, 1, array($_GET['email'])) : '';
     $this->pageMeta = '';
     $this->render('front_feedback', array('model' => $model, 'user' => $user));
 }
Example #17
0
 public function run()
 {
     $model = new ProGlobalEnquiry('create');
     $model->country_id = ActiveRecord::getDefaultAreaCode();
     if (isset(Yii::app()->user->id)) {
         $model->name = Yii::app()->user->title . ' ' . Yii::app()->user->first_name . ' ' . Yii::app()->user->last_name;
         $model->email = Yii::app()->user->email;
         if (Yii::app()->user->role_id != ROLE_REGISTER_MEMBER) {
             $model->email = Yii::app()->user->email_not_login;
         }
         $model->phone = Yii::app()->user->phone;
         $model->country_id = Yii::app()->user->country;
     }
     if (isset(Yii::app()->user->id)) {
         $cmsFormater = new CmsFormatter();
         $mUser = Users::model()->findByPk(Yii::app()->user->id);
         $model->name = $cmsFormater->formatFullNameRegisteredUsers($mUser);
         $model->email = $mUser->email;
         $model->nric = $mUser->nric_passportno_roc;
         $model->phone = $mUser->phone;
         if (Yii::app()->user->role_id == ROLE_LANDLORD || Yii::app()->user->role_id == ROLE_TENANT) {
             $model->phone = $mUser->contact_no;
             $model->email = $mUser->email_not_login;
         }
         if (Yii::app()->user->role_id == ROLE_AGENT) {
             $model->email = $mUser->email_not_login;
         }
     }
     //        $model->type_selling= 'Tenancy';
     $box = Pages::getPageById(PAGE_ENGAGE_US_BOX);
     $this->render("global_enquiry", array('model' => $model, 'box' => $box));
 }
Example #18
0
 public function actionForgotPass()
 {
     $result = ApiModule::$defaultSuccessResponse;
     $this->checkRequest();
     $q = $this->q;
     $this->checkRequiredParams($q, array('email'));
     $model = new ForgotPasswordForm();
     $model->email = trim($q->email);
     if ($model->validate()) {
         //check Email
         $criteria = new CDbCriteria();
         $criteria->compare('t.email_not_login', $model->email);
         $criteria->compare('t.role_id', ROLE_AGENT);
         $mUser = Users::model()->find($criteria);
         if (!$mUser) {
             $model->addError('email', 'Email does not exist.');
         } elseif ($mUser->status == STATUS_ACTIVE) {
             $password = substr(uniqid(rand(), 1), 1, 10);
             $pass_en = md5($password);
             $mUser->password_hash = $pass_en;
             $mUser->temp_password = $password;
             $mUser->update(array('password_hash', 'temp_password'));
             SendEmail::forgotPassword($mUser, $password, ROLE_AGENT);
             $result['message'] = Yii::t('systemmsg', 'An email with your new password has been sent to "{email}". ' . 'Please check your inbox. If you do not receive the email, ' . 'please add "@properyinfo.sg" to your mailbox safe list and check your Junk/Spam mailbox.', array('{email}' => $mUser->email_not_login));
         } else {
             $model->addError('email', 'Email does not exist.');
         }
     }
     $result['record_error_key'] = array_keys($model->getErrors());
     $result['record_error'] = $model->getErrors();
     ApiModule::sendResponse($result);
 }
Example #19
0
 /**
  * 用户基本信息
  */
 public function actionUserinfo()
 {
     $thisuser = Users::model()->findByPk(Yii::app()->user->getId());
     if (isset($_POST['Users'])) {
         $thisuser->setAttributes($_POST['Users']);
         foreach ((array) $_POST['Users'] as $key => $value) {
             if (trim($value) == '') {
                 $thisuser->addError($key, "字段不能为空");
                 break;
             }
         }
         if (!$thisuser->getErrors()) {
             if ($thisuser->validate()) {
                 $thisuser->setAttribute("real_status", 1);
                 if (!$thisuser->update()) {
                     $thisuser->addError("realname", "更新失败");
                 }
             } else {
                 $thisuser->addError("realname", "更新失败");
             }
         }
     }
     $this->pageTitle = "基本资料";
     $this->render('member_userinfo', array("thisuser" => $thisuser));
 }
    public function beforeAction($action)
    {
        //Load user's knight data
        if (!Yii::app()->user->isGuest) {
            $this->user_data['knights'] = Knights::model()->with('knightsCard', 'knightsStats')->find('id=:id', array(':id' => Yii::app()->user->knights_id));
            $this->user_data['knights_card'] =& $this->user_data['knights']->knightsCard;
            //Load stats of knight
            $this->user_data['knights_stats'] =& $this->user_data['knights']->knightsStats;
            //Load if user has new friendship request
            $sql = 'SELECT friends.id as id, k1.name as name, k1.avatars_id as avatars_id FROM friends
					INNER JOIN users ON users.id = friends.from_user
					INNER JOIN knights as k1 ON k1.users_id = users.id
					WHERE friends.status = :status AND to_user = :users_knights_id1
					ORDER BY start_date DESC';
            $command = Yii::app()->db->createCommand($sql);
            $command->bindValue(':status', Friends::STATUS_ONWAITING, PDO::PARAM_INT);
            $command->bindValue(':users_knights_id1', $this->user_data['knights']->id, PDO::PARAM_INT);
            $this->user_data['knights_new_friends'] = $command->queryAll();
            //Load last messages
            $this->user_data['new_messages'] = Messages::getNewMessages(Yii::app()->user->users_id);
            //Load all attributes name attributes
            $this->app_data['attribute_list'] = Constants::model()->findAll('type=:type', array(':type' => Constants::KNIGHTS_ATTRIBUTES));
            //Load settings
            $this->user_data['knight_settings'] = KnightsSettings::model()->findByPk(Yii::app()->user->knights_id);
            $this->user_data['user'] = Users::model()->findByPk(Yii::app()->user->users_id);
        } else {
            $this->redirect('/');
        }
        return true;
    }
Example #21
0
 /**
  * Authenticates a user.
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     if ($this->userType == 'Front') {
         $record = Users::model()->findByAttributes(array('username' => $this->username));
         if ($record === null) {
             $this->errorCode = self::ERROR_USERNAME_INVALID;
         } else {
             if (!$record->validatePassword($this->password)) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
             } else {
                 $this->setUser($record);
                 $this->errorCode = self::ERROR_NONE;
             }
         }
         return !$this->errorCode;
     }
     if ($this->userType == 'Back') {
         $record = Users::model()->findByAttributes(array('username' => $this->username, 'level' => 2));
         if ($record === null) {
             $this->errorCode = self::ERROR_USERNAME_INVALID;
         } else {
             if (!$record->validatePassword($this->password)) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
             } else {
                 $this->setState('isAdmin', 1);
                 $this->setUser($record);
                 $this->errorCode = self::ERROR_NONE;
             }
         }
         return !$this->errorCode;
     }
 }
Example #22
0
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         $cams = array_map('trim', explode(',', $this->hcams));
         $c = count($cams);
         foreach ($cams as $cam) {
             $this->camBuff[] = Cams::model()->findByPK(Cams::model()->getRealId($cam));
         }
         $this->camBuff = array_filter($this->camBuff);
         if (empty($this->camBuff) || count($this->camBuff) != $c) {
             $this->addError('cams', $c > 1 ? Yii::t('errors', 'One of cam is wrong') : Yii::t('errors', 'There is no such cam'));
             return false;
         }
         if (!is_array($this->emails)) {
             $emails = array_map('trim', explode(',', $this->emails));
         } else {
             $emails = array_map('trim', $this->emails);
         }
         $c = count($emails);
         $this->emailBuff = Users::model()->findAllByAttributes(array('email' => $emails));
         if (empty($this->emailBuff) || count($this->emailBuff) != $c) {
             $this->addError('emails', $c > 1 ? Yii::t('errors', 'One of user is wrong') : Yii::t('errors', 'There is no such user'));
             return false;
         }
         return true;
     }
     return false;
 }
Example #23
0
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     //        $users=array(
     //                // username => password
     //                'demo'=>'demo',
     //                'admin'=>'admin',
     //        );
     //        if(!isset($users[$this->username]))
     //                $this->errorCode=self::ERROR_USERNAME_INVALID;
     //        elseif($users[$this->username]!==$this->password)
     //                $this->errorCode=self::ERROR_PASSWORD_INVALID;
     //        else
     //                $this->errorCode=self::ERROR_NONE;
     //        return !$this->errorCode;
     $account = Account::model()->find('Username=:Username', array('Username' => $this->username));
     if ($account === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (isset($account->Password) && $account->Password != $this->password) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->errorCode = self::ERROR_NONE;
             Yii::app()->user->setState('idAccount', $account->ID);
             $user = Users::model()->find('ID_Account=:id', array('id' => $account->ID));
             Yii::app()->user->setState('idUser', $user->ID);
         }
     }
     return !$this->errorCode;
 }
 public function authenticate()
 {
     if (isset($this->key)) {
         $record = Users::model()->findByAttributes(array('key' => $this->key));
     } else {
         $record = Users::model()->findByAttributes(array('email' => $this->email));
     }
     $status = false;
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (isset($this->password) && $record->password !== md5($this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->_id = $record->id;
             $this->user = $record;
             $this->setState('email', $record->email);
             //            $this->setState('name', $record->username);
             $this->setState('id', $record->id);
             //            $this->setState('key', $record->key);
             $auth = Yii::app()->authManager;
             $data = AuthAssignment::model()->find('userid=:userid', array(':userid' => $record->id));
             $this->setState('role', $data->itemname);
             //echo  Yii::app()->user->role;exit();
             $this->errorCode = self::ERROR_NONE;
             $status = true;
         }
     }
     return $status;
 }
Example #25
0
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $user = Users::model()->findByAttributes(array('username' => $this->username));
     if ($user === null) {
         if (strpos($this->username, "@")) {
             $this->errorCode = self::ERROR_EMAIL_INVALID;
         } else {
             $this->errorCode = self::ERROR_EMAIL_INVALID;
         }
     } else {
         if (md5($this->password) !== $user->password) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             if ($user->status == 0 && Yii::app()->getModule('admin')->loginNotActiv == false) {
                 $this->errorCode = self::ERROR_STATUS_NOTACTIV;
             } else {
                 if ($user->status == -1) {
                     $this->errorCode = self::ERROR_STATUS_BAN;
                 } else {
                     Yii::app()->session['user_id'] = $user->id;
                     Yii::app()->session['user_name'] = $user->username;
                     Yii::app()->session['first_name'] = $user->first_name;
                     Yii::app()->session['last_name'] = $user->last_name;
                 }
             }
         }
     }
     return !$this->errorCode;
 }
Example #26
0
 public function authenticate()
 {
     $nick = strtolower($this->username);
     $user = Users::model()->find('LOWER(email)=?', array($nick));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } elseif (!$user->validatePassword($this->password, $user->salt)) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     } elseif ($user->status == 0) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
         return 2;
     } elseif ($user->status == 4) {
         // user is banned
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
         return 3;
     } else {
         $this->_id = $user->id;
         $this->username = $user->email;
         $this->setState('isAdmin', $user->status == 3);
         $this->setState('permissions', $user->status);
         $this->setState('nick', $user->nick);
         $this->setState('session_key', md5($user->email . time() . uniqid() . $user->salt));
         $this->setState('user_ip', Yii::app()->request->userHostAddress);
         Sessions::model()->deleteAllByAttributes(array('user_id' => $user->id));
         $this->errorCode = self::ERROR_NONE;
     }
     return $this->errorCode == self::ERROR_NONE;
 }
Example #27
0
 public function actionRecover()
 {
     $model = new RecoverForm();
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'recover-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['RecoverForm'])) {
         $model->attributes = $_POST['RecoverForm'];
         if ($model->validate()) {
             $user = Users::model()->findByAttributes(array("email" => $model->email));
             $password = md5(uniqid());
             $user->hash = md5($user->email . uniqid());
             $user->userkey = sha1($user->email . uniqid());
             $user->password = md5($password . $user->hash);
             if ($user->save()) {
                 $message = $this->renderPartial('/messages/recover', array("username" => $user->username, "password" => $password), true);
                 MyPhpMailer::send($user->email, "Восстановление пароля на FermionAm.ru", $message);
                 $this->redirect(array('site/index'));
             } else {
                 print CHtml::errorSummary($user);
                 Yii::app()->end();
             }
         } else {
             print CHtml::errorSummary($model);
             Yii::app()->end();
         }
     }
     $this->render('recover', array('model' => $model));
 }
Example #28
0
 public function actionIndex($uid)
 {
     //自己才能看自己的个人中心
     if ($uid != Yii::app()->user->id) {
         $this->redirect('/');
     }
     //显示用户资料
     $user_model = Users::model()->findByPk($uid);
     //获取ype
     if (isset($_GET['type']) && $_GET['type'] == 'focus') {
         //获取关注的问题
         $sql = "select `{{question}}`.`id`,`{{question}}`.`question_content`,`{{question}}`.`add_time`,`{{question}}`.`published_uid`,`{{question}}`.`lock`,`{{question}}`.`best_answer`,`{{question}}`.`answer_count`,`{{question}}`.`view_count` from `{{question}}` left join `{{question_focus}}` on (`{{question_focus}}`.`question_id`=`{{question}}`.`id`) where `{{question_focus}}`.`uid`={$uid} order by `{{question_focus}}`.`add_time` desc";
     } elseif (isset($_GET['type']) && $_GET['type'] == 'answer') {
         //获取回复的问题
         $sql = "select `{{question}}`.`id`,`{{question}}`.`question_content`,`{{question}}`.`add_time`,`{{question}}`.`published_uid`,`{{question}}`.`lock`,`{{question}}`.`best_answer`,`{{question}}`.`answer_count`,`{{question}}`.`view_count` from `{{question}}` left join `{{answer}}` on (`{{answer}}`.`question_id`=`{{question}}`.`id`) where `{{answer}}`.`uid`={$uid}";
     } else {
         //获取自己发布的问题
         $sql = "select `{{question}}`.`id`,`{{question}}`.`question_content`,`{{question}}`.`add_time`,`{{question}}`.`published_uid`,`{{question}}`.`lock`,`{{question}}`.`best_answer`,`{{question}}`.`answer_count`,`{{question}}`.`view_count` from `{{question}}` where `{{question}}`.`published_uid`={$uid} order by `{{question}}`.`add_time` desc";
     }
     $connection = Yii::app()->db;
     $criteria = new CDbCriteria();
     $models = $connection->createCommand($sql)->queryAll();
     $count = count($models);
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $pages->applylimit($criteria);
     $models = $connection->createCommand($sql . " LIMIT :offset,:limit");
     $models->bindValue(':offset', $pages->currentPage * $pages->pageSize);
     $models->bindValue(':limit', $pages->pageSize);
     $models = $models->queryAll();
     $this->render('index', array('user_model' => $user_model, 'models' => $models, 'pages' => $pages, 'count' => $count));
 }
Example #29
0
 public function testUserEmailChange()
 {
     $newEmail = '*****@*****.**';
     $model = $this->user;
     $profileForm = new ProfileForm();
     $this->assertTrue($model !== NULL);
     $profileForm->load($model->id, true);
     $profileForm->email = $newEmail;
     // Verify that the profile form saves
     $this->assertTrue($profileForm->save());
     // Verify that the base user model didn't change
     $model = $this->getUserModel();
     $this->assertTrue($model->email == '*****@*****.**');
     $newEmailModel = UserMetadata::model()->findByAttributes(array('user_id' => $this->user->id, 'key' => 'newEmailAddress'));
     // Verify that the new email is stored in the database
     $this->assertTrue($newEmailModel !== NULL);
     $this->assertTrue($newEmailModel->value == $newEmail);
     $key = UserMetadata::model()->findByAttributes(array('user_id' => $this->user->id, 'key' => 'newEmailAddressChangeKey'));
     $this->assertTrue($key !== NULL);
     $emailChangeForm = new EmailChangeForm();
     $emailChangeForm->setUser($this->getUserModel());
     $emailChangeForm->verificationKey = $key->value;
     $emailChangeForm->password = '******';
     // Verify that the verification key works
     $this->assertTrue($emailChangeForm->validateVerificationKey());
     // Veirfy that the email address changes
     $this->assertTrue($emailChangeForm->validate());
     $this->assertTrue($emailChangeForm->save());
     // Verify that the email has changed for the model now
     $model = Users::model()->findByAttributes(array('email' => '*****@*****.**'));
     $this->assertTrue($model->email == $newEmail);
 }
 /**
  * Get All notifications of a user.
  *
  * @author Kuldeep Dangi <*****@*****.**>
  */
 public function actionGetAllNotifications($userId)
 {
     $model = new Notifications();
     $data = array();
     $notifications = $model->getNotificationByUserId($userId);
     foreach ($notifications as $notification) {
         //print_r($notification); die;
         switch ($notification['type']) {
             case self::NOTIFICATION_TYPE_FOLLOW:
                 $user = Users::model()->findByAttributes(array('user_id' => $notification['byUserId']));
                 if ($user) {
                     $data[] = array('type' => $notification['type'], 'user_id' => $user->user_id, 'username' => $user->username, 'first_name' => $user->firstname, 'last_name' => $user->lastname, 'datetime' => strtotime($notification['created_at']));
                 }
             case self::NOTIFICATION_TYPE_WISHLISTCOMMENT:
                 $user = Users::model()->findByPk($notification['byUserId']);
                 $userFeed = UserFeed::model()->findByPk($notification['notify_comment']);
                 if ($user && $userFeed) {
                     $data[] = array('type' => $notification['type'], 'user_id' => $user->user_id, 'username' => $user->username, 'first_name' => $user->firstname, 'last_name' => $user->lastname, 'datetime' => strtotime($notification['created_at']), 'wishlistId' => $userFeed->user_feed_id, 'wishlistTitle' => $userFeed->comment);
                 }
             case self::NOTIFICATION_TYPE_WISHLISTUPLOAD:
                 $user = Users::model()->findByPk($notification['byUserId']);
                 $userFeed = UserFeed::model()->findByPk($notification['notify_comment']);
                 if ($user && $userFeed) {
                     $data[] = array('type' => $notification['type'], 'user_id' => $user->user_id, 'username' => $user->username, 'first_name' => $user->firstname, 'last_name' => $user->lastname, 'datetime' => strtotime($notification['created_at']), 'noteId' => $notification['notify_extension'], 'wishlistId' => $userFeed->user_feed_id, 'wishlistTitle' => $userFeed->comment);
                 }
         }
     }
     $this->result['success'] = true;
     $this->result['data'] = $data;
     $this->sendResponse($this->result);
 }