/** Sign Up page. (Registration) */
 public function actionSignup()
 {
     $this->layout = '@vendor/cubiclab/admin-cube/views/layouts/signin';
     $user = new User(['scenario' => 'register']);
     // if register action is triggered
     if ($user->load(Yii::$app->request->post())) {
         if ($user->validate()) {
             if ($user->save(false)) {
                 Yii::$app->user->login($user);
                 Yii::$app->session->setFlash('success', 'Register success');
                 return $this->goHome();
             } else {
                 Yii::$app->session->setFlash('danger', 'Register error');
                 return $this->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($user);
         }
     }
     // render view
     return $this->render('signup', ['user' => $user]);
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'api_key', $this->api_key]);
     return $dataProvider;
 }
Example #3
0
 /**
  * Get user based on email and/or username
  *
  * @return \cubiclab\users\models\User|null
  */
 protected function getUser()
 {
     // check if we need to get user
     if ($this->_user === false) {
         $user = User::find();
         if ($this->module->loginEmail) {
             $user->orWhere(["email" => $this->username]);
         }
         if ($this->module->loginUsername) {
             $user->orWhere(["username" => $this->username]);
         }
         // get and store user
         $this->_user = $user->one();
     }
     // return stored user
     return $this->_user;
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
Example #5
0
 /**
  * Find User model by ID
  *
  * @param integer|array $id User ID
  *
  * @return \cubiclab\users\models\User User
  * @throws NotFoundHttpException User not found
  */
 private function findUser($id)
 {
     if (is_array($id)) {
         /** @var User $user */
         $model = User::findIdentities($id);
     } else {
         /** @var User $user */
         $model = User::findIdentity($id);
     }
     if ($model !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('User not found');
     }
 }
Example #6
0
 protected function getAuditValues($model)
 {
     return [[$model->getAttributeLabel('created_at'), date('d.m.Y', $model->created_at)], [$model->getAttributeLabel('created_by'), User::findOne($model->created_by)->username], [$model->getAttributeLabel('updated_at'), date('d.m.Y', $model->updated_at)], [$model->getAttributeLabel('updated_by'), User::findOne($model->updated_by)->username]];
 }