public static function addUser($username, $password, $email)
 {
     $insertSuccessful = self::insertUserIntoDB($username, $password, $email);
     if ($insertSuccessful) {
         $user = UserRepository::retrieveUserByUsername($username);
         return $user;
     } else {
         return null;
     }
 }
 /**
 	Sets the current user if the credentials are correct.
 	returns true if successful; an array of problems if the inputs are invalid
 */
 public function login($username, $password)
 {
     $result = $this->loginInputIsValid($username, $password);
     if ($result !== true) {
         return $result;
     } else {
         $user = UserRepository::retrieveUserByUsername($username);
         if ($user === null) {
             $problem = array('badUsername' => true);
             return $problem;
         } else {
             if ($user->passwordMatches($password)) {
                 print "logged in";
                 $this->currentUser = $user;
                 return true;
             } else {
                 $problem = array('badPassword' => true);
                 return $problem;
             }
         }
     }
 }
Exemple #3
0
 private static function usernameIsAvailable($username)
 {
     $result = UserRepository::retrieveUserByUsername($username);
     $usernameIsAvailable = $result === null;
     return $usernameIsAvailable;
 }