Skip to content

Commit 61b7250

Browse files
author
Mikkel Sørensen
committed
Add remaining fixes from change request
1 parent 72ccb3c commit 61b7250

File tree

5 files changed

+118
-185
lines changed

5 files changed

+118
-185
lines changed
Lines changed: 35 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,95 @@
11
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
4-
using System.Net;
5-
using System.Net.NetworkInformation;
6-
using LLlibs.ZeroDepJson;
72
using LootLocker.Extension.Requests;
8-
using LootLocker.Requests;
9-
using UnityEditor.VersionControl;
3+
using LootLocker.Extension.Responses;
104
using UnityEngine;
115

6+
#if UNITY_EDITOR && UNITY_2021_3_OR_NEWER
127
namespace LootLocker.Admin
138
{
149
public partial class LootLockerAdminManager
1510
{
16-
11+
12+
public static void SendAdminRequest(string endPoint, LootLockerHTTPMethod httpMethod, string json, Action<LootLockerResponse> onComplete, bool useAuthToken)
13+
{
14+
LootLockerServerRequest.CallAPI(endPoint, httpMethod, json, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); },
15+
useAuthToken,
16+
callerRole: LootLockerEnums.LootLockerCallerRole.Admin);
17+
}
18+
1719
public static void AdminLogin(string email, string password, Action<LoginResponse> onComplete)
1820
{
1921
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
2022
{
21-
Debug.Log("Input is invalid!");
23+
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Error)("Email or Password is empty.");
2224
return;
2325
}
2426

27+
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionLogin;
28+
2529
AdminLoginRequest request = new AdminLoginRequest();
2630
request.email = email;
2731
request.password = password;
2832

29-
AdminLogin(request, onComplete);
30-
}
31-
32-
public static void AdminLogin(AdminLoginRequest data, Action<LoginResponse> onComplete)
33-
{
34-
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionLogin;
35-
36-
string json = LootLockerJson.SerializeObject(data);
33+
string json = LootLockerJson.SerializeObject(request);
3734

38-
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, json,
39-
onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); }, false,
40-
callerRole: LootLockerEnums.LootLockerCallerRole.Admin);
35+
SendAdminRequest(endPoint.endPoint, endPoint.httpMethod, json,
36+
onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); }, true);
4137
}
4238

43-
4439
public static void MFAAuthenticate(string authCode, string secret, Action<LoginResponse> onComplete)
4540
{
4641
if (string.IsNullOrEmpty(authCode) || string.IsNullOrEmpty(secret))
4742
{
48-
Debug.Log("Input is invalid!");
43+
Debug.Log("No authentication code found!");
4944
return;
5045
}
5146

47+
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionMFA;
48+
5249
MfaAdminLoginRequest data = new MfaAdminLoginRequest();
5350
data.mfa_key = authCode;
5451
data.secret = secret;
5552

56-
MFAAuthenticate(data, onComplete);
57-
}
58-
59-
public static void MFAAuthenticate(MfaAdminLoginRequest data, Action<LoginResponse> onComplete)
60-
{
61-
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionMFA;
62-
6353
string json = LootLockerJson.SerializeObject(data);
64-
65-
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, json,
66-
onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse);},
67-
callerRole: LootLockerEnums.LootLockerCallerRole.Admin);
6854

55+
SendAdminRequest(endPoint.endPoint, endPoint.httpMethod, json,
56+
onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); }, true);
6957
}
7058

71-
7259
public static void GetAllKeys(string game_id, Action<KeysResponse> onComplete)
73-
{
74-
LootLockerGetRequest data = new LootLockerGetRequest();
75-
data.getRequests.Add(game_id);
76-
77-
GetAllKeys(data, onComplete);
78-
}
79-
80-
public static void GetAllKeys(LootLockerGetRequest lootLockerGetRequest, Action<KeysResponse> onComplete)
8160
{
8261
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionGetAllKeys;
62+
string getVariable = string.Format(endPoint.endPoint, game_id);
8363

84-
string getVariable = string.Format(endPoint.endPoint, lootLockerGetRequest.getRequests[0]);
85-
86-
LootLockerServerRequest.CallAPI(getVariable, endPoint.httpMethod, "",
87-
onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse);},
88-
callerRole: LootLockerEnums.LootLockerCallerRole.Admin);
89-
90-
64+
SendAdminRequest(getVariable, endPoint.httpMethod, "",
65+
onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); }, true);
9166
}
9267

93-
public static void GenerateKey(string game_id, string key_name, string key_environment, Action<Key> onComplete)
68+
public static void GenerateKey(string game_id, string key_name, string key_environment, Action<KeyResponse> onComplete)
9469
{
95-
LootLockerGetRequest request = new LootLockerGetRequest();
96-
request.getRequests.Add(game_id);
70+
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionCreateKey;
71+
72+
string getVariable = string.Format(endPoint.endPoint, game_id);
9773

9874
KeyCreationRequest data = new KeyCreationRequest();
9975
data.name = key_name;
10076
data.api_type = key_environment;
10177

102-
103-
GenerateKey(data, request, onComplete);
104-
}
105-
106-
public static void GenerateKey(KeyCreationRequest data, LootLockerGetRequest lootLockerGetRequest, Action<Key> onComplete)
107-
{
108-
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionCreateKey;
109-
110-
string getVariable = string.Format(endPoint.endPoint, lootLockerGetRequest.getRequests[0]);
111-
11278
string json = LootLockerJson.SerializeObject(data);
11379

114-
LootLockerServerRequest.CallAPI(getVariable, endPoint.httpMethod, json,
115-
onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); },
116-
callerRole: LootLockerEnums.LootLockerCallerRole.Admin);
80+
SendAdminRequest(getVariable, endPoint.httpMethod, json,
81+
onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); }, true);
11782
}
11883

119-
120-
//Roles
12184
public static void GetUserRole(string userId, Action<UserRoleResponse> onComplete)
122-
{
123-
LootLockerGetRequest data = new LootLockerGetRequest();
124-
data.getRequests.Add(userId);
125-
126-
GetUserRole(data, onComplete);
127-
}
128-
129-
public static void GetUserRole(LootLockerGetRequest lootLockerGetRequest, Action<UserRoleResponse> onComplete)
13085
{
13186
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionGetUserRole;
13287

133-
string getVariable = string.Format(endPoint.endPoint, lootLockerGetRequest.getRequests[0]);
134-
135-
LootLockerServerRequest.CallAPI(getVariable, endPoint.httpMethod, "",
136-
onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); },
137-
callerRole: LootLockerEnums.LootLockerCallerRole.Admin);
88+
string getVariable = string.Format(endPoint.endPoint, userId);
13889

90+
SendAdminRequest(getVariable, endPoint.httpMethod, "",
91+
onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); }, true);
13992
}
140-
14193
}
142-
143-
}
94+
}
95+
#endif
Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
using LootLocker.Extension.DataTypes;
12
using System.Collections.Generic;
23

34
namespace LootLocker.Extension.Requests
45
{
5-
//Login
6-
7-
86
public class MfaAdminLoginRequest
97
{
108
public string mfa_key { get; set; }
@@ -17,9 +15,15 @@ public class AdminLoginRequest
1715
public string password { get; set; }
1816
}
1917

18+
public class KeyCreationRequest
19+
{
20+
public string name { get; set; }
21+
public string api_type { get; set; }
22+
}
23+
}
2024

21-
//Games
22-
[System.Serializable]
25+
namespace LootLocker.Extension.DataTypes
26+
{
2327
public class Game
2428
{
2529
public int id { get; set; }
@@ -30,8 +34,6 @@ public class Game
3034
public Game development { get; set; }
3135
}
3236

33-
//Organization
34-
[System.Serializable]
3537
public class Organisation
3638
{
3739
public int id { get; set; }
@@ -51,15 +53,13 @@ public Game GetGameByID(int id)
5153
}
5254
}
5355

54-
//User
55-
[System.Serializable]
5656
public class User
5757
{
5858
public int id { get; set; }
5959
public string name { get; set; }
6060
public string email { get; set; }
6161
public long signed_up { get; set; }
62-
public Organisation[] organisations { get; set; }
62+
public Organisation[] organisations { get; set; }
6363
private Dictionary<int, int> organisationIndexByID { get; set; }
6464

6565
public Organisation GetOrganisationByID(int id)
@@ -74,7 +74,10 @@ public Organisation GetOrganisationByID(int id)
7474
return null;
7575
}
7676
}
77+
}
7778

79+
namespace LootLocker.Extension.Responses
80+
{
7881
public class LoginResponse : LootLockerResponse
7982
{
8083

@@ -83,20 +86,17 @@ public class LoginResponse : LootLockerResponse
8386
public User user { get; set; }
8487
}
8588

86-
//Roles
87-
public class Permissions
88-
{
89-
public string permission { get; set; }
90-
}
9189
public class UserRoleResponse : LootLockerResponse
9290
{
9391
public string[] permissions { get; set; }
9492
public bool self { get; set; }
9593
}
9694

97-
//API Keys
98-
99-
public class Key : LootLockerResponse
95+
public class KeysResponse : LootLockerResponse
96+
{
97+
public KeyResponse[] api_keys { get; set; }
98+
}
99+
public class KeyResponse : LootLockerResponse
100100
{
101101
public int id { get; set; }
102102
public int game_id { get; set; }
@@ -105,18 +105,5 @@ public class Key : LootLockerResponse
105105
public string name { get; set; }
106106
public string created_at { get; set; }
107107
public string updated_at { get; set; }
108-
109108
}
110-
111-
public class KeysResponse : LootLockerResponse
112-
{
113-
public Key[] api_keys { get; set; }
114-
}
115-
116-
public class KeyCreationRequest
117-
{
118-
public string name { get; set; }
119-
public string api_type { get; set; }
120-
}
121-
122109
}

Runtime/Editor/StoredUser.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using System.IO;
44
using UnityEditor;
55
using UnityEngine;
6-
#if (UNITY_EDITOR)
6+
7+
#if UNITY_EDITOR && UNITY_2021_3_OR_NEWER
8+
using LootLocker.Extension.DataTypes;
79
public class StoredUser : ScriptableObject
810
{
911
[HideInInspector]

0 commit comments

Comments
 (0)