【问题标题】:authentication fail in laravel and sentry packagelaravel 和 sentry 包中的身份验证失败
【发布时间】:2014-12-28 15:49:05
【问题描述】:

我试图在我的新应用程序中使用 Sentry 2 来处理所有用户和组。
在使用哨兵对用户进行身份验证后,当尝试重定向到另一个页面时,身份验证丢失
在测试代​​码中检查函数Sentry::check()的输出为真

public function Login(){
               $credentials = array(
                        'username'    => 'Mouad',
                        'password' => 'test',
                    );

                // Authenticate the user
               $user = Sentry::authenticate($credentials, false);
               var_dump(Sentry::check());


    }

会话输出

array (size=3)
  '_token' => string 'slAqB8IYYrSPPSC1k1A2i8aTpkpVklPad3fiqoFA' (length=40)
  'flash' => 
    array (size=2)
      'old' => 
        array (size=0)
          empty
      'new' => 
        array (size=0)
          empty
  'cartalyst_sentry' => 
    array (size=2)
      0 => null
      1 => string '$2y$08$nWq4rHlacrNykXhQykipJ.0c8mr6VK4o364UvatPtJZ1kM1W8KH7K' (length=60)

当我在身份验证后尝试重定向页面时,'cartalyst_sentry' 会话条目已更改并且检查函数Sentry::check() 的输出为假

 public function Login(){
               $credentials = array(
                        'username'    => 'Mouad',
                        'password' => 'test',
                    );

                // Authenticate the user
               $user = Sentry::authenticate($credentials, false);
               return Redirect::to('admin');


    }
    public function Admin(){
        $data = Session::all();
        var_dump($data);
        var_dump(Sentry::check());
    }

路由配置简单

Route::get('/', 'MainController@Index');
Route::get('create', 'MainController@Create');
Route::get('login', 'MainController@Login');
Route::get('admin', 'MainController@Admin');
Route::get('logout', 'MainController@Logout');

会话配置是默认的,存储文件夹是可写的

【问题讨论】:

    标签: php laravel laravel-4 cartalyst-sentry


    【解决方案1】:

    你可以试试这个方法:

    登录控制器

    public function store() {
            if (Input::get('remember') == "") {
                $remember = false;
            } else {
                $remember = true;
            }
            $user = [
                'email' => Input::get('email'),
                'password' => Input::get('password')
            ];
    
            $login = User::login($user, $remember);
    
        }
    

    用户模型$login 是对模态用户的调用):

    public static function login(array $credentials, $remember) {
        try {
            $user = Sentry::findUserByCredentials($credentials);
    
           // PROCESS TO THE LOGIN AND REDIRECT TO THE DASHBOARD PAGE
              $user->is_logged_in = 1;
              $user->save();
              Sentry::login($user, $remember);    
              return \Redirect::route('admin.dashboard.index');
    
        } catch (\Cartalyst\Sentry\Users\LoginRequiredException $e) {
            return \Redirect::back()->withErrors(['auth_message' => 'U moet alle velden in vullen']);
        } catch (\Cartalyst\Sentry\Users\PasswordRequiredException $e) {
            return \Redirect::back()->withErrors(['auth_message' => 'U moet het wachtwoordveld invullen']);
        } catch (\Cartalyst\Sentry\Users\WrongPasswordException $e) {
            return \Redirect::back()->withErrors(['auth_message' => 'Het opgegeven email/wachtwoord is onjuist']);
        } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) {
            return \Redirect::back()->withErrors(['auth_message' => 'Het opgegeven email/wachtwoord is onjuist']);
        } catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e) {
            return \Redirect::back()->withErrors(['auth_message' => 'Dit account is nog niet geactiveerd']);
        } catch (\Cartalyst\Sentry\Throttling\UserSuspendedException $e) {
            return \Redirect::back()->withErrors(['auth_message' => 'Dit account heeft een timeout']);
        } catch (\Cartakyst\Sentry\Throttling\UserBannedExveption $e) {
            return \Redirect::back()->withErrors(['auth_message' => 'Dit account is van onze site verbannen']);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-08-16
      • 1970-01-01
      • 2015-01-02
      • 1970-01-01
      • 2020-08-17
      • 2014-05-29
      • 2014-07-05
      相关资源
      最近更新 更多