Example #1
0
 public static function FromDatabase($row, Colony $c = NULL)
 {
     $user = new User();
     $user->ID($row['ID']);
     $user->Username($row['username']);
     $user->AuthorisationLevel(Database::Instance()->ExecuteQuery("SELECT * FROM authorisation WHERE ID = " . (int) $row['authorisationID'] . ";", "SELECT"));
     $user->PrimaryEmail($row['primary_email']);
     $user->SecondaryEmail($row['secondary_email']);
     $user->RegistrationTime($row['registration_time']);
     $user->LastOnline($row['last_online']);
     $user->IsBanned($row['is_banned']);
     $user->BannedUntil($row['banned_until']);
     // Load authorisation level name
     $levelNameRow = Database::Instance()->ExecuteQuery("SELECT name FROM authorisation WHERE level = " . $user->AuthorisationLevel() . ";", "SELECT");
     $user->AuthorisationLevelName($levelNameRow['name']);
     // Load home colony
     if ($c == NULL) {
         $colonyDatabaseRow = Database::Instance()->ExecuteQuery("SELECT * FROM colony WHERE userID = " . $user->ID() . " AND is_home_colony = 1", "SELECT");
         $user->CurrentColony(Colony::FromDatabase($colonyDatabaseRow, $user));
     } else {
         $user->CurrentColony($c);
     }
     // Load user's technologies
     $technologyDatabaseRow = Database::Instance()->ExecuteQuery("SELECT * FROM user_technology WHERE userID = " . $user->ID(), "SELECT");
     $user->Technologies(TechnologyGroup::FromDatabase($technologyDatabaseRow, $user));
     // Load user's officers
     $officerDatabaseRow = Database::Instance()->ExecuteQuery("SELECT * FROM user_officers WHERE userID = " . $user->ID(), "SELECT");
     $user->Officers(OfficerGroup::FromDatabase($officerDatabaseRow, $user));
     // Return user
     return $user;
 }
Example #2
0
 public static function Login(UserCredentials $credentials)
 {
     //Credentials check
     $res = 0;
     if ($credentials->Email && $credentials->Password) {
         $res = 3;
         $user = new User($credentials->Email);
         if ($user->mExists) {
             $res = 2;
             if ($user->CheckPassword($credentials->Password)) {
                 $res = 4;
                 //check if user is banned
                 if (!$user->IsBanned()) {
                     //Login :)
                     $user->IsOnline = true;
                     $user->LastLogin = date('Y-m-d H:i:s');
                     $user->Save();
                     $res = 1;
                 }
             }
         }
     }
     return array('res' => $res, 'userid' => $user->Id);
 }