Ejemplo n.º 1
0
    public function postLogin()
    {
        $this->validate(request(), [
            'username'  => 'required',
            'password'  => 'required',
        ]);

        if (User::login(request())) {
            return redirect()->intended('/');
        } else {
            return back()->withErrors('用户名或密码错误');
        }
    }
 public function loginAction()
 {
     if (!$this->isPostRequest()) {
         return $this->redirect('home');
     } else {
         $pd = $this->getPostData();
         $pass = md5($pd['password']);
         $u = User::login($pd['email'], $pass);
         $_SESSION['logged']['id'] = $u['id'];
         $_SESSION['logged']['name'] = $u['name'];
         $_SESSION['logged']['email'] = $u['email'];
         $_SESSION['logged']['power'] = $u['power'];
         return $this->redirectOldLink();
     }
 }
Ejemplo n.º 3
0
 /**
  * Login action method
  *
  * @return void
  */
 public function login()
 {
     $this->prepareView('login.phtml');
     $this->view->title = 'Please Login';
     $this->view->form = new Form\Login($this->application->config()['forms']['App\\Form\\Login']);
     if ($this->request->isPost()) {
         $auth = new Auth\Auth(new Auth\Adapter\Table('App\\Table\\Users', Auth\Auth::ENCRYPT_BCRYPT));
         $this->view->form->addFilter('strip_tags')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($this->request->getPost(), $auth);
         $user = new Model\User();
         $session = new Model\Session();
         if ($this->view->form->isValid() && $session->validate($auth->adapter()->getUser(), $this->application->config())) {
             $user->login($auth->adapter()->getUser(), $this->sess, $this->application->config());
             $this->redirect('/');
         } else {
             if (null !== $auth->adapter()->getUser() && null !== $auth->adapter()->getUser()->id) {
                 $user->failed($auth->adapter()->getUser());
                 if ($this->view->form->isValid()) {
                     $this->sess->setRequestValue('failed', true);
                     $this->redirect('/login');
                 }
             }
         }
     }
     $this->send();
 }