加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – Laravel登录(Auth :: attempt)无效

发布时间:2020-12-14 19:38:50 所属栏目:大数据 来源:网络整理
导读:嗨,我有Laravel的问题.我无法登录.我尝试了我在网上找到的所有内容.也许有人知道我弄错了什么.创建新用户并发送电子邮件工作正常.登录我不知道循环工作回来查看没有错误或任何消息.我在laravel中使用调试模式,但它没有显示任何错误. ?php class AccountContr
嗨,我有Laravel的问题.我无法登录.我尝试了我在网上找到的所有内容.也许有人知道我弄错了什么.创建新用户并发送电子邮件工作正常.登录我不知道循环工作回来查看没有错误或任何消息.我在laravel中使用调试模式,但它没有显示任何错误.

<?php
    class AccountController extends BaseController {

        //Sign in function start

        public function getSignIn(){
            return View::make('account.signin');
        }

        public function postSignIn(){
            $validator = Validator::make(Input::all(),array(
                    'email'                 => 'required|email','username'          => 'required'
                )
            );

            if($validator->fails()){

                return Redirect::route('account-sign-in')
                    ->withErrors($validator)
                    ->withInput();  

            }else{

                if($auth = Auth::attempt(array(
                    'email' => Input::get('email'),'password' => Input::get('password'),'active' => 1

                ),true)){
                    return Redirect::to('/');
                }else{
                    return Redirect::route('account-sign-in')
                        ->with('global','Email/password wrong or account not activated');
                }

            }

            return Redirect::route('account-sign-in')
                ->with('global','There was a problem signing you in');
        }

        //Sign in function end




        //Create new account function start

        public function getCreate(){
            return View::make('account.create');
        }

        public function postCreate(){
            $validator = Validator::make(Input::all(),array(
                    'email'                 => 'required|max:50|email|unique:users','username'          => 'required|max:20|min:3|unique:users','password'          => 'required|min:6','password_again'    => 'required|same:password'
                )
            );


            if($validator->fails()){
                return Redirect::route('account-create')
                    ->withErrors($validator)
                    ->withInput();
            }else{

                $email      = Input::get('email');
                $username   = Input::get('username');
                $password   = Input::get('password');

                //Activation code

                $code       = str_random(60);

                $user = User::create(array(
                    'email'         => $email,'username'  => $username,'password'  => Hash::make($password),'code'      => $code,'active'    => 0

                ));

                if($user){

                    //Send link function start

                    Mail::send('emails.auth.active',array(
                        'link' => URL::route('account-active',$code),'username' => $username),function($message) use ($user){$message->to($user->email,$user->username)->subject('Activation your account');});

                    //Send link function end

                    return Redirect::route('home')
                        ->with('global','Your account has been created! We have sent you an email with activation link');
                }
            }
        }
        public function getActivate($code){
            $user = User::where('code','=',$code)->where('active',0);

            if($user->count()){
                $user = $user->first();

                //Update user to active state

                $user->active   = 1;
                $user->code         ='';

                if($user->save()){
                    return Redirect::route('home')
                        ->with('global','Activated! You can now sign in!');
                }
            }
                return Redirect::route('home')
                    ->with('global','We could not activate your account. Please try again later.');


        }

        //Create new account function end

    }

?>

解决方法

在postSignIn()验证器中,您从逻辑和错误消息中可以看到,您需要指定用户名,您需要用户指定要登录的电子邮件和密码.而是尝试:

$validator = Validator::make(Input::all(),array(
        'email'                 => 'required|email','password'          => 'required'
    )
);

使用电子邮件和密码提交登录表单时,验证程序始终会失败,因为没有用户名输入

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读