Dominus77 / yii2-advanced-start

Yii2 Start Project Advanced Template

Home Page:https://dominus77.github.io/yii2-advanced-start/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

User can not change password & First Name & Last Name in Frontend

polinwei opened this issue · comments

Debug :

    public function actionUpdatePassword()
    {
        $model = $this->findModel();

        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ActiveForm::validate($model);
        }
        if ($model->load(Yii::$app->request->post())) {
        	\yii\helpers\VarDumper::dump($model, 10, 1);
        	die;
            $model->save();
        }        
        return $this->redirect(['update', 'tab' => 'password']);
    }

message is below

 modules\users\models\frontend\User#1
(
    [currentPassword] => null
    [newPassword] => null
    [newPasswordRepeat] => null
    [role] => null
    [imageFile] => null
    [isDel] => null
    [yii\db\BaseActiveRecord:_attributes] => [
        'id' => 11
        'username' => 'msn'
        'auth_key' => '1tItNGtiGS8JqhN6HESDhKABrZ_S-bB-'
        'password_hash' => '$2y$13$1Cdtb7DMQwyDUF3.yQs8rONXPAdnRJC/f0DWzWsLWJDWZCkh75pUO'
        'password_reset_token' => 'GGbKY0Ga_7ooOSRdLh5T8ZBDWqEOupHr_1507797960'
        'email_confirm_token' => null
        'email' => 'xxx@msn.com'
        'status' => 1
        'last_visit' => 1507802728
        'created_at' => 1507797770
        'updated_at' => 1507797960
        'avatar' => null
        'first_name' => null
        'last_name' => null
        'openid' => null
        'registration_type' => 0
    ]
    [yii\db\BaseActiveRecord:_oldAttributes] => [
        'id' => 11
        'username' => 'msn'
        'auth_key' => '1tItNGtiGS8JqhN6HESDhKABrZ_S-bB-'
        'password_hash' => '$2y$13$1Cdtb7DMQwyDUF3.yQs8rONXPAdnRJC/f0DWzWsLWJDWZCkh75pUO'
        'password_reset_token' => 'GGbKY0Ga_7ooOSRdLh5T8ZBDWqEOupHr_1507797960'
        'email_confirm_token' => null
        'email' => 'xxx@msn.com'
        'status' => 1
        'last_visit' => 1507802728
        'created_at' => 1507797770
        'updated_at' => 1507797960
        'avatar' => null
        'first_name' => null
        'last_name' => null
        'openid' => null
        'registration_type' => 0
    ]
    [yii\db\BaseActiveRecord:_related] => []
    [yii\base\Model:_errors] => null
    [yii\base\Model:_validators] => ArrayObject#2
    (
        [0] => yii\validators\RequiredValidator#3
        (
            [skipOnEmpty] => false
            [requiredValue] => null
            [strict] => false
            [message] => '{attribute} cannot be blank.'
            [attributes] => [
                0 => 'username'
            ]
            [on] => []
            [except] => []
            [skipOnError] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [1] => yii\validators\RegularExpressionValidator#4
        (
            [pattern] => '#^[\\w_-]+$#i'
            [not] => false
            [attributes] => [
                0 => 'username'
            ]
            [message] => '{attribute} is invalid.'
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [2] => yii\validators\UniqueValidator#5
        (
            [targetClass] => 'modules\\users\\models\\frontend\\User'
            [targetAttribute] => null
            [filter] => null
            [message] => 'This user name is already in use.'
            [comboNotUnique] => null
            [targetAttributeJunction] => 'and'
            [attributes] => [
                0 => 'username'
            ]
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [3] => yii\validators\StringValidator#6
        (
            [length] => null
            [max] => 255
            [min] => 2
            [message] => '{attribute} must be a string.'
            [tooShort] => '{attribute} should contain at least {min, number} {min, plural, one{character} other{characters}}.'
            [tooLong] => '{attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}.'
            [notEqual] => null
            [encoding] => 'UTF-8'
            [attributes] => [
                0 => 'username'
            ]
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [4] => yii\validators\RequiredValidator#7
        (
            [skipOnEmpty] => false
            [requiredValue] => null
            [strict] => false
            [message] => '{attribute} cannot be blank.'
            [attributes] => [
                0 => 'email'
            ]
            [on] => []
            [except] => []
            [skipOnError] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [5] => yii\validators\EmailValidator#8
        (
            [pattern] => '/^[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/'
            [fullPattern] => '/^[^@]*<[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?>$/'
            [allowName] => false
            [checkDNS] => false
            [enableIDN] => false
            [attributes] => [
                0 => 'email'
            ]
            [message] => '{attribute} is not a valid email address.'
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [6] => yii\validators\UniqueValidator#9
        (
            [targetClass] => 'modules\\users\\models\\frontend\\User'
            [targetAttribute] => null
            [filter] => null
            [message] => 'This email address has already been taken.'
            [comboNotUnique] => null
            [targetAttributeJunction] => 'and'
            [attributes] => [
                0 => 'email'
            ]
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [7] => yii\validators\StringValidator#10
        (
            [length] => null
            [max] => 255
            [min] => null
            [message] => '{attribute} must be a string.'
            [tooShort] => null
            [tooLong] => '{attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}.'
            [notEqual] => null
            [encoding] => 'UTF-8'
            [attributes] => [
                0 => 'email'
            ]
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [8] => yii\validators\NumberValidator#11
        (
            [integerOnly] => true
            [max] => null
            [min] => null
            [tooBig] => null
            [tooSmall] => null
            [integerPattern] => '/^\\s*[+-]?\\d+\\s*$/'
            [numberPattern] => '/^\\s*[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?\\s*$/'
            [attributes] => [
                0 => 'status'
            ]
            [message] => '{attribute} must be an integer.'
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [9] => yii\validators\DefaultValueValidator#12
        (
            [value] => 2
            [skipOnEmpty] => false
            [attributes] => [
                0 => 'status'
            ]
            [message] => null
            [on] => []
            [except] => []
            [skipOnError] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [10] => yii\validators\RangeValidator#13
        (
            [range] => [
                0 => 0
                1 => 1
                2 => 2
                3 => 3
            ]
            [strict] => false
            [not] => false
            [allowArray] => false
            [attributes] => [
                0 => 'status'
            ]
            [message] => '{attribute} is invalid.'
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [11] => yii\validators\StringValidator#14
        (
            [length] => null
            [max] => 45
            [min] => null
            [message] => '{attribute} must be a string.'
            [tooShort] => null
            [tooLong] => '{attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}.'
            [notEqual] => null
            [encoding] => 'UTF-8'
            [attributes] => [
                0 => 'first_name'
                1 => 'last_name'
            ]
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [12] => yii\validators\SafeValidator#15
        (
            [attributes] => [
                0 => 'role'
                1 => 'registration_type'
            ]
            [message] => null
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [13] => yii\validators\RequiredValidator#16
        (
            [skipOnEmpty] => false
            [requiredValue] => null
            [strict] => false
            [message] => '{attribute} cannot be blank.'
            [attributes] => [
                0 => 'newPassword'
                1 => 'newPasswordRepeat'
                2 => 'currentPassword'
            ]
            [on] => [
                0 => 'passwordUpdate'
            ]
            [except] => []
            [skipOnError] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [14] => yii\validators\StringValidator#17
        (
            [length] => null
            [max] => null
            [min] => 6
            [message] => '{attribute} must be a string.'
            [tooShort] => '{attribute} should contain at least {min, number} {min, plural, one{character} other{characters}}.'
            [tooLong] => null
            [notEqual] => null
            [encoding] => 'UTF-8'
            [attributes] => [
                0 => 'newPassword'
            ]
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [15] => yii\validators\CompareValidator#18
        (
            [compareAttribute] => 'newPassword'
            [compareValue] => null
            [type] => 'string'
            [operator] => '=='
            [message] => '{attribute} must be equal to \"{compareValueOrAttribute}\".'
            [attributes] => [
                0 => 'newPasswordRepeat'
            ]
            [on] => []
            [except] => []
            [skipOnError] => true
            [skipOnEmpty] => true
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
        [16] => yii\validators\InlineValidator#19
        (
            [method] => 'validateCurrentPassword'
            [params] => null
            [clientValidate] => null
            [attributes] => [
                0 => 'currentPassword'
            ]
            [message] => null
            [on] => []
            [except] => []
            [skipOnError] => false
            [skipOnEmpty] => false
            [enableClientValidation] => true
            [isEmpty] => null
            [when] => null
            [whenClient] => null
            [yii\base\Component:_events] => []
            [yii\base\Component:_behaviors] => null
        )
    )
    [yii\base\Model:_scenario] => 'default'
    [yii\base\Component:_events] => [
        'beforeInsert' => [
            0 => [
                0 => [
                    0 => yii\behaviors\TimestampBehavior#20
                    (
                        [createdAtAttribute] => 'created_at'
                        [updatedAtAttribute] => 'updated_at'
                        [value] => null
                        [attributes] => [
                            'beforeInsert' => [
                                0 => 'created_at'
                                1 => 'updated_at'
                            ]
                            'beforeUpdate' => 'updated_at'
                        ]
                        [skipUpdateOnClean] => true
                        [owner] => modules\users\models\frontend\User#1(...)
                    )
                    1 => 'evaluateAttributes'
                ]
                1 => null
            ]
        ]
        'beforeUpdate' => [
            0 => [
                0 => [
                    0 => yii\behaviors\TimestampBehavior#20(...)
                    1 => 'evaluateAttributes'
                ]
                1 => null
            ]
        ]
    ]
    [yii\base\Component:_behaviors] => [
        'timestamp' => yii\behaviors\TimestampBehavior#20(...)
    ]
) 

Add scenario for methods like this:
For update passwords

$model->scenario = $model::SCENARIO_PASSWORD_UPDATE;

For update profile
$model->scenario = $model::SCENARIO_PROFILE_UPDATE;

If the tab does not open when you load it, fix it like this:

'active' => (!Yii::$app->request->get('tab') || (Yii::$app->request->get('tab') == 'profile')) ? true : false,

and
'active' => (!Yii::$app->request->get('tab') || (Yii::$app->request->get('tab') == 'profile')) ? true : false,

Update workable.