/** * Logs in a user. * * @return mixed */ public function actionLogin() { $this->layout = 'main_login'; if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); $signupModel = new SignupForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } elseif ($signupModel->load(Yii::$app->request->post())) { if ($user = $signupModel->signup()) { if (Yii::$app->getUser()->login($user)) { $profile = new ProfileCrud(); $profile->user_id = $user->id; $profile->fullname = $user->username; $profile->email = $user->email; $profile->save(); return $this->goHome(); } } } else { return $this->render('login', ['model' => $model, 'signupModel' => $signupModel]); } }
/** * Logs in a user. * * @return mixed */ public function actionLogin() { $this->layout = 'main_login'; if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); $signupModel = new SignupForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } elseif ($signupModel->load(Yii::$app->request->post())) { if ($user = $signupModel->signup()) { if (Yii::$app->getUser()->login($user)) { $profile = new ProfileCrud(); $profile->scenario = 'signup'; $profile->user_id = $user->id; $profile->fullname = $user->username; $profile->email = ' '; $profile->save(); if ($profile->sendEmail($user->email, 1)) { Yii::$app->session->setFlash('success', 'Hi ' . $user->username . ', selamat bergabung. Mohon lakukan verifikasi email dan lengkapi profile anda. '); } else { Yii::$app->session->setFlash('error', 'Maaf, kami tidak dapat mengirimkan email verifikasi untuk anda.'); } return $this->goHome(); } } } else { return $this->render('login', ['model' => $model, 'signupModel' => $signupModel]); } }
/** * [findProfileByUserId description] * @param [type] $id [description] * @return [type] [description] */ protected function findProfileByUserId($id) { if (($model = ProfileCrud::find($id)->where(['user_id' => $id])->andWhere(['created_by' => $id])->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }