示例#1
0
 public function testFormBasics()
 {
     $f = new Form();
     $f->setAction('/');
     $f->setMethod('POST');
     $this->assertTrue($f->getAction() == '/');
     $this->assertTrue($f->getMethod() == 'POST');
     Registry::getInstance()->set('ViewPath', dirname(__FILE__) . '/data/view/');
     $this->assertTrue($f->render('form') == '/POST');
     Registry::getInstance()->set('ViewPath', '');
     $this->assertTrue(strpos((string) $f, '<form') !== false);
 }
示例#2
0
 /**
  * Handles user login (form and processing)
  */
 public function login()
 {
     $isLoginFailure = false;
     if ($this->request->getMethod() == 'POST') {
         $token = $this->getParam('token');
         if (!isset($token, $_SESSION['login_token']) || $token !== $_SESSION['login_token']) {
             $isLoginFailure = true;
         } else {
             unset($_SESSION['login_token']);
             $user = $this->userStore->getByEmail($this->getParam('email'));
             if ($user && password_verify($this->getParam('password', ''), $user->getHash())) {
                 session_regenerate_id(true);
                 $_SESSION['phpci_user_id'] = $user->getId();
                 $response = new b8\Http\Response\RedirectResponse();
                 $response->setHeader('Location', $this->getLoginRedirect());
                 return $response;
             } else {
                 $isLoginFailure = true;
             }
         }
     }
     $form = new b8\Form();
     $form->setMethod('POST');
     $form->setAction(PHPCI_URL . 'session/login');
     $email = new b8\Form\Element\Email('email');
     $email->setLabel(Lang::get('email_address'));
     $email->setRequired(true);
     $email->setContainerClass('form-group');
     $email->setClass('form-control');
     $form->addField($email);
     $pwd = new b8\Form\Element\Password('password');
     $pwd->setLabel(Lang::get('password'));
     $pwd->setRequired(true);
     $pwd->setContainerClass('form-group');
     $pwd->setClass('form-control');
     $form->addField($pwd);
     $pwd = new b8\Form\Element\Submit();
     $pwd->setValue(Lang::get('log_in'));
     $pwd->setClass('btn-success');
     $form->addField($pwd);
     $tokenValue = $this->generateToken();
     $_SESSION['login_token'] = $tokenValue;
     $token = new b8\Form\Element\Hidden('token');
     $token->setValue($tokenValue);
     $form->addField($token);
     $this->view->form = $form->render();
     $this->view->failed = $isLoginFailure;
     return $this->view->render();
 }
示例#3
0
 /**
  * Handles user login (form and processing)
  */
 public function login()
 {
     $isLoginFailure = false;
     if ($this->request->getMethod() == 'POST') {
         $user = $this->userStore->getByEmail($this->getParam('email'));
         if ($user && password_verify($this->getParam('password', ''), $user->getHash())) {
             $_SESSION['user_id'] = $user->getId();
             header('Location: ' . $this->getLoginRedirect());
             die;
         } else {
             $isLoginFailure = true;
         }
     }
     $form = new b8\Form();
     $form->setMethod('POST');
     $form->setAction(PHPCI_URL . 'session/login');
     $email = new b8\Form\Element\Email('email');
     $email->setLabel('Email Address');
     $email->setRequired(true);
     $email->setContainerClass('form-group');
     $email->setClass('form-control');
     $form->addField($email);
     $pwd = new b8\Form\Element\Password('password');
     $pwd->setLabel('Password');
     $pwd->setRequired(true);
     $pwd->setContainerClass('form-group');
     $pwd->setClass('form-control');
     $form->addField($pwd);
     $pwd = new b8\Form\Element\Submit();
     $pwd->setValue('Log in &raquo;');
     $pwd->setClass('btn-success');
     $form->addField($pwd);
     $this->view->form = $form->render();
     $this->view->failed = $isLoginFailure;
     return $this->view->render();
 }