Esempio n. 1
0
 /**
  * Logs in the given user. If the login was successful, a session is automatically started.
  *
  * @return array The data
  * @throws InvalidLoginDataException
  *
  * @ServiceCall(description="Authenticates a user against the system",
  * 				documentation="Authenticates a user and starts a new session upon success.",
  * 				returnValues={
  * 					@ServiceReturnValue(
  * 											name="username",
  * 											type="string:50",
  * 											description="The logged in username"
  * 										),
  * 					@ServiceReturnValue(
  * 											name="sessionid",
  * 											type="string:50",
  * 											description="The session ID"
  * 										),
  * 					@ServiceReturnValue(
  * 											name="admin",
  * 											type="boolean",
  *	 										description="True if the logged in user has admin rights"
  * 										),
  * 					@ServiceReturnValue(
  * 											name="userPreferences",
  * 											type="UserPreference[]",
  * 											description="An array of UserPreferences"
  * 										)
  * 					},
  * 				parameters={
  * 					@ServiceParameter(	name="username",
  * 										type="string:50",
  * 										required=true,
  * 										description="The username to authenticate"
  * 										),
  * 					@ServiceParameter(	name="password",
  * 										type="string:32",
  * 										required=true,
  * 										description="The password, hashed in MD5"
  * 										)
  * 				})
  *
  */
 public function login()
 {
     $this->requireParameter("username");
     $this->requireParameter("password");
     /* Build a temporary user */
     $user = new User();
     $user->setRawUsername($this->getParameter("username"));
     $user->setHashedPassword($this->getParameter("password"));
     $authenticatedUser = UserManager::getInstance()->authenticate($user);
     if ($authenticatedUser !== false) {
         /* Start Session */
         $session = SessionManager::getInstance()->startSession($authenticatedUser);
         $session->getUser()->updateSeen();
         $aPreferences = array();
         foreach ($session->getUser()->getPreferences() as $result) {
             $aPreferences[] = $result->serialize();
         }
         return array("sessionid" => $session->getSessionID(), "username" => $this->getParameter("username"), "admin" => $session->getUser()->isAdmin(), "userPreferences" => array("response" => array("data" => $aPreferences)));
     } else {
         throw new InvalidLoginDataException();
     }
 }
Esempio n. 2
0
 private function authenticateByUsername($username, $password)
 {
     /* Build a temporary user */
     $user = new User();
     $user->setRawUsername($username);
     $user->setHashedPassword($password);
     $authenticatedUser = UserManager::getInstance()->authenticate($user);
     if ($authenticatedUser !== false) {
         /* Start Session */
         $session = SessionManager::getInstance()->startSession($authenticatedUser);
         return $session->getSessionID();
     } else {
         throw new InvalidLoginDataException();
     }
 }