Exemplo n.º 1
0
 public function executeLogin($request)
 {
     $form = new LoginForm();
     $form->bind(array('name' => $request->getParameter('name'), 'password' => $request->getParameter('password')));
     if ($form->isValid()) {
         $values = $form->getValues();
         $user = User::getByPassword($values['name'], $values['password']);
         if ($user) {
             $output = '<rsp stat="ok">' . $user->getXML(false, true) . '</rsp>';
         }
     } else {
         $output = '<rsp stat="fail"><err code="1" msg="' . $form->getErrorSchema() . '" /></rsp>';
     }
     $this->output = $output;
     $this->setTemplate('index');
 }
Exemplo n.º 2
0
 /**
  * Login process
  */
 public function executeLogin(sfWebRequest $r)
 {
     // If we've posted the form
     if ($r->isMethod('post')) {
         // Launching form
         $login = new LoginForm();
         // Binding fields to validators
         $login->bind($r->getParameter($login->getName()));
         // Doing a little sleep to prevent automatic bruteforce
         sleep(1);
         // If form is valid
         if ($login->isValid()) {
             // Fetching account for this user
             $q = Doctrine::getTable("Users")->findOneByUsername($login->getValue("username"));
             // Setting cookies for auto-login
             $this->getResponse()->setCookie("uid", $q->getId(), time() + 365 * 3600 * 24);
             $this->getResponse()->setCookie("pwd", $q->getCookiesHash(), time() + 365 * 3600 * 24);
             // Informing user
             $this->getUser()->setFlash("notice", $this->getContext()->getI18N()->__("Happy to see you %s% !", array("%s%" => $q->getUsername())));
             if ($r->isXmlHttpRequest()) {
                 $this->getResponse()->setStatusCode(202);
                 return $this->renderText("");
             }
         } else {
             $c = (string) $login->getErrorSchema();
             preg_match_all('#(.+) \\[(.+)\\]#U', $c, $m);
             $m[1] = array_map('trim', $m[1]);
             die(json_encode($m, JSON_FORCE_OBJECT));
         }
     }
     // Redirect to homepage
     $this->redirect("@homepage");
 }