/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { $profile = new Profile(); $profile->loadDefaultValues(); $profile->first_name = $this->first_name; $profile->last_name = $this->last_name; $profile->dob = $this->dob; $profile->address = $this->address; $profile->address2 = $this->address2; $profile->district = $this->district; $profile->state = $this->state; $profile->mobile = $this->mobile; $profile->ic = $this->ic; $profile->postcode = $this->postcode; $profile->name = $this->name; $profile->link('user', $user); if ($this->role == 'ENT') { $ent = new Entrepreneur(); $ent->plkn = $this->plkn; $ent->link('user', $user); } elseif ($this->role == 'MNT') { $mnt = new Mentor(); $mnt->link('user', $user); } Yii::$app->mailer->compose()->setFrom('*****@*****.**')->setTo($user->email)->setSubject('SALEXES Registration')->setTextBody('Congratulations you have been succesfully registered with us !!!')->setHtmlBody('<b>Please contact admin@9teraju.com to make payment for account activation.</b>')->send(); return $user; } } return null; }
public function save() { $user = User::findOne(Yii::$app->user->id); $model = new Profile(); $model->loadDefaultValues(); $model->attributes = $this->attributes; try { return $model->link('user', $user); } catch (ErrorException $e) { echo $e->getMessage(); } }
/** * Signs user up. * * @return mixed */ public function actionSignup() { $this->layout = 'unify/registration'; $model = new SignupForm(); if ($model->load(Yii::$app->request->post())) { if ($user = $model->signup()) { if (Yii::$app->getUser()->login($user)) { $profile = new Profile(); $profile->loadDefaultValues(); $profile->firstname = $model->firstname; $profile->lastname = $model->lastname; $profile->link('user', $user); return $this->goHome(); } } } return $this->render('signup', ['model' => $model]); }