Пример #1
0
 public function testNotCorrectSignup()
 {
     $model = new SignupForm(['username' => 'troy.becker', 'email' => '*****@*****.**', 'password' => 'some_password']);
     expect_not($model->signup());
     expect_that($model->getErrors('username'));
     expect_that($model->getErrors('email'));
     expect($model->getFirstError('username'))->equals('This username has already been taken.');
     expect($model->getFirstError('email'))->equals('This email address has already been taken.');
 }
Пример #2
0
 public function actionCreate()
 {
     $model = new SignupForm();
     $parseData['model'] = $model;
     // get user types
     $types = $model->_types;
     $role = new Role();
     if ($role->isAdmin) {
         foreach ($types as $key => $value) {
             if ($value['value'] == User::TYPE_ADMIN) {
                 unset($types[$key]);
             }
         }
     }
     $parseData['types'] = $model->_prepareDataSelect($types, 'value', 'label');
     $post = Yii::$app->request->post();
     if ($post) {
         $model->load(Yii::$app->request->post());
         if ($model->validate()) {
             $model->signup();
             return $this->redirect(['index']);
         } else {
             $parseData['errors'] = $model->getErrors();
         }
     }
     return $this->render('create', $parseData);
 }
Пример #3
0
 public function actionAjaxsignup()
 {
     $res['status'] = 'error';
     $data = Yii::$app->request->post();
     $model = new SignupForm();
     if ($data) {
         $model->username = $data['email'];
         $model->email = $data['email'];
         $model->password = $data['password'];
         if ($user = $model->signup()) {
             $auth = Yii::$app->authManager;
             $role = $auth->getRole(User::ROLE_CUSTOMER);
             $auth->assign($role, $user->id);
             Yii::$app->getUser()->login($user);
             $res['status'] = 'ok';
         } else {
             $errors = $model->getErrors();
             $res['description_email'] = $errors['email'];
         }
     }
     echo json_encode($res);
     exit;
 }