Пример #1
0
 /**
  * Creates a new Admin model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Admin();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 public function actionChangePassword()
 {
     $model = new \backend\models\Admin(['scenario' => 'admin-change-password']);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $user = Admin::findOne(Yii::$app->user->identity->id);
         $user->setPassword($model->password);
         $user->generateAuthKey();
         if ($user->save()) {
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'New password was saved.'));
         }
         return $this->redirect(['change-password']);
     }
     return $this->render('changePassword', ['model' => $model]);
 }
Пример #3
0
 /**
  * Creates a new Admin model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //if(!Yii::$app->user->can('createUser')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $model = new Admin(['scenario' => 'admin-create']);
     if ($model->load(Yii::$app->request->post())) {
         $imageName = $model->username;
         if (UploadedFile::getInstance($model, 'file')) {
             $model->file = UploadedFile::getInstance($model, 'file');
             $model->file->saveAs('uploads/admin/' . $imageName . '.' . $model->file->extension);
             $model->image = 'uploads/admin/' . $imageName . '.' . $model->file->extension;
         }
         $model->status = Admin::STATUS_ACTIVE;
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }