@@ -15,8 +15,8 @@ namespace Lowscope.AppwritePlugin.Accounts
15
15
{
16
16
public class Account
17
17
{
18
- public Action < User > OnLogin = delegate { } ;
19
- public Action OnLogout = delegate { } ;
18
+ public Action < User > OnLogin = delegate { } ;
19
+ public Action OnLogout = delegate { } ;
20
20
21
21
private readonly AppwriteConfig config ;
22
22
private readonly Dictionary < string , string > headers ;
@@ -25,7 +25,7 @@ public class Account
25
25
private DateTime lastRegisterRequestDate ;
26
26
27
27
private bool validatedSession = false ;
28
-
28
+
29
29
private string UserPath => Path . Combine ( Application . persistentDataPath , "user.json" ) ;
30
30
31
31
internal Account ( AppwriteConfig config )
@@ -46,11 +46,11 @@ private void StoreUserToDisk()
46
46
{
47
47
FileUtilities . Write ( user , UserPath , config ) ;
48
48
49
- if ( validatedSession )
49
+ if ( validatedSession )
50
50
return ;
51
-
51
+
52
52
validatedSession = true ;
53
-
53
+
54
54
OnLogin ( user ) ;
55
55
}
56
56
@@ -90,7 +90,7 @@ private async UniTask<bool> RequestUserInfo()
90
90
ClearUserDataFromDisk ( ) ;
91
91
break ;
92
92
}
93
-
93
+
94
94
return false ;
95
95
}
96
96
@@ -142,7 +142,7 @@ or HttpStatusCode.InternalServerError
142
142
or HttpStatusCode . TooManyRequests :
143
143
return ( null , ELoginResponse . ServerBusy ) ;
144
144
}
145
-
145
+
146
146
Debug . Log ( $ "Unimplemented: { httpStatusCode } { body } ") ;
147
147
return ( null , ELoginResponse . Failed ) ;
148
148
}
@@ -173,7 +173,7 @@ or HttpStatusCode.InternalServerError
173
173
{
174
174
if ( ! WebUtilities . IsEmailValid ( email ) )
175
175
return ( null , ERegisterResponse . InvalidEmail ) ;
176
-
176
+
177
177
if ( string . IsNullOrEmpty ( id ) || string . IsNullOrEmpty ( name ) || string . IsNullOrEmpty ( email ) )
178
178
return ( null , ERegisterResponse . MissingCredentials ) ;
179
179
@@ -215,7 +215,7 @@ or HttpStatusCode.InternalServerError
215
215
return ( null , ERegisterResponse . InvalidEmail ) ;
216
216
break ;
217
217
}
218
-
218
+
219
219
Debug . Log ( $ "Unimplemented: { httpStatusCode } { body } ") ;
220
220
return ( null , ERegisterResponse . Failed ) ;
221
221
}
@@ -298,7 +298,7 @@ public async UniTask<EEmailVerifyResponse> RequestVerificationMail()
298
298
string url = $ "{ config . AppwriteURL } /account/verification";
299
299
using var request = new WebRequest ( EWebRequestType . POST , url , headers , user . Cookie , bytes ) ;
300
300
var ( json , httpStatusCode ) = await request . Send ( ) ;
301
-
301
+
302
302
// Session has become invalid, not able to utilize session anymore.
303
303
switch ( httpStatusCode )
304
304
{
@@ -314,6 +314,33 @@ public async UniTask<EEmailVerifyResponse> RequestVerificationMail()
314
314
return httpStatusCode == HttpStatusCode . Created ? EEmailVerifyResponse . Sent : EEmailVerifyResponse . Failed ;
315
315
}
316
316
317
+ public async UniTask < EAccountRecoverResponse > RequestPasswordRecovery ( string email )
318
+ {
319
+ if ( ! WebUtilities . IsEmailValid ( email ) )
320
+ return EAccountRecoverResponse . InvalidEmail ;
321
+
322
+ if ( user != null )
323
+ return EAccountRecoverResponse . AlreadyLoggedIn ;
324
+
325
+ JObject obj = new JObject ( new JProperty ( "email" , email ) , new JProperty ( "url" , config . RecoverPasswordURL ) ) ;
326
+ byte [ ] bytes = Encoding . UTF8 . GetBytes ( obj . ToString ( ) ) ;
327
+
328
+ string url = $ "{ config . AppwriteURL } /account/recovery";
329
+ using var request = new WebRequest ( EWebRequestType . POST , url , headers , "" , bytes ) ;
330
+ var ( json , httpStatusCode ) = await request . Send ( ) ;
331
+
332
+ switch ( httpStatusCode )
333
+ {
334
+ case HttpStatusCode . Unauthorized :
335
+ case HttpStatusCode . NotFound :
336
+ return EAccountRecoverResponse . Failed ;
337
+ }
338
+
339
+ return httpStatusCode == HttpStatusCode . Created
340
+ ? EAccountRecoverResponse . Sent
341
+ : EAccountRecoverResponse . Failed ;
342
+ }
343
+
317
344
/// <summary>
318
345
/// Obtains user information
319
346
/// </summary>
0 commit comments