Authored by wuxiao

Admin::findOne()->updateAttributes()

@@ -32,6 +32,8 @@ class AdminController extends BaseController @@ -32,6 +32,8 @@ class AdminController extends BaseController
32 $model->setPassword($posts['password']); 32 $model->setPassword($posts['password']);
33 $model->generateAuthKey(); 33 $model->generateAuthKey();
34 $model->generatePasswordResetToken(); 34 $model->generatePasswordResetToken();
  35 + //用户加入后默认启用状态
  36 + $model->status = Admin::STATUS_ACTIVE;
35 37
36 if ($model->save()){ 38 if ($model->save()){
37 if (($roleName = Yii::$app->request->post('role')) && ($role = $this->authManager->getRole($roleName))){ 39 if (($roleName = Yii::$app->request->post('role')) && ($role = $this->authManager->getRole($roleName))){
@@ -120,10 +122,10 @@ class AdminController extends BaseController @@ -120,10 +122,10 @@ class AdminController extends BaseController
120 $authManager = $this->authManager; 122 $authManager = $this->authManager;
121 switch (true){ 123 switch (true){
122 case $target == 'user' && $type == 'disable': 124 case $target == 'user' && $type == 'disable':
123 - $r = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'))->updateAll(['status'=>Admin::STATUS_DELETED]); 125 + $r = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'))->updateAttributes(['status'=>Admin::STATUS_DELETED]);
124 break; 126 break;
125 case $target == 'user' && $type == 'enable': 127 case $target == 'user' && $type == 'enable':
126 - $r = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'))->updateAll(['status'=>Admin::STATUS_ACTIVE]); 128 + $r = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'))->updateAttributes(['status'=>Admin::STATUS_ACTIVE]);
127 break; 129 break;
128 case $target == 'user' && $type == 'del': 130 case $target == 'user' && $type == 'del':
129 $r = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'))->delete(); 131 $r = Admin::findOne(Yii::$app->getRequest()->getQueryParam('id'))->delete();
@@ -38,6 +38,7 @@ class Admin extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface @@ -38,6 +38,7 @@ class Admin extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
38 public function rules() 38 public function rules()
39 { 39 {
40 return [ 40 return [
  41 + [['username','email'], 'trim'],
41 [['username', 'auth_key', 'password_hash', 'email'], 'required'], 42 [['username', 'auth_key', 'password_hash', 'email'], 'required'],
42 [['role', 'status', 'create_time', 'update_time'], 'integer'], 43 [['role', 'status', 'create_time', 'update_time'], 'integer'],
43 [['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255], 44 [['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],