/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionSignup() { $model = new SignupForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->signup()) { Yii::$app->session->setFlash('success', 'Добавлен новый пользователь'); return $this->redirect('/user/manage/index', 301); } else { Yii::$app->session->setFlash('error', 'Возникла ошибка при регистрации'); Yii::error('Ошибка при регистрации'); return $this->refresh(); } } return $this->render('signup', ['model' => $model]); }
/** * render Signup.php with $model = new SignupForm(); * * @return $this->render('signup', ['model' => $model]) */ public function actionSignup() { $model = new SignupForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $findUser = User::findByUsername($model->username); if (!$findUser) { $user = new User(); if ($user->addUser($model)) { // succeed to add User return $this->render('signup-success', ['model' => $model]); } $model->releaseErrorModel(); return $this->render('signup-success', ['model' => $model]); } $model->password = ''; /**< activate the rule */ $model->userExist('username', []); } // fail to add user, $model is changed branch statements return $this->render('signup', ['model' => $model]); }
public function actionSignup() { if (Yii::$app->user->identity->username == "zama") { $model = new SignupForm(); $empleado = new Empleado(); if ($model->load(Yii::$app->request->post()) && $empleado->load(Yii::$app->request->post())) { $empleado->estatus_did = 1; if ($empleado->validate() && $model->validate()) { $empleado->save(); $model->empleado_did = $empleado->id; if ($user = $model->signup()) { if (Yii::$app->getUser()->login($user)) { return $this->goHome(); } } } } return $this->render('signup', ['model' => $model, 'empleado' => $empleado]); } else { return $this->goHome(); } }
public function testPasswordRepeat() { // required $signupForm = new SignupForm(); $signupForm->password_repeat = 'password_repeat'; $this->assertFalse($signupForm->validate(['password_repeat'])); // compare $signupForm = new SignupForm(); $signupForm->password = '******'; $signupForm->password_repeat = 'password2'; $this->assertFalse($signupForm->validate(['password_repeat'])); $signupForm = new SignupForm(); $signupForm->password = '******'; $signupForm->password_repeat = 'password'; $this->assertTrue($signupForm->validate(['password_repeat'])); }