src/snac/server/ServerExecutor.php
/**
     * Authenticate User
     *
     * Authenticates the user by checking the user store (dbuser)
     *
     * @param \snac\data\User $user User information to check
     * @return boolean true if user authenticated, false if not
     */
Authenticate User
Authenticates the user by checking the user store (dbuser)

@param \snac\data\User $user User information to check
@return boolean true if user authenticated, false if not
Authenticate User Authenticates the user by checking the user store ( dbuser ) @param \ snac \ data \ User $user User information to check @return boolean true if user authenticated false if not
public function authenticateUser($user) {
        $this->logger->addDebug("Starting Authentication function");
        if ($user != null) {
            $this->logger->addDebug("Attempting to authenticate user", $user->toArray());
            $this->user = false;
            if ($user->getUserName() != null) {
                $this->user = $this->uStore->readUser($user);
                $this->logger->addDebug("Read user", array($this->user));
                if ($this->user === false) {
                    throw new \snac\exceptions\SNACUserException("Invalid OAuth user", 403);
                }
            } else {
                throw new \snac\exceptions\SNACUserException("Username required for login", 400);
            }
            $this->logger->addDebug("The user was found in the database", $this->user->toArray());
            $this->user->setToken($user->getToken());
            $this->user->setAvatar($user->getAvatar());
            $this->user->setAvatarSmall($user->getAvatarSmall());
            $this->user->setAvatarLarge($user->getAvatarLarge());
            if ($this->user->getFirstName() == null)
                $this->user->setFirstName($user->getFirstName());
            if ($this->user->getLastName() == null)
                $this->user->setLastName($user->getLastName());
            if ($this->user->getFullName() == null)
                $this->user->setFullName($user->getFullName());
            if ($this->user->getEmail() == null)
                $this->user->setEmail($user->getEmail());
            $this->uStore->saveUser($this->user);
            $this->logger->addDebug("Updated the user with their token", $this->user->toArray());
            if ($this->user !== false && $this->uStore->sessionExists($this->user)) {
                if ($this->uStore->sessionActive($this->user)) {
                    $this->logger->addDebug("User is valid from SNAC details");
                    return true;
                } else {
                    $this->logger->addDebug("User is valid from SNAC details");
                    return $this->uStore->sessionExtend($this->user);
                }
            } else if ($this->user !== false && $this->user->getToken() != null) {
                $this->uStore->clearAllSessions($this->user);
                if (isset($this->user->getToken()["authority"]) &&
                    $this->user->getToken()["authority"] == "snac") {
                    return true;
                } else if ($this->checkOAuth($this->user) &&
                    $this->uStore->addSession($this->user)) {
                    return true;
                } else {
                    throw new \snac\exceptions\SNACUserException("User did not have a valid session to capture", 400);
                }
            } else {
                throw new \snac\exceptions\SNACUserException("User did not have session", 400);
            }
            $this->logger->addDebug("Something went wrong checking user in SNAC");
            return false;
        }
        $this->logger->addDebug("User object was null: no permissions but okay auth");
        return true;
    }
public function authenticateUser ( $ user ) { $ this -> logger -> addDebug ( " Starting Authentication function " ) ; if ( $ user != null ) { $ this -> logger -> addDebug ( " Attempting to authenticate user " , $ user -> toArray ( ) ) ; $ this -> user = false ; if ( $ user -> getUserName ( ) != null ) { $ this -> user = $ this -> uStore -> readUser ( $ user ) ; $ this -> logger -> addDebug ( " Read user " , array ( $ this -> user ) ) ; if ( $ this -> user === false ) { throw new \ snac \ exceptions \ SNACUserException ( " Invalid OAuth user " , 403 ) ; } } else { throw new \ snac \ exceptions \ SNACUserException ( " Username required for login " , 400 ) ; } $ this -> logger -> addDebug ( " The user was found in the database " , $ this -> user -> toArray ( ) ) ; $ this -> user -> setToken ( $ user -> getToken ( ) ) ; $ this -> user -> setAvatar ( $ user -> getAvatar ( ) ) ; $ this -> user -> setAvatarSmall ( $ user -> getAvatarSmall ( ) ) ; $ this -> user -> setAvatarLarge ( $ user -> getAvatarLarge ( ) ) ; if ( $ this -> user -> getFirstName ( ) == null ) $ this -> user -> setFirstName ( $ user -> getFirstName ( ) ) ; if ( $ this -> user -> getLastName ( ) == null ) $ this -> user -> setLastName ( $ user -> getLastName ( ) ) ; if ( $ this -> user -> getFullName ( ) == null ) $ this -> user -> setFullName ( $ user -> getFullName ( ) ) ; if ( $ this -> user -> getEmail ( ) == null ) $ this -> user -> setEmail ( $ user -> getEmail ( ) ) ; $ this -> uStore -> saveUser ( $ this -> user ) ; $ this -> logger -> addDebug ( " Updated the user with their token " , $ this -> user -> toArray ( ) ) ; if ( $ this -> user !== false && $ this -> uStore -> sessionExists ( $ this -> user ) ) { if ( $ this -> uStore -> sessionActive ( $ this -> user ) ) { $ this -> logger -> addDebug ( " User is valid from SNAC details " ) ; return true ; } else { $ this -> logger -> addDebug ( " User is valid from SNAC details " ) ; return $ this -> uStore -> sessionExtend ( $ this -> user ) ; } } else if ( $ this -> user !== false && $ this -> user -> getToken ( ) != null ) { $ this -> uStore -> clearAllSessions ( $ this -> user ) ; if ( isset ( $ this -> user -> getToken ( ) [ " authority " ] ) && $ this -> user -> getToken ( ) [ " authority " ] == " snac " ) { return true ; } else if ( $ this -> checkOAuth ( $ this -> user ) && $ this -> uStore -> addSession ( $ this -> user ) ) { return true ; } else { throw new \ snac \ exceptions \ SNACUserException ( " User did not have a valid session to capture " , 400 ) ; } } else { throw new \ snac \ exceptions \ SNACUserException ( " User did not have session " , 400 ) ; } $ this -> logger -> addDebug ( " Something went wrong checking user in SNAC " ) ; return false ; } $ this -> logger -> addDebug ( " User object was null: no permissions but okay auth " ) ; return true ; }
Authenticate User
 Authenticates the user by checking the user store (dbuser)
Authenticate User Authenticates the user by checking the user store ( dbuser )
// If the user exists in our database and we know about this token, // then we'll let them continue. Else, we will try to authenticate // with Google, check their information, and add them to the database. // Check that the user has a session in the database //$this->user = $this->uStore->checkSessionActive($user); // For purposes of authentication, the UserName is required // The user wasn't found in the database // Use the values passed in from the client to update the user object, // if applicable // The session is still active // The session has expired, so we will be nice and extend // Remove all old sessions for this user // Try to add the session (check google first) // This was a fake but legit token from SNAC // Google approved the session and we successfully added it // If the user is null, then we're okay on authentication (no permissions)