/** * [loginAdmin description] * @return [type] [description] */ public function loginAdmin() { if ($this->validate() && UserDetails::isUserAdmin($this->username)) { return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); } else { return false; } }
/** * @return \yii\db\ActiveQuery */ public function getUserDetails() { return $this->hasMany(UserDetails::className(), ['loc_id' => 'id']); }
/** * [behaviors description] * @return [type] [description] */ public function behaviors() { return ['access' => ['class' => AccessControl::className(), 'rules' => [['allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return UserDetails::isUserAdmin(Yii::$app->user->identity->id); }], ['actions' => ['login'], 'allow' => true, 'roles' => ['?']]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['post']]]]; }
/** * @return \yii\db\ActiveQuery */ public function getDetails() { return $this->hasOne(UserDetails::className(), ['user_id' => 'id']); }
public function behaviors() { return ['access' => ['class' => AccessControl::className(), 'rules' => [['allow' => (bool) UserDetails::find()->where(['>=', 'role', 20])->andWhere(['id' => Yii::$app->user->id])->one()]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['post']]]]; }
/** * * @todo find how how to get the next inserted ID, reserve it, and save both User and UserDetails at the same time. * @return [type] [description] */ public function actionSignup() { $signupform = new SignupForm(); $userDetails = new UserDetails(); $data = Yii::$app->request->post(); if ($signupform->load($data)) { if ($user = $signupform->signup()) { // get the users ID fron the users TBO && add it to the users details TBO obj $data['UserDetails']['user_id'] = $user->getAttribute('id'); $userDetails->load($data); if ($userDetails->save()) { if (Yii::$app->getUser()->login($user)) { return \Yii::$app->response->redirect(['site/signup-complete']); } } } } return $this->render('signup', ['model' => $signupform, 'details' => $userDetails]); }
/** * Finds the UserDetails model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return UserDetails the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UserDetails::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getUserDetails() { return $this->hasMany(UserDetails::className(), ['lang_code' => 'code']); }
<?php use yii\helpers\Html; /* @var $this yii\web\View */ $this->title = 'Naabs 2'; $userData = \common\models\UserDetails::find()->andWhere(['user_id' => \Yii::$app->user->getIdentity()->id])->one(); $username = \common\models\User::find()->andWhere(['id' => \Yii::$app->user->getIdentity()->id])->one()->username; ?> <div class="site-index"> <div class="jumbotron"> <h1>Naabs 2</h1> <p class="lead"></p> </div> <div class="body-content"> <div class="row"> <div class="col-12"> <h2 class="center">Account Creation was a success!</h2> <p></p> </div> </div> <div class="row"> <div class="col-12"> <h4 class="center">You are Almost Done</h4> <p></p> </div> </div>