简体   繁体   English

身份验证问题。 Laravel

[英]Problems with authentication. Laravel

I'm making authentication using Laravel framework. 我正在使用Laravel框架进行身份验证。 It's works, after passing a valid data to form auth will be perfomed. 它的工作原理是,在将有效数据传递给表单auth之后,将执行该操作。 But there is a problem: after refreshing of page I'm losing authenticated user. 但是有一个问题:刷新页面后,我失去了经过身份验证的用户。

Here my UserController method: 这是我的UserController方法:

public function LogIn(){
    $Data = Input::all();

    $Validator = $this::ValidateInputData($Data,'L');

    if($Validator->fails())
    {
        print "Ошибка, авторизация не произведена.";
        $Errors = $Validator->messages()->toArray();

        return View::make('signupView')->with('Errors',$Errors);
    }
    else{

     $User = User::ProceedLogining($Data,$this->GetStayedStatus(Input::get('Stay')));
     if ($User instanceof \Illuminate\Database\Eloquent\Model)
     {
         Auth::login($User,$this->GetStayedStatus(Input::get('Stay')));

         return Redirect::to('/');
     }

      else{

          $Alert = 'Ошибка авторизации, проверьте правильность ввода данных.';
          return  View::make('signupView')->with('Alert',$Alert);
      }
    }
}

And my Model method: 而我的Model方法:

public static function ProceedLogining($Data,$StayStatus){

        if (Auth::attempt([
            'login' => $Data['Login'],
            'password' => $Data['Password']
        ], $StayStatus))

         return Auth::user();
    else return 'Auth error';

}

Of course, first proposition will be checking "GetStayedStatus" function, but I tried pass 'true' values, It doesn't bring any positive results 当然,第一个命题将是检查“ GetStayedStatus”功能,但我尝试传递“ true”值,但不会带来任何积极结果

Ok. 好。 I solved this. 我解决了 In my layout I had such code: 在我的布局中,我有这样的代码:

  @if(Sentry::check())
                    <li class="dropdown">
                        <a href="" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><span class="glyphicon glyphicon-user"></span> Профиль {{Sentry::getUser()->login}} <span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="#">Мой кабинет (My profile) <span class="glyphicon glyphicon-th-large"></span></a></li>
                            <li><a href="#">Обновления (News) <span class="glyphicon glyphicon-tasks"></span> </a></li>
                            <li><a href="#">Сообщения (Messages) <span class="glyphicon glyphicon-comment"></span></a></li>
                            <li class="divider"></li>
                            <li><a href='logout'>Выход (log out)  <span class="glyphicon glyphicon-log-out"></span></a></li>
                        </ul>
                    </li>
                @else
                    <div class="sign-up">
                        <a class="alert-link" href="{{URL::to("signup/")}}">Вход / Регестрация (Sign up) </a>
                    </div> <!-- End of sign-up -->
                @endif

In previous post I used built-in 'Auth' class, but in this you can see 'Sentry'- it doesn't matter, my problem still hasn't been solved. 在上一篇文章中,我使用了内置的“ Auth”类,但是在此您可以看到“ Sentry”-没关系,我的问题仍然没有解决。

So there are some actions what actually can help you. 因此,有些行动实际上可以为您提供帮助。 1) Check your users table and ensure that you have 'id' field and it set as primary key. 1)检查您的用户表,并确保您具有“ id”字段并将其设置为主键。 2) Check your session.php, which located at App/config/ . 2)检查您的session.php,它位于App / config /中。 Set 'driver' property to 'file'. 将“驱动程序”属性设置为“文件”。 3) Unfortunately, these actions don't give any positive results. 3)不幸的是,这些行动并没有带来任何积极的结果。 I will describe my instance. 我将描述我的实例。

Pay attention to this string: <li><a href='logout'>Выход (log out) <span class="glyphicon glyphicon-log-out"></span></a></li> , when I have this problem 'href' property was set to 'Sentry::LogOut()' or 'Auth::LogOut()', then I change it to route and problem gone. 请注意以下字符串: <li><a href='logout'>Выход (log out) <span class="glyphicon glyphicon-log-out"></span></a></li>遇到此问题,将“ href”属性设置为“ Sentry :: LogOut()”或“ Auth :: LogOut()”,然后将其更改为路由,问题就消失了。

Hope it will help! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM