Example #1
0
        //Get all maps from admins/ and users/
        public static void GetAllMapsForAdmin(MapListOperationSuccess callback, OperationFail fallback = null)
        {
            List <MapConfig> maps = new List <MapConfig>();

            GetAllAdminMaps((adminMaps) => {
                maps.AddRange(adminMaps);
                GetAllUsersMaps((userMaps) => {
                    maps.AddRange(userMaps);
                    callback(maps);
                }, fallback);
            }, fallback);
        }
Example #2
0
 //Get a map from admins with a selected id
 public static void GetAdminMap(string id, MapOperationSuccess callback, OperationFail fallback = null)
 {
     RestClient.Get($"{Config.DATABASE_URL}{Config.ADMINS_FOLDER}{Config.MAPS_FOLDER}{id}/.json?auth={Config.ID_TOKEN}").Then(response => {
         MapConfig returnedMap = JsonConvert.DeserializeObject <MapConfig>(response.Text);
         callback(returnedMap);
     }).Catch(err =>
     {
         var error = err as RequestException;
         Debug.Log(error.Response);
         fallback();
     });
 }
Example #3
0
 //Get all maps from admins/
 public static void GetAllAdminMaps(MapListOperationSuccess callback, OperationFail fallback = null)
 {
     RestClient.Get($"{Config.DATABASE_URL}{Config.ADMINS_FOLDER}{Config.MAPS_FOLDER}.json?auth={Config.ID_TOKEN}").Then(response => {
         var maps         = new List <MapConfig>();
         var returnedJson = JsonConvert.DeserializeObject <Dictionary <string, MapConfig> >(response.Text);
         callback(new List <MapConfig>(returnedJson.Values));
     }).Catch(err =>
     {
         var error = err as RequestException;
         Debug.Log(error.Response);
         fallback();
     });
 }
Example #4
0
 //Get all map ids from admins/
 public static void GetAllAdminMapIds(StringListOperationSuccess callback, OperationFail fallback = null)
 {
     RestClient.Get($"{Config.DATABASE_URL}{Config.ADMINS_FOLDER}{Config.MAPS_FOLDER}.json?auth={Config.ID_TOKEN}").Then(response => {
         var strings      = new List <String>();
         var returnedJson = JsonConvert.DeserializeObject <Dictionary <string, MapConfig> >(response.Text);
         foreach (KeyValuePair <string, MapConfig> kvp in returnedJson)
         {
             strings.Add(kvp.Key);
         }
         callback(strings);
     }).Catch(err =>
     {
         var error = err as RequestException;
         Debug.Log(error.Response);
         fallback();
     });
 }
Example #5
0
 //Get all maps of all users from users/
 public static void GetAllUsersMaps(MapListOperationSuccess callback, OperationFail fallback = null)
 {
     RestClient.Get($"{Config.DATABASE_URL}{Config.USERS_FOLDER}.json?auth={Config.ID_TOKEN}").Then(response => {
         var returnedJson = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, Dictionary <string, MapConfig> > > >(response.Text);
         var maps         = new List <MapConfig>();
         foreach (Dictionary <string, Dictionary <string, MapConfig> > dict1 in returnedJson.Values)
         {
             foreach (Dictionary <string, MapConfig> dict2 in dict1.Values)
             {
                 foreach (MapConfig map in dict2.Values)
                 {
                     maps.Add(map);
                 }
             }
         }
         callback(maps);
     }).Catch(err =>
     {
         var error = err as RequestException;
         Debug.Log(error.Response);
         fallback();
     });
 }
Example #6
0
 public static void CreateUserMap(MapConfig map, StringOperationSuccess callback = null, OperationFail fallback = null)
 {
     RestClient.Post($"{Config.DATABASE_URL}{Config.USERS_FOLDER}{Config.USER_ID}/{Config.MAPS_FOLDER}.json?auth={Config.ID_TOKEN}", map).Then(response =>
     {
         var returnedJson = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Text);
         callback(returnedJson["name"]);
     }).Catch(err =>
     {
         var error = err as RequestException;
         Debug.Log(error.Response);
         fallback();
     });
 }
Example #7
0
        private static void CheckEmailVerification(string idToken, OperationSuccess callback, OperationFail fallback)
        {
            var payLoad = $"{{\"idToken\":\"{idToken}\"}}";

            RestClient.Post($"https://identitytoolkit.googleapis.com/v1/accounts:lookup?key={Config.API_KEY}",
                            payLoad).Then(
                response =>
            {
                var userInfos = JsonConvert.DeserializeObject <UsersInfo>(response.Text);
                Debug.Log(response.Text);
                if (userInfos.users[0].emailVerified)
                {
                    callback();
                }
                else
                {
                    fallback();
                }
            });
        }
Example #8
0
        public static void Login(string email, string password, OperationSuccess callback, OperationFail fallback = null)
        {
            var payload = $"{{\"email\":\"{email}\",\"password\":\"{password}\",\"returnSecureToken\":true}}";

            RestClient.Post($"https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key={Config.API_KEY}", payload).Then(
                response =>
            {
                var returnedJson = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Text);

                Debug.Log("Got the id token for user " + email);
                CheckEmailVerification(returnedJson["idToken"], () =>
                {
                    Debug.Log("Login successful");
                    Config.ID_TOKEN = returnedJson["idToken"];
                    Config.USER_ID  = returnedJson["localId"];
                    callback();
                }, () => { Debug.Log("Email not verified"); });
            }).Catch(err =>
            {
                var error = err as RequestException;
                Debug.Log(error.Response);
                fallback();
            });
        }