亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Laravel form validation directly displays Forbidden solution?
過去多啦不再A夢(mèng)
過去多啦不再A夢(mèng) 2017-05-16 16:53:34
0
1
569
// App\Http\Requests\LoginRequest

<?

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class LoginRequest extends FormRequest
{

    public function authorize()
    {
        return false;
    }


    public function rules()
    {
        return [
            'username' => [
                'required',
            ]
        ];
    }
}
// App\Http\Controllers\Admin
<?php


namespace App\Http\Controllers\Admin;
use App\Http\Requests\LoginRequest;
use Illuminate\Cache\RateLimiter;


/**
 * Class Auth
 * @package App\Http\Controllers\Admin
 */
class Auth extends BaseController
{

    public function login()
    {
        return view('admin.login');
    }

    public function dologin(LoginRequest $request)
    {
        dd($request->fails());

        $rl = app(RateLimiter::class);
        $res = $rl->tooManyAttempts($this->getFailKey($request),5,3);
        if ($res)
            return redirect()->back()->withErrors(['errors'=>'3分鐘內(nèi)錯(cuò)誤超過5次,請(qǐng)稍后重試']);
        $rl->hit($this->getFailKey($request));
    }

    private function getFailKey(Request $request)
    {
        return $request->input('username').':'.$request->ip();
    }
}

postForbidden is displayed directly after logging in. Why?

update The problem has been solved.

authorize should return true. Return false and a forbidden message will appear. But here comes the problem. I want to handle the logic myself when auth is false. What to do?

過去多啦不再A夢(mèng)
過去多啦不再A夢(mèng)

reply all(1)
大家講道理

Override the following method of the base class:

    /**
     * Get the response for a forbidden operation.
     *
     * @return \Illuminate\Http\Response
     */
    public function forbiddenResponse()
    {
        return new Response('Forbidden', 403);
    }
    

Override this method according to your own logic under your LoginRequest.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template