Пример #1
0
 public function executeDologin(sfWebRequest $request)
 {
     $form = new LoginForm();
     $form->bind($this->getRequestParameter('credentials'));
     if ($form->isValid()) {
         $credentials = $request->getParameter('credentials');
         $login = $credentials['login'];
         $user = UserTable::getUserFromLogin($login);
         ## Store array of allowed sectionIds that can be accessed!
         $sectionIdsArray = Doctrine_Core::getTable('Program')->getProgramsByDepartmentId($user->getDepartmentId());
         // set the session correctly
         $this->getUser()->setAuthenticated(true);
         $this->getUser()->setAttribute('userId', $user->getId());
         $this->getUser()->setAttribute('departmentId', $user->getDepartmentId());
         $this->getUser()->setAttribute('departmentName', $user->getDepartment());
         $this->getUser()->setAttribute('sectionIds', array_keys($sectionIdsArray));
         $this->getUser()->setAttribute('credential', $user->getPrivilege());
         ##Do Logging!!
         $newLog = new AuditLog();
         $action = 'User has logged into Student Record Management System';
         $newLog->addNewLogInfo($this->getUser()->getAttribute('userId'), $action);
         $this->getUser()->setFlash('notice', 'Welcome' . ' ' . $user->getFirstName());
         //$this->redirect('filter/show?id='.$user->getId());
         $this->redirect('programsection/index');
     } else {
         // give the form again
         $this->form = $form;
         $this->setTemplate('login');
     }
 }
 public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
 {
     parent::initialize($dispatcher, $storage, $options);
     $env = sfContext::getInstance()->getConfiguration()->getEnvironment();
     if ($env != 'test') {
         $this->checkPermissions();
         $this->resetPasswordCheck();
         // here?
         $this->checkDatabase();
         $this->checkHtaccess();
         $this->performTests();
     }
     $request = sfContext::getInstance()->getRequest();
     if (!$this->isAuthenticated()) {
         if ($request->getPostParameter('password') == '' && $request->getCookie($this->cookie_name) != '' && $request->getMethod() != sfRequest::POST) {
             $params = array();
             $params['password'] = $request->getCookie($this->cookie_name);
             $form = new LoginForm($this, true, array(), array(), false);
             // no csrf
             $form->bind($params);
             if ($form->isValid()) {
                 $this->setAuthenticated(true);
             }
         }
     }
 }
Пример #3
0
 /**
  *
  * @param sfWebRequest $request
  * @param LoginForm $form
  */
 protected function processLogin(sfWebRequest $request, LoginForm $form)
 {
     $form->bind($request->getParameter('signin'));
     if ($form->isValid()) {
         $values = $form->getValues();
         $this->getUser()->signIn($values['user'], array_key_exists('remember', $values) ? $values['remember'] : false);
         // Set the tow previous referer to the same value for:
         // 1) redirect to previous user's location
         // 2) avoid redirect loop in signin
         $this->getUser()->setReferer($this->getUser()->getReferer());
         // Redirect to referer
         return $this->redirect($this->getUser()->getReferer());
     }
 }
Пример #4
0
 public function executeDologin(sfWebRequest $request)
 {
     $form = new LoginForm();
     $form->bind($this->getRequestParameter('credentials'));
     if ($form->isValid()) {
         $login = $request->getParameter('credentials[login]');
         $user = UserPeer::getUserFromLogin($login);
         // set the session correctly
         $this->getUser()->setAuthenticated(true);
         $this->getUser()->setAttribute('user_id', $user->getId());
         $this->getUser()->setFlash('notice', 'Welcome' . ' ' . $user->getLogin());
         $this->redirect('user/show?id=' . $user->getId());
     } else {
         // give the form again
         $this->form = $form;
         $this->setTemplate('login');
     }
 }
Пример #5
0
 public function httpPostMethod(Http $http, array $formFields)
 {
     if (filter_var($formFields['Login'], FILTER_VALIDATE_EMAIL) != false) {
         try {
             $userSession = new UserSession();
             $CustomerModel = new CustomerModel();
             $user_id = $CustomerModel->findWithCredentials($formFields['Login'], $formFields['Password'], $_SERVER['REMOTE_ADDR']);
             if (ctype_digit($user_id)) {
                 $user = $CustomerModel->findCustomer($user_id);
                 $userSession->create($user);
                 $http->redirectTo('/');
             }
         } catch (DomainException $event) {
             //var_dump($event);
             $form = new LoginForm();
             $form->bind($formFields);
             $form->setErrorMessage($event->getMessage());
             return ['_form' => $form];
             //AVEC CONTROLEUR EXECPTION --- $http->redirectTo('Exception?'.$user_id);
         }
     } else {
         $http->redirectTo('Exception?Error=4');
     }
 }
Пример #6
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');
 }
Пример #7
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");
 }