Exemple #1
0
 public function run()
 {
     if (Yii::app()->request->isPostRequest) {
         if ($this->data()) {
             $userModel = new User();
             if (!$userModel->existsEmail($this->email)) {
                 // 邮箱是否注册过
                 $transaction = $userModel->dbConnection->beginTransaction();
                 try {
                     $userModel->email = $this->email;
                     $userModel->password = $this->encryptPassword();
                     $userModel->register_time = time();
                     if ($userModel->save()) {
                         $this->uid = $userModel->getPrimaryKey();
                         if ($this->sendActiveEmail()) {
                             $transaction->commit();
                             die('register success');
                         }
                     }
                 } catch (Exception $exc) {
                     file_put_contents(date('YmdHis') . 'register.txt', var_export($exc->getMessage()));
                     $transaction->rollback();
                 }
             }
             $this->controller->error('该邮箱已经注册过');
         }
         $this->controller->error($this->msg);
     }
     $this->controller->render('register');
 }
Exemple #2
0
 public function register($params)
 {
     $row = (array) json_decode($params['data']);
     $row['created'] = date("Y-m-d H:i:s");
     $row['enabled'] = '1';
     $row['image_id'] = '0';
     $row['role_id'] = '2';
     /**
      * @todo
      * Validation if pseudo or email already exists
      */
     $imageMapper = new ImageMapper();
     //var_dump($_FILES);
     $imageObj = $imageMapper->upload($_FILES['file'], $row['created']);
     $userObj = new User();
     $userObj->setCreated($row['created'])->setEnabled($row['enabled'])->setImageId($row['image_id'])->setRoleId($row['role_id'])->setLogin($row['login'])->setPassword(md5($row['password']))->setEmail($row['email']);
     //$userObj = $this->save($userObj);
     $imageObj->setAlt('Picture of ' . $userObj->getLogin());
     $imageObj->setTitle('Picture of ' . $userObj->getLogin());
     $imageObj->setWidth('');
     $imageObj->setHeight('');
     $imageObj = $imageMapper->save($imageObj);
     $userObj->setImageId($imageObj->getId());
     //var_dump($imageObj->getId());
     $this->save($userObj);
     return array('success' => true, 'data' => array('username' => $userObj->getLogin(), 'image' => $imageObj->getImageName(), 'image_alt' => $imageObj->getAlt(), 'image_title' => $imageObj->getTitle(), 'role' => $userObj->getRoleId() == 2 ? 'customer' : 'admin'));
 }
Exemple #3
0
 /**
  * Username regex failed test.
  * 
  * This method will test usernames that aren't complied with the regex.
  */
 public function testUsernameRegexFailedUsername()
 {
     //Testing username regex rule.
     /* @var $user User */
     $user = new User();
     //False testcases
     $failedUsernameTestcases = array('user', 'username.', '1username', 'usern$');
     foreach ($failedUsernameTestcases as $testcase) {
         $user->clearErrors();
         $this->assertFalse($user->hasErrors('username'));
         $user->username = $testcase;
         $user->validate();
         //Invoking rule testing.
         $this->assertTrue($user->hasErrors('username'));
     }
 }
Exemple #4
0
 /**
  * User management list test.
  */
 public function testIndex()
 {
     $this->open('/administration/users');
     $users = User::model()->findAll();
     foreach ($users as $user) {
         /* @var $user application\models\User */
         $this->assertTextPresent($user->id);
         $this->assertTextPresent($user->username);
         $this->assertTextPresent($user->fullName);
     }
 }
Exemple #5
0
 /**
  * 验证激活
  * @return boolean 激活成功返回true
  */
 protected function active()
 {
     $model = UserActive::model();
     $active = $model->fetchUidByCode($this->code);
     if ($active) {
         unset($model);
         $model = User::model();
         $user = $model->findByPk($active->id);
         if ($user && $user->email == $this->email) {
             $user->status = User::STATUS_ENABLE;
             return $user->save();
         }
     }
     return false;
 }
 /**
  * User list display action.
  * 
  * This page will display list of users along with actions for user
  * management.
  */
 public function actionIndex()
 {
     $dataProvider = new \CActiveDataProvider(User::model(), array('criteria' => array('scopes' => array(User::SCOPE_SELECT_LABELS, User::SCOPE_ORDER_NEWEST)), 'pagination' => array()));
     $this->render('index', array('dataProvider' => $dataProvider));
 }