Dominus77 / yii2-advanced-start

Yii2 Start Project Advanced Template
https://dominus77.github.io/yii2-advanced-start/
MIT License
23 stars 12 forks source link

Can not see picture on Profile #5

Closed polinwei closed 6 years ago

polinwei commented 6 years ago

When I Setup the domainFrontend & domainBackend

 'polin.wei@myweb.com',
    'supportEmail' => 'polin.wei@myweb.com',
    'user.passwordResetTokenExpire' => 3600,
    'domainFrontend' => 'myweb.com',
    'domainBackend' => 'myweb.com/admin',
];

I get the error message as below. If I remove domainFrontend & domainBackend , then workable.

GET http://myweb.com/admin/users/1/myweb.com/uploads/users/1/1507792080.jpg 404 (Not Found)
browser.chrome.js:172 dcePageScanner::ParsePage Starting page scan, href=http://myweb.com/admin/users/1/view
Dominus77 commented 6 years ago

you do not have a protocol http:// in the config

'polin.wei@myweb.com',
    'supportEmail' => 'polin.wei@myweb.com',
    'user.passwordResetTokenExpire' => 3600,
    'domainFrontend' => 'http://myweb.com',
    'domainBackend' => 'http://myweb.com/admin',
];

These parameters serve to display pictures from backend to frontend and vice versa. The download folder is in the frontend https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/common/config/bootstrap.php#L8

polinwei commented 6 years ago

Ha !! Ha !! My fault.

The other issue: When I send the request on page: "http://myweb.com/request-password-reset" . It always say "Sorry, we are unable to reset password for email provided. "

Where do I need to setup?

Dominus77 commented 6 years ago

Return to false https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/controllers/frontend/DefaultController.php#L246

See: https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/models/frontend/PasswordResetRequestForm.php#L37

For two reasons:

  1. https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/models/frontend/PasswordResetRequestForm.php#L45
  2. https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/models/frontend/PasswordResetRequestForm.php#L49

Reset password only for active account: https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/models/frontend/PasswordResetRequestForm.php#L41

polinwei commented 6 years ago

but the user&email is exist.

Dominus77 commented 6 years ago

but the user&email is exist.

Debug here: https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/models/frontend/PasswordResetRequestForm.php#L44

\yii\helpers\VarDumper::dump($user, 10, 1);
die;
polinwei commented 6 years ago
 modules\users\models\frontend\User#1
(
    [currentPassword] => null
    [newPassword] => null
    [newPasswordRepeat] => null
    [role] => null
    [imageFile] => null
    [isDel] => null
    [yii\db\BaseActiveRecord:_attributes] => [
        'id' => 9
        'username' => 'wei'
        'auth_key' => 'c1yDOdviN0keRC-zB7mHAS-9S6Q3o9B0'
        'password_hash' => '$2y$13$JHCvI9kBm5YmH6TPyVZ70uZGwR/VNjWR4mmgltkSARd6c2wFY2EkG'
        'password_reset_token' => null
        'email_confirm_token' => null
        'email' => 'xxx@msn.com'
        'status' => 1
        'last_visit' => 1507792923
        'created_at' => 1507790911
        'updated_at' => 1507792722
        'avatar' => '1507792722.jpg'
        'first_name' => null
        'last_name' => null
        'openid' => null
        'registration_type' => 0
    ]
    [yii\db\BaseActiveRecord:_oldAttributes] => [
        'id' => 9
        'username' => 'wei'
        'auth_key' => 'c1yDOdviN0keRC-zB7mHAS-9S6Q3o9B0'
        'password_hash' => '$2y$13$JHCvI9kBm5YmH6TPyVZ70uZGwR/VNjWR4mmgltkSARd6c2wFY2EkG'
        'password_reset_token' => null
        'email_confirm_token' => null
        'email' => 'xxx@msn.com'
        'status' => 1
        'last_visit' => 1507792923
        'created_at' => 1507790911
        'updated_at' => 1507792722
        'avatar' => '1507792722.jpg'
        'first_name' => null
        'last_name' => null
        'openid' => null
        'registration_type' => 0
    ]
    [yii\db\BaseActiveRecord:_related] => []
    [yii\base\Model:_errors] => null
    [yii\base\Model:_validators] => null
    [yii\base\Model:_scenario] => 'default'
    [yii\base\Component:_events] => [
        'beforeInsert' => [
            0 => [
                0 => [
                    0 => yii\behaviors\TimestampBehavior#2
                    (
                        [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#2(...)
                    1 => 'evaluateAttributes'
                ]
                1 => null
            ]
        ]
    ]
    [yii\base\Component:_behaviors] => [
        'timestamp' => yii\behaviors\TimestampBehavior#2(...)
    ]
) 
Dominus77 commented 6 years ago

This Ok! Yet:

\yii\helpers\VarDumper::dump(Yii::$app->params['supportEmail'], 10, 1);
die;
polinwei commented 6 years ago

'polin.wei@myweb.com'

Dominus77 commented 6 years ago

Debug here: https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/models/frontend/PasswordResetRequestForm.php#L55

\yii\helpers\VarDumper::dump($user, 10, 1);
die;

Should be generated 'password_reset_token'

polinwei commented 6 years ago

 modules\users\models\frontend\User#1
(
    [currentPassword] => null
    [newPassword] => null
    [newPasswordRepeat] => null
    [role] => null
    [imageFile] => null
    [isDel] => null
    [yii\db\BaseActiveRecord:_attributes] => [
        'id' => 9
        'username' => 'wei'
        'auth_key' => 'c1yDOdviN0keRC-zB7mHAS-9S6Q3o9B0'
        'password_hash' => '$2y$13$JHCvI9kBm5YmH6TPyVZ70uZGwR/VNjWR4mmgltkSARd6c2wFY2EkG'
        'password_reset_token' => 'UO5M8_9UZJHF7cqMAhreY83sT8jaGNfn_1507796636'
        'email_confirm_token' => null
        'email' => 'xxx@msn.com'
        'status' => 1
        'last_visit' => 1507792923
        'created_at' => 1507790911
        'updated_at' => 1507796636
        'avatar' => '1507792722.jpg'
        'first_name' => null
        'last_name' => null
        'openid' => null
        'registration_type' => 0
    ]
    [yii\db\BaseActiveRecord:_oldAttributes] => [
        'id' => 9
        'username' => 'wei'
        'auth_key' => 'c1yDOdviN0keRC-zB7mHAS-9S6Q3o9B0'
        'password_hash' => '$2y$13$JHCvI9kBm5YmH6TPyVZ70uZGwR/VNjWR4mmgltkSARd6c2wFY2EkG'
        'password_reset_token' => 'UO5M8_9UZJHF7cqMAhreY83sT8jaGNfn_1507796636'
        'email_confirm_token' => null
        'email' => 'xxx@msn.com'
        'status' => 1
        'last_visit' => 1507792923
        'created_at' => 1507790911
        'updated_at' => 1507796636
        'avatar' => '1507792722.jpg'
        'first_name' => null
        'last_name' => null
        'openid' => null
        'registration_type' => 0
    ]
    [yii\db\BaseActiveRecord:_related] => []
    [yii\base\Model:_errors] => null
    [yii\base\Model:_validators] => null
    [yii\base\Model:_scenario] => 'default'
    [yii\base\Component:_events] => [
        'beforeInsert' => [
            0 => [
                0 => [
                    0 => yii\behaviors\TimestampBehavior#2
                    (
                        [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#2(...)
                    1 => 'evaluateAttributes'
                ]
                1 => null
            ]
        ]
    ]
    [yii\base\Component:_behaviors] => [
        'timestamp' => yii\behaviors\TimestampBehavior#2(...)
    ]
) 

polinwei commented 6 years ago

I compare git . I do nothing . But now it can work. strange.

polinwei commented 6 years ago

Maybe I use the same browser with a different account to do the test ?!

Dominus77 commented 6 years ago

Replace: https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/models/frontend/PasswordResetRequestForm.php#L56 On:

$result = Yii::$app
            ->mailer
            ->compose(
                ['html' => '@modules/users/mail/passwordResetToken-html', 'text' => '@modules/users/mail/passwordResetToken-text'],
                ['user' => $user]
            )
            ->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])
            ->setTo($this->email)
            ->setSubject(Module::t('frontend', 'PASSWORD_RESET_FOR') . ' ' . Yii::$app->name)
            ->send();

        \yii\helpers\VarDumper::dump($result, 10, 1);
        die;
return $result;

If all goes well, it returns true

polinwei commented 6 years ago

Now it can send mail . When I click the link http://myweb.com/users/default/reset-password?token=UO5M8_9UZJHF7cqMAhreY83sT8jaGNfn_1507796636 from mail. I got Not Found (#404)

Dominus77 commented 6 years ago

Maybe I use the same browser with a different account to do the test ?!

Well, yes, you are logged in one window and try to remember the password as an authorized user))

Dominus77 commented 6 years ago

Now it can send mail . When I click the link http://myweb.com/users/default/reset-password?token=UO5M8_9UZJHF7cqMAhreY83sT8jaGNfn_1507796636 from mail. I got Not Found (#404)

Check the rule: https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/Bootstrap.php#L35 It must be so <_a:(login|logout|signup|email-confirm|request-password-reset|reset-password)>

polinwei commented 6 years ago

http://myweb.com/users/default/reset-password?token=GGbKY0Ga_7ooOSRdLh5T8ZBDWqEOupHr_1507797960

I look the table:user , is GGbKY0Ga_7ooOSRdLh5T8ZBDWqEOupHr_1507797960

Dominus77 commented 6 years ago

How do you call the method? https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/controllers/frontend/DefaultController.php#L267 This bug version 1.0.1 https://github.com/Dominus77/yii2-advanced-start/blob/288682261f87af0a72a6abb2693d55d0076c8fe5/modules/users/Bootstrap.php#L35 The wizard has been fixed: https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/Bootstrap.php#L35

Dominus77 commented 6 years ago

http://myweb.com/users/default/reset-password?token=GGbKY0Ga_7ooOSRdLh5T8ZBDWqEOupHr_1507797960

Correct link: http://myweb.com/reset-password?token=GGbKY0Ga_7ooOSRdLh5T8ZBDWqEOupHr_1507797960

Repeat the test again, the correct link should be generated in the letter.

polinwei commented 6 years ago

from mail


Hello msn,
!
Follow the link below to reset your password:
:
http://myweb.com/users/default/reset-password?token=GGbKY0Ga_7ooOSRdLh5T8ZBDWqEOupHr_1507797960

Dominus77 commented 6 years ago

Link generate to

https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/mail/passwordResetToken-text.php#L6

https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/mail/passwordResetToken-html.php#L9

The rule is corrected exactly? https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/Bootstrap.php#L35

It should turn out: http://myweb.com/reset-password?token=GGbKY0Ga_7ooOSRdLh5T8ZBDWqEOupHr_1507797960

polinwei commented 6 years ago

I don't know what I need to do . I paste the link http://myweb.com/reset-password?token=GGbKY0Ga_7ooOSRdLh5T8ZBDWqEOupHr_1507797960 , It also say Page not found.

Dominus77 commented 6 years ago

At the beginning of the method, insert https://github.com/Dominus77/yii2-advanced-start/blob/97fd99a66c34cf4ce37fcbb1ae9dab1b03757725/modules/users/controllers/frontend/DefaultController.php#L268

\yii\helpers\VarDumper::dump($token, 10, 1);
die;

And click on the link: http://myweb.com/reset-password?token=GGbKY0Ga_7ooOSRdLh5T8ZBDWqEOupHr_1507797960 Will the token show?

polinwei commented 6 years ago

Not show the token

Dominus77 commented 6 years ago

Show me your https://github.com/Dominus77/yii2-advanced-start/blob/master/modules/users/Bootstrap.php https://github.com/Dominus77/yii2-advanced-start/blob/master/frontend/config/main.php https://github.com/Dominus77/yii2-advanced-start/blob/master/modules/users/mail/passwordResetToken-html.php https://github.com/Dominus77/yii2-advanced-start/blob/master/modules/users/mail/passwordResetToken-text.php and https://github.com/Dominus77/yii2-advanced-start/blob/master/modules/users/controllers/frontend/DefaultController.php

polinwei commented 6 years ago

modules/users/Bootstrap.php


 * Date: 17.10.16
 * Time: 13:36
 */

namespace modules\users;

use yii\base\BootstrapInterface;

class Bootstrap implements BootstrapInterface
{
    /**
     * @inheritdoc
     */
    public function bootstrap($app)
    {
        // i18n
        $app->i18n->translations['modules/users/*'] = [
            'class' => 'yii\i18n\PhpMessageSource',
            'basePath' => '@modules/users/messages',
            'fileMap' => [
                'modules/users/backend' => 'backend.php',
                'modules/users/frontend' => 'frontend.php',
                'modules/users/mail' => 'mail.php',
            ],
        ];

        // Rules
        $app->getUrlManager()->addRules(
            [
                // объявление правил здесь
                '<_a:(login|logout|signup|email-confirm|request-password-reset|password-reset)>' => 'users/default/<_a>',

                'users' => 'users/default/index',
                'users/create' => 'users/default/create',
                'users//<_a:[\w\-]+>' => 'users/default/<_a>',
                'user/update' => 'users/default/update',
                'user/update-profile' => 'users/default/update-profile',
                'user/update-avatar' => 'users/default/update-avatar',
                'user/update-password' => 'users/default/update-password',
                'user/delete' => 'users/default/delete',
            ]
        );
    }
}
polinwei commented 6 years ago

frontend/config/main.php


$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-frontend',    
    'homeUrl' => '/',
    'basePath' => dirname(__DIR__),
    'bootstrap' => [
        'log',
        'modules\main\Bootstrap',
        'modules\users\Bootstrap',
        'modules\rbac\Bootstrap',
    ],
    'defaultRoute' => 'main/default/index',
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-frontend',
            'baseUrl' => '',
        ],
        'user' => [
            'identityClass' => 'modules\users\models\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
            'loginUrl' => ['/users/default/login'],
        ],
        'session' => [
            // this is the name of the session cookie used for login on the frontend
            'name' => 'advanced-frontend',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'frontend/error',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => true,
            'rules' => [],
        ],
    ],
    'as afterAction' => [
        'class' => '\modules\users\components\behavior\LastVisitBehavior',
    ],
    'params' => $params,
];

polinwei commented 6 years ago

modules/users/mail/passwordResetToken-html.php


`
urlManager->createAbsoluteUrl(['users/default/reset-password', 'token' => $user->password_reset_token]);
?>

$user->username]); ?>,

!

:

:

`
polinwei commented 6 years ago

modules/users/mail/passwordResetToken-text.php

`
urlManager->createAbsoluteUrl(['users/default/reset-password', 'token' => $user->password_reset_token]);
?>
Hello username ?>,

Follow the link below to reset your password:



`
Dominus77 commented 6 years ago

Stop!

Dominus77 commented 6 years ago

Look for the Bootstrap.php error I wrote about this above many times)) https://github.com/Dominus77/yii2-advanced-start/issues/5#issuecomment-336062038 https://github.com/Dominus77/yii2-advanced-start/issues/5#issuecomment-336064875 Necessary '<_a:(login|logout|signup|email-confirm|request-password-reset|reset-password)>' => 'users/default/<_a>', But not '<_a:(login|logout|signup|email-confirm|request-password-reset|password-reset)>' => 'users/default/<_a>',

polinwei commented 6 years ago

Sorry. It is reset-password and workable.