Skip to content

Commit 695f56d

Browse files
authored
Merge pull request #11 from LootLocker/white-label-session-support
Add Support For New White Label Login Calls
2 parents 5705127 + 392570b commit 695f56d

File tree

4 files changed

+273
-2
lines changed

4 files changed

+273
-2
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class LootLockerEndPoints
2020
// White Label Login
2121
[Header("White Label Login")]
2222
public static EndPointClass whiteLabelSignUp = new EndPointClass("white-label-login/sign-up", LootLockerHTTPMethod.POST);
23+
public static EndPointClass whiteLabelLogin = new EndPointClass("white-label-login/login", LootLockerHTTPMethod.POST);
24+
public static EndPointClass whiteLabelVerifySession = new EndPointClass("white-label-login/verify-session", LootLockerHTTPMethod.POST);
2325
public static EndPointClass whiteLabelRequestPasswordReset = new EndPointClass("white-label-login/request-reset-password", LootLockerHTTPMethod.POST);
2426
public static EndPointClass whiteLabelRequestAccountVerification = new EndPointClass("white-label-login/request-verification", LootLockerHTTPMethod.POST);
2527

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,76 @@ public static void StartSteamSession(string steamId64, Action<LootLockerSessionR
190190
LootLockerAPIManager.Session(sessionRequest, onComplete);
191191
}
192192

193+
/// <summary>
194+
/// Checks if we have a stored session and also if that session is valid.
195+
///
196+
/// Depending on response of this method the developer can either start a session using the token,
197+
/// or show a login form.
198+
///
199+
/// White label platform must be enabled in the web console for this to work.
200+
/// </summary>
201+
public static void CheckWhiteLabelSession(Action<bool> onComplete)
202+
{
203+
if (!CheckInitialized())
204+
{
205+
onComplete(false);
206+
return;
207+
}
208+
209+
string existingSessionToken = PlayerPrefs.GetString("LootLockerWhiteLabelSessionToken", "");
210+
if (existingSessionToken == "")
211+
{
212+
onComplete(false);
213+
return;
214+
}
215+
216+
string existingSessionEmail = PlayerPrefs.GetString("LootLockerWhiteLabelSessionEmail", "");
217+
if (existingSessionEmail == "")
218+
{
219+
onComplete(false);
220+
return;
221+
}
222+
223+
LootLockerWhiteLabelVerifySessionRequest sessionRequest = new LootLockerWhiteLabelVerifySessionRequest();
224+
sessionRequest.email = existingSessionEmail;
225+
sessionRequest.token = existingSessionToken;
226+
227+
LootLockerAPIManager.WhiteLabelVerifySession(sessionRequest, response =>
228+
{
229+
if (!response.success)
230+
{
231+
onComplete(false);
232+
return;
233+
}
234+
235+
onComplete(true);
236+
});
237+
}
238+
239+
public static void CheckWhiteLabelSession(string email, string token, Action<bool> onComplete)
240+
{
241+
if (!CheckInitialized())
242+
{
243+
onComplete(false);
244+
return;
245+
}
246+
247+
LootLockerWhiteLabelVerifySessionRequest sessionRequest = new LootLockerWhiteLabelVerifySessionRequest();
248+
sessionRequest.email = email;
249+
sessionRequest.token = token;
250+
251+
LootLockerAPIManager.WhiteLabelVerifySession(sessionRequest, response =>
252+
{
253+
if (!response.success)
254+
{
255+
onComplete(false);
256+
return;
257+
}
258+
259+
onComplete(true);
260+
});
261+
}
262+
193263
/// <summary>
194264
/// Create new user using the white label login system.
195265
///
@@ -206,6 +276,45 @@ public static void StartWhiteLabelSession(string email, string password, Action<
206276
LootLockerAPIManager.WhiteLabelSession(sessionRequest, onComplete);
207277
}
208278

279+
public static void StartWhiteLabelSession(LootLockerWhiteLabelSessionRequest input, Action<LootLockerSessionResponse> onComplete)
280+
{
281+
if (!CheckInitialized())
282+
{
283+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerSessionResponse>());
284+
return;
285+
}
286+
LootLockerWhiteLabelSessionRequest sessionRequest = new LootLockerWhiteLabelSessionRequest(input.email);
287+
sessionRequest.token = input.token;
288+
LootLockerAPIManager.WhiteLabelSession(sessionRequest, onComplete);
289+
}
290+
291+
public static void StartWhiteLabelSession(Action<LootLockerSessionResponse> onComplete)
292+
{
293+
if (!CheckInitialized())
294+
{
295+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerSessionResponse>());
296+
return;
297+
}
298+
299+
string existingSessionToken = PlayerPrefs.GetString("LootLockerWhiteLabelSessionToken", "");
300+
if (existingSessionToken == "")
301+
{
302+
onComplete(LootLockerResponseFactory.Error<LootLockerSessionResponse>("no session token found"));
303+
return;
304+
}
305+
306+
string existingSessionEmail = PlayerPrefs.GetString("LootLockerWhiteLabelSessionEmail", "");
307+
if (existingSessionEmail == "")
308+
{
309+
onComplete(LootLockerResponseFactory.Error<LootLockerSessionResponse>("no session email found"));
310+
return;
311+
}
312+
313+
LootLockerWhiteLabelSessionRequest sessionRequest = new LootLockerWhiteLabelSessionRequest(existingSessionEmail);
314+
sessionRequest.token = existingSessionToken;
315+
LootLockerAPIManager.WhiteLabelSession(sessionRequest, onComplete);
316+
}
317+
209318
public static void EndSession(string deviceId, Action<LootLockerSessionResponse> onComplete)
210319
{
211320
if (!CheckInitialized())
@@ -225,6 +334,52 @@ public static void EndSession(string deviceId, Action<LootLockerSessionResponse>
225334

226335
#region White Label Login
227336

337+
/// <summary>
338+
/// Create new user using the white label login system.
339+
///
340+
/// White label platform must be enabled in the web console for this to work.
341+
/// </summary>
342+
public static void WhiteLabelLogin(string email, string password, Action<LootLockerWhiteLabelLoginResponse> onComplete)
343+
{
344+
if (!CheckInitialized())
345+
{
346+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerWhiteLabelLoginResponse>());
347+
return;
348+
}
349+
350+
LootLockerWhiteLabelUserRequest input = new LootLockerWhiteLabelUserRequest
351+
{
352+
email = email,
353+
password = password
354+
};
355+
356+
LootLockerAPIManager.WhiteLabelLogin(input, onComplete);
357+
}
358+
359+
public static void WhiteLabelLogin(string email, string password, bool remember, Action<LootLockerWhiteLabelLoginResponse> onComplete)
360+
{
361+
if (!CheckInitialized())
362+
{
363+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerWhiteLabelLoginResponse>());
364+
return;
365+
}
366+
367+
LootLockerWhiteLabelUserRequest input = new LootLockerWhiteLabelUserRequest
368+
{
369+
email = email,
370+
password = password,
371+
remember = remember
372+
};
373+
374+
LootLockerAPIManager.WhiteLabelLogin(input, response => {
375+
PlayerPrefs.SetString("LootLockerWhiteLabelSessionToken", response.SessionToken);
376+
PlayerPrefs.SetString("LootLockerWhiteLabelSessionEmail", email);
377+
PlayerPrefs.Save();
378+
379+
onComplete(response);
380+
});
381+
}
382+
228383
/// <summary>
229384
/// Create new user using the white label login system.
230385
///

Runtime/Game/Requests/LootLockerSessionRequest.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,24 @@ public class LootLockerWhiteLabelSessionRequest : LootLockerGetRequest
3333
public string game_key => LootLockerConfig.current.apiKey?.ToString();
3434
public string email { get; private set; }
3535
public string password { get; private set; }
36+
public string token { get; set; }
3637
public string game_version => LootLockerConfig.current.game_version;
3738
public bool development_mode => LootLockerConfig.current.developmentMode;
3839
public LootLockerWhiteLabelSessionRequest(string email, string password)
3940
{
4041
this.email = email;
4142
this.password = password;
4243
}
44+
45+
public LootLockerWhiteLabelSessionRequest(string email)
46+
{
47+
this.email = email;
48+
}
4349
}
4450

4551
[System.Serializable]
4652
public class LootLockerSessionResponse : LootLockerResponse
4753
{
48-
4954
public string session_token { get; set; }
5055
public int player_id { get; set; }
5156
public bool seen_before { get; set; }
@@ -116,7 +121,7 @@ public static void WhiteLabelSession(LootLockerGetRequest data, Action<LootLocke
116121
if (string.IsNullOrEmpty(serverResponse.Error))
117122
{
118123
response = JsonConvert.DeserializeObject<LootLockerSessionResponse>(serverResponse.text);
119-
LootLockerConfig.current.UpdateToken(response.session_token, (data as LootLockerSessionRequest)?.player_identifier);
124+
LootLockerConfig.current.UpdateToken(response.session_token, "");
120125
}
121126

122127
response.text = serverResponse.text;

Runtime/Game/Requests/WhiteLabelRequest.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ public class LootLockerWhiteLabelUserRequest
1414
{
1515
public string email { get; set; }
1616
public string password { get; set; }
17+
public bool remember { get; set; }
18+
}
19+
20+
public class LootLockerWhiteLabelVerifySessionRequest
21+
{
22+
public string email { get; set; }
23+
public string token { get; set; }
24+
}
25+
26+
public class LootLockerWhiteLabelVerifySessionResponse : LootLockerResponse
27+
{
28+
public string Email { get; set; }
29+
public string Token { get; set; }
1730
}
1831

1932
public class LootLockerWhiteLabelSignupResponse : LootLockerResponse
@@ -29,12 +42,108 @@ public class LootLockerWhiteLabelSignupResponse : LootLockerResponse
2942
#nullable enable
3043
public string? ValidatedAt { get; set; }
3144
}
45+
46+
public class LootLockerWhiteLabelLoginResponse : LootLockerWhiteLabelSignupResponse
47+
{
48+
public string? SessionToken { get; set; }
49+
}
3250
}
3351

3452
namespace LootLocker
3553
{
3654
public partial class LootLockerAPIManager
3755
{
56+
57+
public static void WhiteLabelLogin(LootLockerWhiteLabelUserRequest input, Action<LootLockerWhiteLabelLoginResponse> onComplete)
58+
{
59+
EndPointClass endPoint = LootLockerEndPoints.whiteLabelLogin;
60+
61+
string json = "";
62+
if (input == null)
63+
{
64+
return;
65+
}
66+
else
67+
{
68+
json = JsonConvert.SerializeObject(input);
69+
}
70+
71+
LootLockerServerRequest.CallDomainAuthAPI(endPoint.endPoint, endPoint.httpMethod, json, ((serverResponse) =>
72+
{
73+
LootLockerWhiteLabelLoginResponse? response = new LootLockerWhiteLabelLoginResponse();
74+
if (string.IsNullOrEmpty(serverResponse.Error) && serverResponse.text != null)
75+
{
76+
DefaultContractResolver contractResolver = new DefaultContractResolver
77+
{
78+
NamingStrategy = new SnakeCaseNamingStrategy()
79+
};
80+
81+
response = JsonConvert.DeserializeObject<LootLockerWhiteLabelLoginResponse>(serverResponse.text, new JsonSerializerSettings
82+
{
83+
ContractResolver = contractResolver,
84+
Formatting = Formatting.Indented
85+
});
86+
87+
if (response == null)
88+
{
89+
response = LootLockerResponseFactory.Error<LootLockerWhiteLabelLoginResponse>("error deserializing server response");
90+
onComplete?.Invoke(response);
91+
return;
92+
}
93+
}
94+
95+
response.text = serverResponse.text;
96+
response.success = serverResponse.success;
97+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
98+
onComplete?.Invoke(response);
99+
}));
100+
}
101+
102+
public static void WhiteLabelVerifySession(LootLockerWhiteLabelVerifySessionRequest input, Action<LootLockerWhiteLabelVerifySessionResponse> onComplete)
103+
{
104+
EndPointClass endPoint = LootLockerEndPoints.whiteLabelVerifySession;
105+
106+
string json = "";
107+
if (input == null)
108+
{
109+
return;
110+
}
111+
else
112+
{
113+
json = JsonConvert.SerializeObject(input);
114+
}
115+
116+
LootLockerServerRequest.CallDomainAuthAPI(endPoint.endPoint, endPoint.httpMethod, json, ((serverResponse) =>
117+
{
118+
LootLockerWhiteLabelVerifySessionResponse? response = new LootLockerWhiteLabelVerifySessionResponse();
119+
if (string.IsNullOrEmpty(serverResponse.Error) && serverResponse.text != null)
120+
{
121+
DefaultContractResolver contractResolver = new DefaultContractResolver
122+
{
123+
NamingStrategy = new SnakeCaseNamingStrategy()
124+
};
125+
126+
response = JsonConvert.DeserializeObject<LootLockerWhiteLabelVerifySessionResponse>(serverResponse.text, new JsonSerializerSettings
127+
{
128+
ContractResolver = contractResolver,
129+
Formatting = Formatting.Indented
130+
});
131+
132+
if (response == null)
133+
{
134+
response = LootLockerResponseFactory.Error<LootLockerWhiteLabelVerifySessionResponse>("error deserializing server response");
135+
onComplete?.Invoke(response);
136+
return;
137+
}
138+
}
139+
140+
response.text = serverResponse.text;
141+
response.success = serverResponse.success;
142+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
143+
onComplete?.Invoke(response);
144+
}));
145+
}
146+
38147
public static void WhiteLabelSignUp(LootLockerWhiteLabelUserRequest input, Action<LootLockerWhiteLabelSignupResponse> onComplete)
39148
{
40149
EndPointClass endPoint = LootLockerEndPoints.whiteLabelSignUp;

0 commit comments

Comments
 (0)