Skip to content

Commit 72ccb3c

Browse files
author
Mikkel Sørensen
committed
Add admin endpoints and small fixes.
1 parent 78d4949 commit 72ccb3c

File tree

7 files changed

+45
-40
lines changed

7 files changed

+45
-40
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,5 @@ public class LootLockerEndPoints
245245
public static EndPointClass reportsCreatePlayer = new EndPointClass("reports/player", LootLockerHTTPMethod.POST);
246246
public static EndPointClass reportsCreateAsset = new EndPointClass("reports/asset", LootLockerHTTPMethod.POST);
247247

248-
//SDK Admin Extension
249-
[Header("Admin Extension")]
250-
public static EndPointClass adminExtensionLogin = new EndPointClass("v1/session", LootLockerHTTPMethod.POST);
251-
public static EndPointClass adminExtensionMFA = new EndPointClass("v1/2fa", LootLockerHTTPMethod.POST);
252-
public static EndPointClass adminExtensionGetAllKeys = new EndPointClass("game/{0}/api_keys", LootLockerHTTPMethod.GET);
253-
public static EndPointClass adminExtensionCreateKey = new EndPointClass("game/{0}/api_keys", LootLockerHTTPMethod.POST);
254-
public static EndPointClass adminExtensionGetUserRole = new EndPointClass("roles/{0}", LootLockerHTTPMethod.GET);
255-
256248
}
257249
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using UnityEngine;
2+
3+
#if UNITY_EDITOR
4+
namespace LootLocker
5+
{
6+
public class LootLockerAdminEndPoints
7+
{
8+
[Header("API Keys")]
9+
public static EndPointClass adminExtensionGetAllKeys = new EndPointClass("game/{0}/api_keys", LootLockerHTTPMethod.GET);
10+
public static EndPointClass adminExtensionCreateKey = new EndPointClass("game/{0}/api_keys", LootLockerHTTPMethod.POST);
11+
12+
[Header("Admin Authentication")]
13+
public static EndPointClass adminExtensionLogin = new EndPointClass("v1/session", LootLockerHTTPMethod.POST);
14+
public static EndPointClass adminExtensionMFA = new EndPointClass("v1/2fa", LootLockerHTTPMethod.POST);
15+
16+
[Header("User Roles")]
17+
public static EndPointClass adminExtensionGetUserRole = new EndPointClass("roles/{0}", LootLockerHTTPMethod.GET);
18+
}
19+
}
20+
#endif

Runtime/Editor/LootLockerExtensionCalls.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void AdminLogin(string email, string password, Action<LoginRespons
3131

3232
public static void AdminLogin(AdminLoginRequest data, Action<LoginResponse> onComplete)
3333
{
34-
EndPointClass endPoint = LootLockerEndPoints.adminExtensionLogin;
34+
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionLogin;
3535

3636
string json = LootLockerJson.SerializeObject(data);
3737

@@ -58,7 +58,7 @@ public static void MFAAuthenticate(string authCode, string secret, Action<LoginR
5858

5959
public static void MFAAuthenticate(MfaAdminLoginRequest data, Action<LoginResponse> onComplete)
6060
{
61-
EndPointClass endPoint = LootLockerEndPoints.adminExtensionMFA;
61+
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionMFA;
6262

6363
string json = LootLockerJson.SerializeObject(data);
6464

@@ -79,7 +79,7 @@ public static void GetAllKeys(string game_id, Action<KeysResponse> onComplete)
7979

8080
public static void GetAllKeys(LootLockerGetRequest lootLockerGetRequest, Action<KeysResponse> onComplete)
8181
{
82-
EndPointClass endPoint = LootLockerEndPoints.adminExtensionGetAllKeys;
82+
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionGetAllKeys;
8383

8484
string getVariable = string.Format(endPoint.endPoint, lootLockerGetRequest.getRequests[0]);
8585

@@ -105,7 +105,7 @@ public static void GenerateKey(string game_id, string key_name, string key_envir
105105

106106
public static void GenerateKey(KeyCreationRequest data, LootLockerGetRequest lootLockerGetRequest, Action<Key> onComplete)
107107
{
108-
EndPointClass endPoint = LootLockerEndPoints.adminExtensionCreateKey;
108+
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionCreateKey;
109109

110110
string getVariable = string.Format(endPoint.endPoint, lootLockerGetRequest.getRequests[0]);
111111

@@ -128,7 +128,7 @@ public static void GetUserRole(string userId, Action<UserRoleResponse> onComplet
128128

129129
public static void GetUserRole(LootLockerGetRequest lootLockerGetRequest, Action<UserRoleResponse> onComplete)
130130
{
131-
EndPointClass endPoint = LootLockerEndPoints.adminExtensionGetUserRole;
131+
EndPointClass endPoint = LootLockerAdminEndPoints.adminExtensionGetUserRole;
132132

133133
string getVariable = string.Format(endPoint.endPoint, lootLockerGetRequest.getRequests[0]);
134134

Runtime/Editor/StoredUser.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
using System.IO;
44
using UnityEditor;
55
using UnityEngine;
6-
#if (UNITY_EDITOR)
6+
#if (UNITY_EDITOR)
77
public class StoredUser : ScriptableObject
88
{
9-
10-
119
[HideInInspector]
1210
public User user = null;
1311

@@ -40,8 +38,6 @@ private static StoredUser Get()
4038
}
4139
_current = Resources.Load<StoredUser>("/LootLockerSDK/Runtime/Editor/Resources/Config/LootLockerUser");
4240

43-
#if UNITY_EDITOR
44-
4541
if (_current == null)
4642
{
4743
StoredUser newUser = CreateInstance<StoredUser>();
@@ -60,7 +56,7 @@ private static StoredUser Get()
6056

6157
_current = newUser;
6258
}
63-
#endif
59+
6460
_current.Deserialize();
6561
return _current;
6662
}
@@ -82,9 +78,12 @@ public static StoredUser current
8278

8379
public bool RemoveUser()
8480
{
81+
DeleteLootLockerPrefs();
82+
8583
_current.serializedUser = null;
8684
_current.user = null;
8785
_current = null;
86+
8887
string configAssetPath = Application.dataPath + "/LootLockerSDK/Runtime/Editor/Resources/Config/LootLockerUser.asset";
8988
string configAssetMetaPath = Application.dataPath + "/LootLockerSDK/Runtime/Editor/Resources/Config/LootLockerUser.asset.meta";
9089

@@ -100,12 +99,20 @@ public bool RemoveUser()
10099

101100
return true;
102101
}
102+
103+
public void DeleteLootLockerPrefs()
104+
{
105+
EditorPrefs.DeleteKey("LootLocker.AdminToken");
106+
EditorPrefs.DeleteKey("LootLocker.mfaKey");
107+
EditorPrefs.DeleteKey("LootLocker.ActiveOrgID");
108+
EditorPrefs.DeleteKey("LootLocker.ActiveGameID");
109+
}
110+
103111
public static bool CreateNewUser(User _user)
104112
{
105113
current.user = _user;
106114
current.Serialize();
107115
return true;
108116
}
109-
110117
}
111118
#endif

Runtime/Editor/VisualElements/LootLocker MainWindow/LootLockerMainWindow.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ public enum ContentType
5555
[MenuItem("LootLocker/Logout", priority = 10)]
5656
public static void Logout()
5757
{
58-
EditorPrefs.DeleteAll();
5958
StoredUser.current.RemoveUser();
6059
}
6160

6261
[MenuItem("LootLocker/Settings", priority = 1)]
6362
public static void OpenMenu()
6463
{
65-
6664
LootLockerMainWindow wnd = GetWindow<LootLockerMainWindow>();
6765
wnd.titleContent = new GUIContent("LootLocker");
6866
if (StoredUser.current.user != null)
@@ -76,8 +74,12 @@ public static void OpenMenu()
7674
}
7775

7876
}
77+
7978
public void LoadLootLockerMainMenu(User user)
8079
{
80+
81+
LootLockerConfig.current.adminToken = EditorPrefs.GetString("LootLocker.AdminToken");
82+
8183
LootLockerServerManager.CheckInit();
8284

8385
activeUser = user;
@@ -161,7 +163,6 @@ public void CreateGUI()
161163
private void Update()
162164
{
163165
returnBtn.style.display = currentPage == Page.OrganisationPage ? DisplayStyle.None : DisplayStyle.Flex;
164-
165166
}
166167

167168
void Return(EventBase e)
@@ -194,7 +195,6 @@ void Return(EventBase e)
194195
target.style.display = DisplayStyle.None;
195196
break;
196197
}
197-
198198
}
199199

200200
private void OpenAPIKeyTab()
@@ -277,16 +277,13 @@ public void ApplyKeyClicked(EventBase e)
277277
button.style.borderLeftColor =
278278
button.style.borderBottomColor =
279279
button.style.borderTopColor = new Color(0.0196078431372549f, 0.15294117647058825f, 0.0784313725490196f);
280-
281280
}
282281
}
283-
284282
}
285283

286284

287285
public void CreateAPIKeyTemplate(Key key)
288286
{
289-
290287
foreach(var existingKey in keyList.Children())
291288
{
292289
if(key.name == existingKey.name)
@@ -377,8 +374,6 @@ public void PopulateList(ContentType contentType)
377374
apikeybtn.AddToClassList("optionbtn");
378375
optionList.Add(apikeybtn);
379376
break;
380-
381-
382377
}
383378
}
384379

@@ -391,7 +386,6 @@ public Button GenerateButton(Game game, bool caret)
391386
newButton.style.width = 200;
392387
newButton.style.height = 50;
393388

394-
395389
Label buttonLabel = new Label();
396390
buttonLabel.name = "name";
397391
buttonLabel.text = game.name;
@@ -450,7 +444,6 @@ public void OrgButtonClicked(EventBase e)
450444
{
451445
activeOrganisation = org;
452446
EditorPrefs.SetInt("LootLocker.ActiveOrgID", activeOrganisation.id);
453-
454447
}
455448
}
456449

@@ -478,7 +471,6 @@ public void GameButtonClicked(EventBase e)
478471
returnBtn.text = "Change Game";
479472
PopulateList(ContentType.GameOptions);
480473
OpenAPIKeyTab();
481-
482474
}
483475

484476
public void GetUserRole()
@@ -495,9 +487,7 @@ public void GetUserRole()
495487
}
496488
}
497489
EditorApplication.update -= OnEditorUpdate;
498-
499490
});
500491
}
501492
}
502-
503493
#endif

Runtime/Editor/VisualElements/LootLocker Setup/LootLockerWizard.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ public void CreateGUI()
3535
l_signup = root.Q<Label>("hyperlinksignup");
3636
l_forgotpassword = root.Q<Label>("hyperlinkforgotpass");
3737

38-
3938
l_signup.RegisterCallback<MouseDownEvent>(_ => Application.OpenURL("https://lootlocker.com/sign-up"));
4039
l_forgotpassword.RegisterCallback<MouseDownEvent>(_ => Application.OpenURL(("https://console.lootlocker.com/forgot-password")));
4140

4241
btn_login.clickable.clickedWithEventInfo += AdminExtensionLogin;
43-
4442
}
4543

4644

@@ -54,7 +52,6 @@ public void AdminExtensionLogin(EventBase e)
5452

5553
EditorApplication.update += OnEditorUpdate;
5654

57-
5855
LootLockerAdminManager.AdminLogin(i_email.value, i_password.value, (onComplete) =>
5956
{
6057
if (onComplete.success)
@@ -68,18 +65,15 @@ public void AdminExtensionLogin(EventBase e)
6865
LootLockerMFA.LoadMFAWindow();
6966
Close();
7067
}
71-
7268
else
7369
{
7470
LootLockerMainWindow wnd = GetWindow<LootLockerMainWindow>();
7571
wnd.titleContent = new GUIContent("LootLocker");
7672
wnd.LoadLootLockerMainMenu(onComplete.user);
7773
Close();
7874
}
79-
8075
}
8176
EditorApplication.update -= OnEditorUpdate;
82-
8377
});
8478
}
8579

Runtime/Game/Resources/LootLockerConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ public static LootLockerConfig current
147147
[HideInInspector]
148148
public string token;
149149
[HideInInspector]
150+
#if UNITY_EDITOR
150151
public string adminToken;
152+
#endif
151153
[HideInInspector]
152154
public string refreshToken;
153155
[HideInInspector]

0 commit comments

Comments
 (0)