/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if (!$this->validate() || !$this->acceptLicence) { return null; } $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); return $user->save() ? $user : null; }
/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $user = new User(['scenario' => 'create']); $profile = new Profile(); if ($user->load(Yii::$app->request->post())) { $user->setPassword(Yii::$app->request->post('User')['newPassword']); $user->generateAuthKey(); $user->save(); return $this->redirect(['view', 'id' => $user->id]); //print_r($user->attributes); } else { return $this->render('create', ['user' => $user, 'profile' => $profile]); } }