Beispiel #1
0
 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);
 }
Beispiel #2
0
 /**
  * Remove session and logout user
  */
 public static function logout()
 {
     Session::remove('userId');
     EventDispatcher::dispatch('auth.logout', self::$user);
 }