backend/controllers/AdminsController.php
/**
     * Updates an existing Admins model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
Updates an existing Admins model.
If update is successful, the browser will be redirected to the 'view' page.
@param integer $id
@return mixed
@throws NotFoundHttpException if the model cannot be found
Updates an existing Admins model . If update is successful the browser will be redirected to the ' view ' page . @param integer $id @return mixed @throws NotFoundHttpException if the model cannot be found
public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        $password_model = new DynamicModel(['password', 'password_repeat', 'current_password']);
        $password_model
            ->addRule(['current_password', 'password'], 'string', ['min' => 6])
            ->addRule(['password'], 'match', ['pattern' => Users::PASSWORD_PATTERN, 'message' => "For the password you can use only letters of the Latin alphabet, digits and symbols !@#$%^&*()_+-=[]{}<>;:\"'\\|?/.,"])
            ->addRule(['password_repeat'], 'compare', ['compareAttribute' => 'password', 'skipOnEmpty' => false]);
        if ($this->Admins->admin_id == $id) {
            $password_model->addRule(['current_password'], 'required');
        }
        if ($model->load(Yii::$app->request->post())) {
            if ($this->Admins->admin_id == $id) {
                if ($this->Admins->admin_role != $model->admin_role) {
                    Yii::$app->session->setFlash('error', "You can't change your role.");
                    return $this->redirect(['update', 'id' => $id]);
                }
                if ($this->Admins->admin_status != $model->admin_status) {
                    Yii::$app->session->setFlash('error', "You can't change your status.");
                    return $this->redirect(['update', 'id' => $id]);
                }
                if ($this->Admins->admin_email != $model->admin_email) {
                    Yii::$app->session->setFlash('error', "You can't change your email.");
                    return $this->redirect(['update', 'id' => $id]);
                }
                if ($password_model->load(Yii::$app->request->post())) {
                    if ($model->validatePassword($password_model->current_password)) {
                        if (mb_strlen($password_model->password)) {
                            $model->setPassword($password_model->password);
                            $model->generateAuthKey();
                        }
                    } else {
                        Yii::$app->session->setFlash('error', "Wrong current password.");
                        return $this->redirect(['update', 'id' => $id]);
                    }
                }
            } else {
                if ($password_model->load(Yii::$app->request->post()) && $password_model->validate()) {
                    if (mb_strlen($password_model->password)) {
                        $model->setPassword($password_model->password);
                        $model->generateAuthKey();
                    }
                }
            }
            if ($model->save()) {
                return $this->redirect(['index']);
            }
        }
        return $this->render('update', [
            'model'   => $model,
            'password_model' => $password_model,
            'current' => $this->Admins,
        ]);
    }
public function actionUpdate ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ password_model = new DynamicModel ( [ 'password' , 'password_repeat' , 'current_password' ] ) ; $ password_model -> addRule ( [ 'current_password' , 'password' ] , 'string' , [ 'min' => 6 ] ) -> addRule ( [ 'password' ] , 'match' , [ 'pattern' => Users :: PASSWORD_PATTERN , 'message' => " For the password you can use only letters of the Latin alphabet, digits and symbols !@#$%^&*()_+-=[]{}<>;: \" ' \\ |?/., " ] ) -> addRule ( [ 'password_repeat' ] , 'compare' , [ 'compareAttribute' => 'password' , 'skipOnEmpty' => false ] ) ; if ( $ this -> Admins -> admin_id == $ id ) { $ password_model -> addRule ( [ 'current_password' ] , 'required' ) ; } if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { if ( $ this -> Admins -> admin_id == $ id ) { if ( $ this -> Admins -> admin_role != $ model -> admin_role ) { Yii :: $ app -> session -> setFlash ( 'error' , " You can't change your role. " ) ; return $ this -> redirect ( [ 'update' , 'id' => $ id ] ) ; } if ( $ this -> Admins -> admin_status != $ model -> admin_status ) { Yii :: $ app -> session -> setFlash ( 'error' , " You can't change your status. " ) ; return $ this -> redirect ( [ 'update' , 'id' => $ id ] ) ; } if ( $ this -> Admins -> admin_email != $ model -> admin_email ) { Yii :: $ app -> session -> setFlash ( 'error' , " You can't change your email. " ) ; return $ this -> redirect ( [ 'update' , 'id' => $ id ] ) ; } if ( $ password_model -> load ( Yii :: $ app -> request -> post ( ) ) ) { if ( $ model -> validatePassword ( $ password_model -> current_password ) ) { if ( mb_strlen ( $ password_model -> password ) ) { $ model -> setPassword ( $ password_model -> password ) ; $ model -> generateAuthKey ( ) ; } } else { Yii :: $ app -> session -> setFlash ( 'error' , " Wrong current password. " ) ; return $ this -> redirect ( [ 'update' , 'id' => $ id ] ) ; } } } else { if ( $ password_model -> load ( Yii :: $ app -> request -> post ( ) ) && $ password_model -> validate ( ) ) { if ( mb_strlen ( $ password_model -> password ) ) { $ model -> setPassword ( $ password_model -> password ) ; $ model -> generateAuthKey ( ) ; } } } if ( $ model -> save ( ) ) { return $ this -> redirect ( [ 'index' ] ) ; } } return $ this -> render ( 'update' , [ 'model' => $ model , 'password_model' => $ password_model , 'current' => $ this -> Admins , ] ) ; }
Updates an existing Admins model.
Updates an existing Admins model .
/* если это текущий пользователь */ /* если это другой юзер а не текущий */