示例#1
0
 /**
  * @return array $reuslt['user','errors'];
  */
 public function signupClient()
 {
     $result = ['user' => '', 'errors' => ''];
     $errors = '';
     $user = '';
     if ($this->validate()) {
         $user = new Account();
         $user->setScenario('client-registration');
         $user->setAttributes($this->getAttributes());
         $user->setAttribute('status', 1);
         $user->password = Yii::$app->security->generateRandomString(8);
         $user->cleanPassword = $user->password;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             $auth = Yii::$app->authManager;
             $authorRole = $auth->getRole('client');
             $auth->assign($authorRole, $user->getId());
         } else {
             $errors['user'] = $user->getErrors();
         }
     } else {
         $errors['signup'] = $this->getErrors();
     }
     $result['user'] = $user;
     $result['errors'] = $errors;
     return $result;
 }