Пример #1
0
 private function forceMigratePlayer($v1PlayerId)
 {
     $v1Player = migration_dbconnection::queryObject("SELECT * FROM players WHERE player_id = '{$v1PlayerId}'", "v1");
     if (!$v1Player) {
         return 0;
     }
     $mig = migration_dbconnection::queryObject("SELECT * FROM user_migrations WHERE v1_player_id = '{$v1PlayerId}'");
     if ($mig) {
         return $mig->v2_user_id;
     }
     $v2User = migration_dbconnection::queryObject("SELECT * FROM users WHERE user_name = '{$v1Player->user_name}'", "v2");
     if (!$v2User) {
         $userpack = new stdClass();
         $userpack->user_name = $v1Player->user_name . "_legacy_siftr";
         $userpack->password = "******";
         $userpack->display_name = !$v1Player->display_name || $v1Player->display_name == "" ? $v1Player->user_name : $v1Player->display_name;
         $userpack->email = $v1Player->email;
         $userpack->permission = "read_write";
         $userpack->no_auto_migrate = true;
         //negative var name because it's a hack and we want the default to be nonexistant
         $v2User = bridgeService("v2", "users", "createUser", "", $userpack)->data;
         if (!$v2User) {
             return 0;
         }
         //username taken I guess
         migration_dbconnection::query("INSERT INTO user_migrations (v2_user_id, v2_read_write_key, v1_player_id, v1_editor_id, v1_read_write_token) VALUES ('{$v2User->user_id}', '{$v2User->read_write_key}', '{$v1Player->player_id}', '0', '0')");
     }
     return $v2User->user_id;
 }
Пример #2
0
 public static function logIn($pack)
 {
     if ($pack->auth && $pack->auth->user_id) {
         $pack->auth->permission = "read_write";
         if (!users::authenticateUser($pack->auth)) {
             return new return_package(6, NULL, "Failed Authentication");
         }
         $user = dbconnection::queryObject("SELECT * FROM users WHERE user_id = '{$pack->auth->user_id}'");
     } else {
         if (!($user = dbconnection::queryObject("SELECT * FROM users WHERE user_name = '{$pack->user_name}'")) || hash("sha256", $user->salt . $pack->password) != $user->hash) {
             /*
              *  BEGIN MIGRATION INJECTION
              */
             //Login Failed. If username/password doesn't exist, check if we can re-route this to a migrate.
             if (!$user && !$pack->no_auto_migrate) {
                 //miguser api for reference
                 //public static function migrateUser($playerName, $playerPass, $editorName, $editorPass, $newName, $newPass, $newDisplay, $newEmail)
                 //first try to migrate full editor & player
                 $migArgs = $pack->user_name . "/" . $pack->password . "/" . $pack->user_name . "/" . $pack->password . "/" . $pack->user_name . "/" . $pack->password . "/0/0";
                 $mig = bridgeService("migration", "migration", "migrateUser", $migArgs, false);
                 if ($mig->returnCode !== 0) {
                     //if that doesn't work, just try editor
                     $migArgs = "0/0/" . $pack->user_name . "/" . $pack->password . "/" . $pack->user_name . "/" . $pack->password . "/0/0";
                     $mig = bridgeService("migration", "migration", "migrateUser", $migArgs, false);
                 }
                 //if THAT doesn't work, bad login
                 if ($mig->returnCode !== 0) {
                     return new return_package(1, NULL, "Incorrect username/password");
                 } else {
                     //pretend the user was correctly recieved
                     $user = dbconnection::queryObject("SELECT * FROM users WHERE user_name = '{$pack->user_name}'");
                 }
             } else {
                 //there already exists a user but they have an invalid password (so drop out of migration injection flow)
                 /*
                  *  END MIGRATION INJECTION
                  */
                 return new return_package(1, NULL, "Incorrect username/password");
             }
         }
     }
     $ret = new stdClass();
     $ret->user_id = $user->user_id;
     $ret->user_name = $user->user_name;
     $ret->display_name = $user->display_name;
     $ret->media_id = $user->media_id;
     if ($pack->permission == "read" || $pack->auth->permission == "read") {
         $ret->read_key = $user->read_key;
     }
     if ($pack->permission == "write" || $pack->auth->permission == "write") {
         $ret->write_key = $user->write_key;
     }
     if ($pack->permission == "read_write" || $pack->auth->permission == "read_write") {
         $ret->read_write_key = $user->read_write_key;
     }
     dbconnection::queryInsert("INSERT INTO user_log (user_id, event_type, created) VALUES ('{$ret->user_id}', 'LOG_IN', CURRENT_TIMESTAMP);");
     return new return_package(0, $ret);
 }