laravel ÒÅÍüÃÜÂë
laravelÊÇÒ»¸öÊ¢ÐеÄphp web¿ò¼Ü£¬ËüÒѾ³ÉΪweb¿ª·¢ÕßÑ¡ÔñµÄÊ×Ñ¡¿ò¼ÜÖ®Ò»¡£Ëæ×ÅlaravelµÄÒ»Ö±Éú³¤ºÍ¸üУ¬ËüÒ»Ö±Ìṩ¸ü¶àµÄ¹¦Ð§ºÍ¸üºÃµÄÓû§ÌåÑé¡£laravelµÄÒÅÍüÃÜÂ빦ЧÊÇÆäÖÐÒ»¸ö×îÊܽӴýµÄ¹¦Ð§Ö®Ò»£¬ÓÉÓÚËüʹµÃÓû§Äܹ»Í¨¹ýµç×ÓÓʼþÖØÖÃËûÃǵÄÃÜÂë¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«Ì½ÌÖlaravelµÄÒÅÍüÃÜÂ빦Ч£¬°üÀ¨ÔõÑùÉèÖúÍ×Ô½ç˵ËüÒÔ¼°ÔõÑù½«ÆäÓÃÓÚÄúµÄÓ¦ÓóÌÐò¡£
Ò»¡¢ÒÅÍüÃÜÂëµÄÁ÷³Ì
ÔÚÌÖÂÛÔõÑùÉèÖÃÒÅÍüÃÜÂ빦Ч֮ǰ£¬ÈÃÎÒÃÇÊ×ÏÈÏàʶÆä»ù´¡Á÷³Ì¡£ÔÚLaravelÖУ¬ÒÅÍüÃÜÂëÁ÷³Ìͨ³£Éæ¼°ÒÔÏ°취£º
Óû§½øÈëÒÅÍüÃÜÂëÒ³Ãæ²¢ÊäÈëËûÃǵĵç×ÓÓʼþµØµã¡£
Ó¦ÓóÌÐòÈ·ÈϸÃÓʼþµØµãÊÇ·ñÓëÈκÎÓû§Ïà¹ØÁª¡£
ÈôÊÇÓʼþµØµã±£´æÓÚÓû§Êý¾Ý¿âÖУ¬ÔòÓ¦ÓóÌÐò»áÌìÉúÒ»¸ö°üÀ¨ÃÜÂëÖØÖÃÐÅÏ¢µÄÁ´½Ó£¬²¢½«¸ÃÁ´½Ó·¢Ë͵½Óû§µÄµç×ÓÓʼþµØµã¡£
Óû§µã»÷Á´½Ó²¢±»´øµ½Ò»¸ö°üÀ¨ÃÜÂëÖØÖÃ±íµ¥µÄÒ³Ãæ¡£
Óû§ÊäÈëÒ»¸öеÄÃÜÂë²¢Ìá½»±íµ¥¡£
Ó¦ÓóÌÐò½«ÐÂÃÜÂë´æ´¢µ½Óû§Êý¾Ý¿âÖУ¬²¢½«Óû§Öض¨Ïòµ½µÇ¼ҳÃæ¡£
¶þ¡¢ÉèÖÃÒÅÍüÃÜÂ빦Ч
ÏÖÔÚÎÒÃÇÒѾÏàʶÁËÒÅÍüÃÜÂ빦ЧµÄ»ù±¾Á÷³Ì£¬ÈÃÎÒÃÇ¿´¿´ÔõÑùÔÚLaravelÖÐÉèÖÃËü¡£
ÉèÖõç×ÓÓʼþ
Ê×ÏÈ£¬ÎÒÃÇÐèҪΪ×ðÁú¿Ê±Ó¦ÓóÌÐòÉèÖõç×ÓÓʼþ¡£LaravelÌṩÁËÒ»¸öÀû±ãµÄ·½·¨À´ÉèÖõç×ÓÓʼþ£º.envÎļþ¡£·¿ªÄúµÄ.envÎļþ²¢²éÕÒÒÔÏÂÉèÖãº
MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME=your-gmail-username MAIL_PASSWORD=your-gmail-password MAIL_ENCRYPTION=tls
µÇ¼ºó¸´ÖÆ
½«ÉÏÃæµÄÉèÖÃÉèÖÃΪÄú×Ô¼ºµÄµç×ÓÓʼþЧÀÍÆ÷ÉèÖá£Äú¿ÉÒÔʹÓÃ@example.com×÷ΪĬÈÏ·¢¼þÈ˵ص㣬»òÕßÉèÖÃΪһ¸öÄúÔÚµç×ÓÓʼþЧÀÍÆ÷ÉÏÒÑÉèÖõÄÓÐÓõص㡣Çë×¢ÖØ£¬ÄúÐèҪΪ´ËÉèÖÃÖ¸¶¨ÏìÓ¦µÄµç×ÓÓʼþЧÀÍÌṩÉ̵Äƾ֤¡£
ÌìÉúÃÜÂëÖØÖôúÂë
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÌìÉúLaravel×Ô´øµÄÃÜÂë¿ØÖÆÆ÷²¢½«ÆäÓÃÓÚÃÜÂëÖØÖá£ÔÚÖÕ¶ËÖÐÔËÐÐÒÔÏÂÏÂÁ
php artisan make:auth
µÇ¼ºó¸´ÖÆ
´ËÏÂÁÌìÉúLaravelµÄÉí·ÝÑéÖ¤¿ØÖÆÆ÷ºÍÊÓͼ£¬°üÀ¨ÖØÖÃÃÜÂë¿ØÖÆÆ÷ºÍÊÓͼ¡£µ±Íê³Éºó£¬ÄúµÄLaravelÓ¦ÓóÌÐò½«¾ßÓÐÒÔϹ¦Ð§£º
怬
×¢²á
ÒÅÍüÃÜÂë
ÖØÖÃÃÜÂë
×Ô½ç˵ÃÜÂëÖØÖÃÊÓͼ
µ±ÄúÍê³ÉÌìÉú¿ØÖÆÆ÷ºÍÊÓͼºó£¬Äú¿ÉÄÜÐèÒª¶ÔÆä¾ÙÐÐ×Ô½ç˵¡£ÀýÈ磬Äú¿ÉÒÔ¸ü¸ÄÊÓͼµÄÍâ¹ÛºÍ¸ÐÊÜ£¬»ò¸ü¸ÄËüÃÇÖ´ÐеIJÙ×÷¡£Îª´Ë£¬Äú¿ÉÒÔÔÚresources/views/auth/passwordsĿ¼ÖÐÕÒµ½ËùÐèµÄÊÓͼÎļþ£¬²¢¶ÔÆä¾ÙÐÐ×Ô½ç˵¡£
×Ô½ç˵ÓʼþÐÂÎÅ
LaravelĬÈÏÌṩµÄÃÜÂëÖØÖÃÓʼþÐÂÎÅ¿ÉÄܲ»ÇкÏÄúµÄÏêϸÐèÇó¡£Òò´Ë£¬Äú¿ÉÄÜÐèÒª¶ÔÆä¾ÙÐÐ×Ô½ç˵¡£ÒªÖ´Ðд˲Ù×÷£¬Çë·¿ªapp/Http/Controllers/Auth/ForgotPasswordController.phpÎļþ£¬²¢ÔÚsendResetLinkEmail()º¯ÊýÖÐ×Ô½ç˵µç×ÓÓʼþÐÂÎÅ¡£Äú¿ÉÒÔʹÓÃÈçÏ´úÂë×Ô½ç˵ÐÂÎÅ£º
return $this->sendResetLinkFailedResponse($request, 'This is a custom message');
µÇ¼ºó¸´ÖÆ
´ËÐдúÂ뽫ÔÚδÕÒµ½ÓëÖ¸¶¨µç×ÓÓʼþµØµãÏà¹ØÁªµÄÓû§Ê±´¥·¢¡£Äú¿ÉÒÔ½«×Ô½ç˵ÐÂÎÅÌ滻ΪÄúϲ»¶µÄÈκÎÐÂÎÅ¡£
Èý¡¢½«ÒÅÍüÃÜÂëÓÃÓÚÄúµÄÓ¦ÓóÌÐò
ÏÖÔÚÎÒÃÇÒѾÀֳɵØÉèÖÃÁËÒÅÍüÃÜÂ빦ЧºÍ×Ô½ç˵Ëü£¬ÎÒÃÇ¿ÉÒÔ½«ÆäÓÃÓÚ×ðÁú¿Ê±LaravelÓ¦ÓóÌÐò¡£Îª´Ë£¬ÄúÐèÒª½«ÏìÓ¦µÄ·ÓÉÌí¼Óµ½Ó¦ÓóÌÐòÖС£ÕâЩ·ÓÉͨ³£ÊÇÔÚroutes/web.phpÎļþÖнç˵µÄ¡£
ÒÔÏÂÊÇroutes/web.phpÎļþÖеÄʾÀýÒÅÍüÃÜÂë·ÓÉ£º
Route::get('forgot-password', 'AuthForgotPasswordController@showLinkRequestForm')->name('password.request'); Route::post('forgot-password', 'AuthForgotPasswordController@sendResetLinkEmail')->name('password.email'); Route::get('reset-password/{token}', 'AuthResetPasswordController@showResetForm')->name('password.reset'); Route::post('reset-password', 'AuthResetPasswordController@reset')->name('password.update');
µÇ¼ºó¸´ÖÆ
ÔÚÕâЩ·ÓÉÖУ¬’Auth’ÊÇLaravelÌìÉúµÄ¿ØÖÆÆ÷·¾¶¡£Äú¿ÉÒÔƾ֤×Ô¼ºµÄ¿ØÖÆÆ÷ºÍÊÓͼµÄÃû³Æ¾ÙÐиü¸Ä¡£
ÏÖÔÚÎÒÃÇÒѾ½«Â·ÓÉÌí¼Óµ½Ó¦ÓóÌÐòÖУ¬ÈÃÎÒÃÇÀ´½¨ÉèÒ»¸öÁ´½Ó¡£Äú¿ÉÒÔ½«ÒÔÏ´úÂëÌí¼Óµ½ÄúµÄÊÓͼÎļþÖУº
<a href="{{ route('password.request') }}">Forgot your password?</a>
µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬µ±Óû§µã»÷ÉÏÃæµÄÁ´½Óʱ£¬ËûÃǽ«±»´øµ½ÒÅÍüÃÜÂëÒ³Ã棬²¢¿ÉÒÔÊäÈëËûÃǵĵç×ÓÓʼþµØµãÒÔÖØÖÃËûÃǵÄÃÜÂë¡£
½áÂÛ£º
±¾ÎÄÖУ¬ÎÒÃÇÌÖÂÛÁËLaravelµÄÒÅÍüÃÜÂ빦Ч¡£ÎÒÃÇÊ×ÏÈÏàʶÁËÒÅÍüÃÜÂëµÄ»ù´¡Á÷³Ì£¬Ëæºóͨ¹ýÉèÖõç×ÓÓʼþ¡¢ÌìÉúÃÜÂëÖØÖôúÂë¡¢×Ô½ç˵ÃÜÂëÖØÖÃÊÓͼºÍÓʼþÐÂÎŵȰ취£¬ÀֳɵØÉèÖúÍ×Ô½ç˵ÁËÒÅÍüÃÜÂ빦Ч¡£×îÖÕ£¬ÎÒÃǽ«ÆäÓÃÓÚ×ðÁú¿Ê±Ó¦ÓóÌÐòÖУ¬²¢½«ÆäÓëÐëÒªµÄ·ÓɺÍÒ³ÃæÁ´½ÓÏàÅþÁ¬¡£Í¨¹ýLaravelµÄÒÅÍüÃÜÂ빦Ч£¬ÎÒÃÇ¿ÉÒÔÇáËɵØÔöÇ¿×ðÁú¿Ê±Ó¦ÓóÌÐòµÄÇå¾²ÐÔºÍÓû§ÌåÑé¡£
ÒÔÉϾÍÊÇlaravel ÒÅÍüÃÜÂëµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡