亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

laravel的用戶修改密碼與綁定郵箱的詳細(xì)操作

 更新時(shí)間:2021年09月07日 16:16:33   作者:陸小天奧利給  
這篇文章主要介紹了laravel的用戶修改密碼與綁定郵箱的詳細(xì)操作,本文給大家介紹的非常詳細(xì),對laravel修改密碼與綁定郵箱的操作感興趣的朋友一起看看吧

一、修改密碼

1.1 創(chuàng)建修改密碼控制器

運(yùn)行命令php artisan make:controller Auth/PasswordController

在這里插入圖片描述

寫入修改密碼方法:

/**
     * 修改密碼
     */
    public function updatePassword(Request $request) {
        $request->validate([
            'old_password' => 'required|min:6|max:16',
            'password' => 'required|min:6|max:16|confirmed',
        ], [
            'old_password.required' => '舊密碼不能為空',
            'old_password.min' => '舊密碼最少6個(gè)字符',
            'old_password.max' => '舊密碼最多16個(gè)字符',
        ]);

        // 舊密碼
        $old_password = $request->input('old_password');
        // 用戶實(shí)例
        $user = auth('api')->user();
        // 驗(yàn)證舊密碼是否正確
        if (!password_verify($old_password, $user->password)) {
            return $this->response->errorBadRequest('舊密碼不正確');
        } 
        // 更新用戶密碼  
        $user->password = bcrypt($request->input('password'));
        $user->save();

        return $this->response->noContent();
    }

在這里插入圖片描述

1.2 創(chuàng)建修改密碼路由

 // 修改密碼
            $api->post('password/update', [PasswordController::class, 'updatePassword']);

在這里插入圖片描述

1.3 測試效果

在這里插入圖片描述

二、綁定郵箱

 2.1 綁定郵箱控制器

運(yùn)行命令php artisan make:controller Auth/BindController創(chuàng)建綁定郵箱的控制器:

在這里插入圖片描述

寫入發(fā)送郵箱驗(yàn)證碼和更新郵箱的處理函數(shù):

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\BaseController;
use App\Mail\SendEmailCode;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class BindController extends BaseController
{
    /**
     * 獲取郵件的驗(yàn)證碼
     */
    public function emailCode(Request $request) {
        $request->validate([
            'email' => 'required|email'
        ]);

        // 發(fā)送驗(yàn)證碼到郵件
        Mail::to($request->input('email'))->queue(new SendEmailCode($request->input('email')));
        return $this->response->noContent();
    }

    /**
     * 更新郵箱
     */
    public function updateEmail(Request $request) {
        $request->validate([
            'email' => 'required|email',
            'code' => 'required'
        ], [
            'code.required' => "驗(yàn)證碼不能為空",
        ]);

        // 驗(yàn)證code是否正確
        if (cache($request->input('email')) != $request->input('code')) {
            return $this->response->errorBadRequest('驗(yàn)證碼或郵箱錯(cuò)誤!');
        }

        // 更新郵箱
        $user = auth('api')->user(); 
        $user->email = $request->input('email');
        $user->save();
        return $this->response->noContent();
    } 
}

如果修改了隊(duì)列了,就要重啟隊(duì)列,命令sudo supervisorctl restart all

2.2 創(chuàng)建對應(yīng)路由

  // 發(fā)送郵件驗(yàn)證碼
            $api->post('email/code', [BindController::class, 'emailCode']);

            // 更新郵箱
            $api->post('email/update', [BindController::class, 'updateEmail']);

在這里插入圖片描述

2.3 創(chuàng)建發(fā)送郵件的類

運(yùn)行命令php artisan make:mail SendEmailCode:

在這里插入圖片描述

寫入:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;

class SendEmailCode extends Mailable
{
    use Queueable, SerializesModels;

    protected $email;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($eamil)
    {
        $this->email = $eamil;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        // 生成code
        $code = rand(1000, 9999);

        // 獲取郵箱

        // 使用緩存郵箱對應(yīng)的code
        Cache::put($this->email, $code, now()->addMinute(5)); // 5分鐘過期

        return $this->view('emails.send-email-code', ['code' => $code]);
    }
}

在這里插入圖片描述

創(chuàng)建發(fā)送郵件的模版:

在這里插入圖片描述

模版寫入:

<h3>郵箱驗(yàn)證碼是:{{$code}}</h3>
<h3>驗(yàn)證碼5分鐘內(nèi)有效,請及時(shí)使用!</h3>

2.4 測試效果

在這里插入圖片描述

可以看到這邊收到郵箱驗(yàn)證碼。
測試更新的輸入郵箱不正確或者驗(yàn)證碼不正確:

在這里插入圖片描述

輸入正確的郵箱和驗(yàn)證碼就會(huì)修改了。

到此這篇關(guān)于laravel的用戶修改密碼與綁定郵箱的文章就介紹到這了,更多相關(guān)laravel修改密碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • PHP JWT初識(shí)及其簡單示例

    PHP JWT初識(shí)及其簡單示例

    這篇文章主要介紹了PHP JWT初識(shí)及其簡單示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-10-10
  • PHP中讀取文件的8種方法和代碼實(shí)例

    PHP中讀取文件的8種方法和代碼實(shí)例

    這篇文章主要介紹了PHP中讀取文件的8種方法和代碼實(shí)例,本文總結(jié)了PHP中讀取文件的8個(gè)函數(shù),每一個(gè)都附有使用例子及注意事項(xiàng)等,需要的朋友可以參考下
    2014-08-08
  • 基于php設(shè)計(jì)模式中單例模式的應(yīng)用分析

    基于php設(shè)計(jì)模式中單例模式的應(yīng)用分析

    本篇文章是對php設(shè)計(jì)模式中單例模式的應(yīng)用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • PHP與Ajax相結(jié)合實(shí)現(xiàn)登錄驗(yàn)證小Demo

    PHP與Ajax相結(jié)合實(shí)現(xiàn)登錄驗(yàn)證小Demo

    AJAX即“Asynchronous Javascript And XML”(異步JavaScript和XML),是指一種創(chuàng)建交互式網(wǎng)頁應(yīng)用的網(wǎng)頁開發(fā)技術(shù)。接下來通過本文給大家分享PHP與Ajax相結(jié)合實(shí)現(xiàn)登錄驗(yàn)證小Demo,對php ajax實(shí)現(xiàn)登錄驗(yàn)證相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧
    2016-03-03
  • ThinkPHP自動(dòng)完成中使用函數(shù)與回調(diào)方法實(shí)例

    ThinkPHP自動(dòng)完成中使用函數(shù)與回調(diào)方法實(shí)例

    這篇文章主要介紹了ThinkPHP自動(dòng)完成中使用函數(shù)與回調(diào)方法,實(shí)例分析了ThinkPHP中自動(dòng)填充的用法以及使用函數(shù)與回調(diào)的方法,是非常實(shí)用的技巧,需要的朋友可以參考下
    2014-11-11
  • Laravel構(gòu)建即時(shí)應(yīng)用的一種實(shí)現(xiàn)方法詳解

    Laravel構(gòu)建即時(shí)應(yīng)用的一種實(shí)現(xiàn)方法詳解

    這篇文章主要給大家介紹了關(guān)于Laravel構(gòu)建即時(shí)應(yīng)用的一種實(shí)現(xiàn)方法,即時(shí)通訊在我們?nèi)粘5拈_發(fā)中經(jīng)常會(huì)遇到,本文通過示例代碼介紹的非常詳細(xì),需要的朋友們可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-08-08
  • 一個(gè)比較不錯(cuò)的PHP日歷類分享

    一個(gè)比較不錯(cuò)的PHP日歷類分享

    這篇文章主要介紹了一個(gè)比較不錯(cuò)的PHP日歷類分享,本文直接給出了實(shí)現(xiàn)的類代碼和使用方法示例,需要的朋友可以參考下
    2014-11-11
  • php獲取referer防非法訪問

    php獲取referer防非法訪問

    這篇文章主要介紹了php獲取referer防非法訪問,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • LNMP部署laravel以及xhprof安裝使用教程

    LNMP部署laravel以及xhprof安裝使用教程

    這篇文章主要介紹了關(guān)于在LNMP上部署laravel以及xhprof安裝使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-09-09
  • thinkPHP導(dǎo)出csv文件及用表格輸出excel的方法

    thinkPHP導(dǎo)出csv文件及用表格輸出excel的方法

    這篇文章主要介紹了thinkPHP導(dǎo)出csv文件及用表格輸出excel的方法,涉及thinkPHP針對表格與Excel文件的操作技巧,需要的朋友可以參考下
    2015-12-12

最新評論