Laravel登录表单拒绝正确的登录凭据

时间:2015-12-12 13:56:08

标签: login eloquent laravel-5.1 laravel-routing laravel-blade

我对这段代码的问题感到困惑。它曾在一个测试环境中工作但现在拒绝工作。我的实现是针对用户反应的,因此: 注册页面(确认代码发送到电子邮件确认) - >电子邮件(用于确认并单击链接以返回登录页面) - >登录页面(供用户使用其凭据登录)。 Everythng继续平滑直到登录,当我输入登录用户名/电子邮件和密码时,它认为它不匹配hixh我非常确定它匹配,因为我使用复制和粘贴。 控制器:

public function store(UserRequest $userRequest)
    {
        $confirmation_code = str_random(30);

        $users = new User;
        $users->firstname             = $userRequest->firstname;
        $users->lastname              = $userRequest->lastname;
        $users->email                 = $userRequest->email;
        $users->username              = $userRequest->username;
        $users->password              = $userRequest->password;
        $users->confirmation_code     = $confirmation_code;

        Mail::send('email.verify', ['users' => $users, 'confirmation_code' => $confirmation_code ], 

            function ($message) use ($users) {

            $message->from('members@schoolproject.com', 'School Project Member');
            $message->to($users->email, $users->firstname)->subject('Registration process Message!');
        });

        $users->save();
       // return redirect()->route('index');
        return redirect()->action('UserController@index')->with('message', 'You have done successfully');
    }


    public function confirm($confirmation_code)
    {
        if( ! $confirmation_code)
        {
            throw new InvalidConfirmationCodeException;
        }

        $users = User::whereConfirmationCode($confirmation_code)->first();

        if ( ! $users)
        {
            throw new InvalidConfirmationCodeException;
        }

        $users->confirmed = 1;
        $users->confirmation_code = null;
        $users->save();

        //Flash::message('You have successfully verified your account.');
        //return redirect()->route('users.index');
        //return view('userpages.login');
        return redirect()->action('DashboardController@login');
    }


    public function login(Request $request){

        if (Auth::attempt(['username' => $request->username, 'password' => $request->password])) {
                return redirect()->route('details')->with('message', 'You have successfully logged in');
        } 

        elseif (Auth::attempt(['email'=> $request->username, 'password' => $request->password])) {
                return redirect()->route('details')->with('message', 'You have successfully logged in');
        } 

        else {
            return redirect('login')
            ->with('message', 'Your username/password combination is not correct')
            ->withInput();
        }
    }

登录表单:

登录

{!! Form::open(array('url' => 'login', 'method' => 'post')) !!}
{!! Form::token() !!}

    {!! Form::label('username', 'Username') !!}<br />
    {!! Form::text('username', Input::old('username')) !!} <br />

    {!! Form::label('password', 'Password') !!}<br />
    {!! Form::password('password') !!} <br />

    {!! Form::submit('Login') !!}

{!! Form::close() !!}

0 个答案:

没有答案