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

261 lines
8.9 KiB

using APP.Models;
using BWPMModels;
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Reflection;
using System.Net.Http;
using App.Helper;
using APP.Helper;
namespace APP.Identity
{
public class UserStoreAppService : IUserEmailStore<AppUser>, IUserPasswordStore<AppUser>, IUserLoginStore<AppUser>, IDisposable
{
//private IAccountDAL _accountDAL;
//public UserStoreAppService(IAccountDAL accountDAL)
//{
// _accountDAL = accountDAL;
//}
public Task AddLoginAsync(AppUser user, UserLoginInfo login, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<IdentityResult> CreateAsync(AppUser user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<IdentityResult> DeleteAsync(AppUser user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public void Dispose()
{
}
public async Task<AppUser> FindByEmailPasswordAsync(string normalizedEmail, string normalizedPassword, CancellationToken cancellationToken)
{
App.Helper.HttpClientHelper httpcli = new App.Helper.HttpClientHelper();
User u = new User();
u.email = normalizedEmail;
httpcli.CallService("user", normalizedEmail + "/" + normalizedPassword, "GET", u);
if (httpcli.Results.resultstatus != true)
{
return null;
}
var appUser = new AppUser()
{
Id = u.ID,
PassWord = u.passwort,
Email = u.email,
FullName = u.username,
Avatar = "",
Usertype = u.usertype.ToString()
};
return appUser;
}
public async Task<AppUser> FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken)
{
App.Helper.HttpClientHelper httpcli = new App.Helper.HttpClientHelper();
User u = new User();
u.email = normalizedEmail;
httpcli.CallService("user", "EMail/"+u.email, "GET", u);
if (httpcli.Results.resultstatus != true)
{
return null;
}
List<User> user = JsonConvert.DeserializeObject<List<User>>(httpcli.Results.daten);
var appUser = new AppUser()
{
Id = user[0].ID,
PassWord = user[0].passwort,
Email = user[0].email,
FullName = user[0].username,
Avatar = "",
Usertype = user[0].usertype.ToString()
};
return appUser;
}
public async Task<AppUser> FindByIdAsync(string userId, CancellationToken cancellationToken)
{
App.Helper.HttpClientHelper httpcli = new App.Helper.HttpClientHelper();
User u = new User();
u.ID = Convert.ToInt32(userId);
httpcli.CallService("user", userId, "GET", u);
if (httpcli.Results.resultstatus != true)
{
return null;
}
List<User> user = JsonConvert.DeserializeObject<List<User>>(httpcli.Results.daten);
var appUser = new AppUser()
{
Id = user[0].ID,
PassWord = user[0].passwort,
Email = user[0].email,
FullName = user[0].username,
Avatar = "",
Usertype = user[0].usertype.ToString()
};
return appUser;
throw new NotImplementedException();
//if (!string.IsNullOrEmpty(userId))
// userId = userId.ToLower();
//cancellationToken.ThrowIfCancellationRequested();
//if (userId == null) throw new ArgumentNullException(nameof(userId));
//var employee = await _accountDAL.GetById(Convert.ToInt32(userId));
//if (employee != null)
//{
// var appUser = new AppUser()
// {
// Id = employee.Id,
// PassWord = employee.PassWord,
// Email = employee.Email,
// FullName = employee.FullName,
// Avatar = employee.Avatar
// };
// return appUser;
//}
//return null;
}
public Task<AppUser> FindByLoginAsync(string loginProvider, string providerKey, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public async Task<AppUser> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken)
{
App.Helper.HttpClientHelper httpcli = new App.Helper.HttpClientHelper();
AppUser u = new AppUser();
u.Name = normalizedUserName.ToLower();
httpcli.CallService("user", "Email/"+u.Name, "GET", u);
if (httpcli.Results.resultstatus != true)
{
return null;
}
List<User> user = JsonConvert.DeserializeObject<List<User>>(httpcli.Results.daten);
var appUser = new AppUser()
{
Id = user[0].ID,
PassWord = user[0].passwort,
Email = user[0].email,
FullName = user[0].username,
Avatar = "",
Usertype = user[0].usertype.ToString()
};
return appUser;
}
public Task<string> GetEmailAsync(AppUser user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<bool> GetEmailConfirmedAsync(AppUser user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<IList<UserLoginInfo>> GetLoginsAsync(AppUser user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<string> GetNormalizedEmailAsync(AppUser user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<string> GetNormalizedUserNameAsync(AppUser user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<string> GetPasswordHashAsync(AppUser user, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
return Task.FromResult(user.PassWord);
}
public Task<string> GetUserIdAsync(AppUser user, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
if (user == null) throw new ArgumentNullException(nameof(user));
return Task.FromResult(user.Id.ToString());
}
public Task<string> GetUserNameAsync(AppUser user, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
return Task.FromResult(user.Email);
}
public Task<bool> HasPasswordAsync(AppUser user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task RemoveLoginAsync(AppUser user, string loginProvider, string providerKey, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task SetEmailAsync(AppUser user, string email, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task SetEmailConfirmedAsync(AppUser user, bool confirmed, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task SetNormalizedEmailAsync(AppUser user, string normalizedEmail, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task SetNormalizedUserNameAsync(AppUser user, string normalizedName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task SetPasswordHashAsync(AppUser user, string passwordHash, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task SetUserNameAsync(AppUser user, string userName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task<IdentityResult> UpdateAsync(AppUser user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}