コード例 #1
0
ファイル: AuthController.php プロジェクト: pinodex/boardy
 public function login(Request $request, Application $app)
 {
     if (Auth::user()) {
         return $app->redirect($app->path('site.index'));
     }
     $vars = array();
     $form = Form::create('login_form')->add('username', Type\TextType::class, ['data' => Session::get('lastUsername'), 'attr' => ['autofocus' => true]])->add('password', Type\PasswordType::class)->add('remember', Type\CheckboxType::class, ['required' => false, 'label' => 'Remember me']);
     $form = $form->getForm();
     $form->handleRequest($request);
     Form::handleFlashErrors($form, 'login_form');
     if ($form->isValid()) {
         $data = $form->getData();
         $user = Auth::attempt($data);
         Session::set('lastUsername', $data['username']);
         if (!$user) {
             Form::flashError('login_form', 'Invalid username and/or password');
             return $app->redirect($app->path('auth.login'));
         }
         if ($data['remember']) {
             // Change cookie lifetime to 1 month.
             Session::migrate(false, 60 * 60 * 24 * 30);
         }
         Auth::login($user);
         return $app->redirect($app->path('site.index'));
     }
     $vars['login_form'] = $form->createView();
     return Theme::view('auth/login', $vars);
 }
コード例 #2
0
ファイル: Auth.php プロジェクト: pinodex/boardy
 /**
  * Get logged in user
  *
  * @return Boardy\Models\User
  */
 public static function user()
 {
     if (self::$user) {
         return self::$user;
     }
     if ($userId = Session::get('userId')) {
         if ($user = User::find($userId)) {
             $user->touch();
             self::$user = $user;
             return $user;
         }
     }
 }