public function actionUser() { if (!User::find()->All() == null) { $this->redirect(Yii::$app->createAbsoluteUrl('site/login')); Yii::$app->end(); } //user $model = new User(); $model->scenario = 'create'; if ($model->load(Yii::$app->request->post())) { if ($model->save()) { $this->redirect(array('company/admin')); } } return $this->render('user', array('model' => $model)); }
public function behaviors() { return ['access' => ['class' => AccessControl::className(), 'only' => ['create', 'index'], 'rules' => [['actions' => ['error'], 'allow' => true, 'roles' => ['10']], ['actions' => ['logout', 'create', 'index'], 'allow' => true, 'roles' => ['@']], ['actions' => ['about'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { $valid_roles = [User::ROLE_ADMIN, User::ROLE_SUPERUSER]; return User::roleInArray($valid_roles) && User::isActive(); }]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['logout' => ['post']]]]; }
public function onAuthSuccess($client) { $attributes = $client->getUserAttributes(); /** @var Auth $auth */ $auth = Auth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one(); if (Yii::$app->user->isGuest) { if ($auth) { // login $user = $auth->user; Yii::$app->user->login($user); } else { // signup if (isset($attributes['email']) && isset($attributes['username']) && User::find()->where(['email' => $attributes['email']])->exists()) { Yii::$app->getSession()->setFlash('error', [Yii::t('app', "User with the same email as in {client} account already exists but isn't linked to it. Login using email first to link it.", ['client' => $client->getTitle()])]); } else { $password = Yii::$app->security->generateRandomString(6); $user = new User(['username' => $attributes['login'], 'email' => $attributes['email'], 'password' => $password]); $user->generateAuthKey(); $user->generatePasswordResetToken(); $transaction = $user->getDb()->beginTransaction(); /* if ($user->save()) { $auth = new Auth([ 'user_id' => $user->id, 'source' => $client->getId(), 'source_id' => (string)$attributes['id'], ]); if ($auth->save()) { $transaction->commit(); Yii::$app->user->login($user); } else { print_r($auth->getErrors()); } } else { print_r($user->getErrors()); } */ } } } else { // user already logged in if (!$auth) { // add auth provider $auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $client->getId(), 'source_id' => $attributes['id']]); $auth->save(); } } }
public function behaviors() { return ['access' => ['class' => AccessControl::className(), 'only' => ['crear', 'modificar', 'buscar', 'eliminar'], 'rules' => [['actions' => ['crear', 'modificar', 'buscar', 'eliminar'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::isUserAdmin(Yii::$app->user->identity->id); }], ['actions' => ['buscar'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::isUserProfe(Yii::$app->user->identity->id); }], ['actions' => ['buscar'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::isUserSubcomision(Yii::$app->user->identity->id); }]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['logout' => ['post']]]]; }
private function findUser() { $search = new User(); if (($token = Yii::$app->request->get('key')) !== null) { $model = $search->findOne(['token' => $token]); } else { if (Yii::$app->user->isGuest == false) { $model = $search->findOne(['login' => Yii::$app->user->identity->username]); } else { return null; } } return $model; }
/** * Finds the TituloDespesa model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return TituloDespesa the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = User::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionThanks($id) { $user = User::find()->where(['id' => $id])->one(); return $this->render('thanks', ['user' => $user]); }