You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
KWWebInvApp/Services/AuthenticationService.cs

48 lines
1.4 KiB
C#

using KWWebInvApp.Data;
using UserInfoServices;
namespace KWWebInvApp.Services
{
public class AuthenticationService : IAuthenticationService
{
private UserInfoServices.userinfo? CurrentUser;
public async Task<userinfo> GetAuthenticatedUserAsync()
{
return CurrentUser;
}
public async Task SetAuthenticatedUserAsync(UserInfoServices.userinfo currentUser)
{
CurrentUser = currentUser;
}
public async Task<bool> LoginAsync(LoginData loginData)
{
if (!string.IsNullOrWhiteSpace(loginData.username) && !string.IsNullOrWhiteSpace(loginData.password))
{
UserInfoServices.UserInfoServiceClient userInfoServiceClient = new();
UserInfoServices.userinfo userAttemptingToLogin = new UserInfoServices.userinfo()
{
username = loginData.username,
pass = await userInfoServiceClient.md5EncodingAsync(loginData.password)
};
CurrentUser = await userInfoServiceClient.AuthenticateUserAsync(userAttemptingToLogin);
if (CurrentUser == null)
return false;
else
return true;
}
return false;
}
public async Task LogoutAsync()
{
CurrentUser = null;
}
}
}