-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
144 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace MAUIsland; | ||
|
||
public record PrincipalUserModel | ||
( | ||
Guid guid, | ||
string userName, | ||
string firstName, | ||
string lastName, | ||
string profilePicUrl, | ||
string email, | ||
string phoneNumber, | ||
string country, | ||
bool gender, | ||
List<string> roles | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
public record ServiceUserInfo(string guid, string userName, string avatarGuild); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace MAUIsland; | ||
|
||
public class UserInformation | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,12 @@ public AuthenticatePopupViewModel(IAppNavigator appNavigator, | |
|
||
[ObservableProperty] | ||
string phoneNumber = "0348164682"; | ||
|
||
[ObservableProperty] | ||
string email = "[email protected]"; | ||
|
||
[ObservableProperty] | ||
string avatarUrl; | ||
#endregion | ||
|
||
#region [Relay Commands] | ||
|
@@ -41,12 +47,34 @@ async Task LoginAsync() | |
{ | ||
try | ||
{ | ||
var accessToken = await this.authenticationServices.SignInWithPhoneNumber(PhoneNumber, Password); | ||
var authenticationToken = await this.authenticationServices.AuthenticateWithPhoneNumber(PhoneNumber, Password); | ||
Guard.IsNotNullOrWhiteSpace(authenticationToken); | ||
|
||
var userInfo = await this.userServices.GetUserInfo(authenticationToken); | ||
Guard.IsNotNull(userInfo); | ||
|
||
await this.userServices.SaveUserToLocalAsync(userInfo); | ||
WeakReferenceMessenger.Default.Send(new LoginMessage(userInfo)); | ||
await AppNavigator.GoBackAsync(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
await AppNavigator.ShowSnackbarAsync(ex.Message); | ||
throw; | ||
} | ||
} | ||
|
||
Guard.IsNotNullOrWhiteSpace(accessToken); | ||
var userInfo = await this.userServices.GetUserByAccessToken(accessToken); | ||
[RelayCommand] | ||
async Task SignUpAsync() | ||
{ | ||
try | ||
{ | ||
var authenticationAccessToken = await this.authenticationServices.CreatePrincipleUserInfo(PhoneNumber, UserName, Email, Password, "", "", ""); | ||
Guard.IsNotNullOrWhiteSpace(authenticationAccessToken); | ||
|
||
var userInfo = await this.userServices.GetUserInfo(authenticationAccessToken); | ||
Guard.IsNotNull(userInfo); | ||
|
||
await this.userServices.SaveUserToLocalAsync(userInfo); | ||
WeakReferenceMessenger.Default.Send(new LoginMessage(userInfo)); | ||
await AppNavigator.GoBackAsync(); | ||
|
9 changes: 5 additions & 4 deletions
9
...erfaces/ITotechsIdentityAuthentication.cs → ...es/ITotechsIdentityAuthenticationRefit.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 35 additions & 20 deletions
55
src/Features/Chat/Services/Implementations/RefitAuthenticationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,59 @@ | ||
using Refit; | ||
using System.Net; | ||
|
||
namespace MAUIsland; | ||
|
||
public class RefitAuthenticationService : IAuthenticationServices | ||
{ | ||
private readonly ITotechsIdentityAuthentication totechsIdentityAuthentication; | ||
private readonly ITotechsIdentityAuthenticationRefit totechsIdentityAuthenticationRefit; | ||
private readonly IUserServices userServices; | ||
private readonly IAppNavigator appNavigator; | ||
#region [CTor] | ||
public RefitAuthenticationService(ITotechsIdentityAuthentication totechsIdentityAuthentication, IAppNavigator appNavigator) | ||
public RefitAuthenticationService(ITotechsIdentityAuthenticationRefit totechsIdentityAuthenticationRefit, IUserServices userServices, IAppNavigator appNavigator) | ||
{ | ||
this.totechsIdentityAuthentication = totechsIdentityAuthentication; | ||
this.totechsIdentityAuthenticationRefit = totechsIdentityAuthenticationRefit; | ||
this.userServices = userServices; | ||
this.appNavigator = appNavigator; | ||
} | ||
#endregion | ||
public Task<string> SignIn(string userName, string password) | ||
|
||
#region [Methods] | ||
|
||
|
||
public async Task<string> Authenticate(string username, string password) | ||
{ | ||
return Task.Run(() => | ||
{ | ||
return string.Empty; | ||
} | ||
); | ||
var response = await this.totechsIdentityAuthenticationRefit.Login(username, password); | ||
return response.AccessToken; | ||
} | ||
|
||
public async Task<string> SignInWithPhoneNumber(string phoneNumber, string password) | ||
public async Task<string> AuthenticateWithPhoneNumber(string phoneNumer, string password) | ||
{ | ||
try | ||
{ | ||
var totechsIdentityInfo = await this.totechsIdentityAuthentication.LoginWithPhoneNumber(new PhoneNumberLoginDTO(phoneNumber, password)); | ||
var response = await this.totechsIdentityAuthenticationRefit.LoginWithPhoneNumber(new PhoneNumberLoginDTO(phoneNumer, password)); | ||
return response.AccessToken; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
catch (ApiException ex) | ||
public async Task<string> CreatePrincipleUserInfo(string phoneNumber, string userName, string email, string password, string firstName, string lastName, string profilePicUrl) | ||
{ | ||
var response = await this.totechsIdentityAuthenticationRefit.Register(userName, password, firstName, lastName, email, phoneNumber, profilePicUrl, new string[] { "", "" }); | ||
if (response == HttpStatusCode.NoContent) | ||
{ | ||
await this.appNavigator.ShowSnackbarAsync(ex.Message); | ||
throw; | ||
return string.Empty; | ||
} | ||
else return string.Empty; | ||
} | ||
|
||
public Task<string> SignUp(string phoneNumber, string userName, string email, string password) | ||
public Task<PrincipalUserModel> GetPrincipleUserInfo(string userGuid, string authenticateAccessToken) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<ServiceUserInfo> GetServiceUserInfo(string userGuid, string authenticateAccessToken) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<string> SignUp(string authenticateAccessToken, string avatarUrl, string userName) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters