Example #1
0
 public function Fire()
 {
     if ($this->input->do == 'fire') {
         $user = new User();
         $user->set_condition('email = :email');
         $user->email = $this->input->email;
         try {
             $user = $user->Fetch();
         } catch (phalanx\data\ModelException $e) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('LOGIN_FAILED')));
             return;
         }
         if ($user->password != md5(sha1($this->input->password) . $user->salt)) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('LOGIN_FAILED')));
             return;
         }
         // We need to set _COOKIE values so that if the last_event requires
         // authentication, we can return the correct state.
         $expires = time() + 60 * 60 * 5;
         $this->_SetCookie('bugdar_user', $user->user_id, $expires);
         $this->_SetCookie('bugdar_pass', $user->authkey, $expires);
         $last_event = NULL;
         if ($this->input->last_event) {
             $last_event = unserialize(base64_decode($this->input->last_event));
             $class = $last_event[0];
             $input = $last_event[1];
             if (!class_exists($class)) {
                 $path = phalanx\base\CamelCaseToUnderscore($class);
                 $path = preg_replace('/_event$/', '', $path);
                 require_once BUGDAR_ROOT . "/events/{$path}.php";
             }
             $last_event = new $class($input);
         }
         $this->successful = TRUE;
         EventPump::Pump()->PostEvent($last_event ?: new StandardSuccessEvent('home', l10n::S('LOGIN_SUCCESSFUL')));
         return;
     }
     // Find the first non-UserLoginEvent that was processed. If the event
     // hasn't been finished, then this event preempted it and we should
     // store its data so that the user can return to what she was doing.
     $events = EventPump::Pump()->GetAllEvents();
     foreach ($events as $event) {
         if (!$event instanceof $this && $event->state() != EventPump::EVENT_FINISHED) {
             $this->last_event = base64_encode(serialize(array(get_class($event), $event->input)));
             break;
         }
     }
 }
Example #2
0
 protected function _ValidateUser($value)
 {
     // Handle the default value.
     if ($this->required && empty($value) && !$this->default_value) {
         return array(FALSE, $value);
     } else {
         if ($this->default_value) {
             return array(TRUE, $this->default_value);
         }
     }
     // Look the user up by alias to get the user ID.
     $user = new User();
     $user->alias = $value;
     $user->set_condition('alias = :alias');
     try {
         $user->FetchInto();
         return array(TRUE, $user->user_id);
     } catch (\phalanx\data\ModelException $e) {
         return array(FALSE, $value);
     }
 }