/**
  * Declares defualt home for index
  */
 public function accessRules()
 {
     $model = new User();
     $level1 = $model->findByAttributes(array('level' => 1));
     $level2 = $model->findByAttributes(array('level' => 2));
     return array(array('allow', 'actions' => array('index', 'view'), 'users' => array('*')), array('allow', 'actions' => array('admin', 'create'), 'users' => array('@')), array('allow', 'actions' => array('update', 'delete'), 'users' => array($level->username)), array('deny', 'users' => array('*')));
 }
Example #2
0
 public function usernameCheck()
 {
     $user = new User();
     $check = $user->findByAttributes(array('username' => $this->username));
     if ($check) {
         $this->addError('username', 'username already exit');
     }
 }
Example #3
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()
 {
     $userModel = new User();
     $user = $userModel->findByAttributes(array('name' => $this->username));
     if (!isset($user)) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } elseif (!password_verify($this->password, $user->password)) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     } else {
         $this->setState('rol', $user->rol_id);
         $this->errorCode = self::ERROR_NONE;
     }
     return !$this->errorCode;
 }
 public function actionForgotpassword()
 {
     $email = isset($_POST['email']) ? $_POST['email'] : '*****@*****.**';
     $model = new Forgot();
     $userModel = new User();
     $user = $userModel->findByAttributes(array('email' => trim($email)));
     if ($user) {
         $isForget = $model->findByAttributes(array('user_id' => $user->id));
         if ($isForget) {
             if (strtotime($isForget->create_date) + 86400 < strtotime(date('Y-m-d h:i:s'))) {
                 $isForget->delete();
             } else {
                 echo json_encode(array('status' => 0, 'message' => 'You already asked for password recovery. Try after 24 hr.'));
                 die;
             }
         }
         $token = $this->genToken(200);
         $model->setAttributes(array('user_id' => $user->id, 'token' => $token, 'create_date' => date('Y-m-d h:i:s')));
         $model->save();
         $this->layout = "emailmaster";
         $body = $this->render('../emails/forgotemail', array('fullname' => $user->firstname . ' ' . $user->lastname, 'token' => $token, 'url' => Yii::app()->params['domain']), true);
         MailHelper::send($body, "SharedKey Password Reset", array($user->email));
         echo json_encode(array('status' => 1));
         die;
     }
     echo json_encode(array('status' => 0, 'message' => 'Error! Email / Username not found in Shared Key system.'));
 }