簡體   English   中英

我無法更改項目中的錯誤消息

[英]I can't change error message in my project

我有一個 Laravel 8 項目。 我想更改 magic auth 錯誤消息。 我確實像這樣更新了我的代碼。

'This code has already been used'我在代碼上下文中用此消息替換了此消息'You will get a link in your email inbox every time you need to log in or register. Keep in mind that each link can only be used once.' 'You will get a link in your email inbox every time you need to log in or register. Keep in mind that each link can only be used once.'

舊 AuthController.php

public function magicauth(Request $request)
{
    $auth = app('firebase.auth');

    $email = $request->email;
    $oobCode = $request->oobCode;

    $exits = User::where('email', $email)->first();
    if(!is_null($exits))
    {
        if(is_null($exits->firebaseUserId))
        {
            $fUser = $auth->createUser([
                'email' => $exits->email,
                'emailVerified' => true,
                'displayName' => $exits->name,
                'password' => ($exits->email . $exits->id),
            ]);
            $firebaseID = $fUser->uid;

            $exits->update([
                'firebaseUserId' => $firebaseID
            ]);
        }
    }

    try 
    {
        $result = $auth->signInWithEmailAndOobCode($email, $oobCode);
 
        $firebaseID = $result->firebaseUserId();            
        $user = User::where('firebaseUserId', $firebaseID)->first();
        if(is_null($user))
        {
            return view('auth.messages', ['message' => 'User not found']);
        }

        if($user->role_id != 3)
        {
            return view('auth.messages', ['message' => 'User is not creator']);
        }

        Auth::login($user); 

        return redirect()->route('home');
    } catch (\Exception $e) {
        return view('auth.messages', ['message' => 'This code has already been used.']);
    }

    return redirect()->route('login');
}

新 AuthController.php

public function magicauth(Request $request)
{
    $auth = app('firebase.auth');

    $email = $request->email;
    $oobCode = $request->oobCode;

    $exits = User::where('email', $email)->first();
    if(!is_null($exits))
    {
        if(is_null($exits->firebaseUserId))
        {
            $fUser = $auth->createUser([
                'email' => $exits->email,
                'emailVerified' => true,
                'displayName' => $exits->name,
                'password' => ($exits->email . $exits->id),
            ]);
            $firebaseID = $fUser->uid;

            $exits->update([
                'firebaseUserId' => $firebaseID
            ]);
        }
    }

    try 
    {
        $result = $auth->signInWithEmailAndOobCode($email, $oobCode);
 
        $firebaseID = $result->firebaseUserId();            
        $user = User::where('firebaseUserId', $firebaseID)->first();
        if(is_null($user))
        {
            return view('auth.messages', ['message' => 'User not found']);
        }

        if($user->role_id != 3)
        {
            return view('auth.messages', ['message' => 'User is not creator']);
        }

        Auth::login($user); 

        return redirect()->route('home');
    } catch (\Exception $e) {
        return view('auth.messages', ['message' => 'You will get a link in your email inbox every time you need to log in or register. Keep in mind that each link can only be used once.']);
    }

    return redirect()->route('login');
}

但是當我現在嘗試時,我看到消息沒有改變。 我怎樣才能解決這個問題?

請按照以下步驟操作:

  1. 如果你還沒有這樣做,刪除或重命名舊的 AuthController class,只使用新的,帶有新消息。
  2. 確保路由轉到新 controller 中的方法
  3. 運行composer dump-autoload

如果問題仍然存在,我會檢查 php 中是否啟用了某種緩存機制,例如 opcache。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM