The cloud manager acts as an intermediary for syncing between the local biskilog server manager and the biskilog accounting web application
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.

96 lines
3.3 KiB

using Cloud_Manager;
using Cloud_Manager.Models.ClientContractModels;
using Cloud_Manager.Models.Enums;
using Cloud_Manager.Models.Interfaces;
using Microsoft.EntityFrameworkCore;
namespace Cloud_Manager.Services
{
public class AuthenticationService : IAuthService
{
private readonly BiskilogContext m_context;
private readonly IKeyService m_tokenService;
public AuthenticationService(BiskilogContext a_context, IKeyService a_tokenService)
{
m_context = a_context;
m_tokenService = a_tokenService;
}
/// <summary>
/// Returns the status of a user account
/// </summary>
/// <returns>AuthEnums</returns>
public AuthEnums AccountStatus(int? a_id, string? a_username)
{
if (m_context.Userauths.Any(i => i.UserId == a_id || i.Username == a_username))
{
return AuthEnums.Found;
}
else
{
return AuthEnums.NotFound;
}
}
public Task<string> AuthenticateClient(string a_username, string a_password)
{
throw new NotImplementedException();
}
/// <summary>
/// Creates a new user account
/// </summary>
/// returns AuthEnums.successful if the account was created successfully
public AuthEnums CreateUser(Userauth a_user)
{
throw new NotImplementedException();
//if (AccountStatus(null, a_user.Username) == AuthEnums.Found)
// return AuthEnums.Registered;
//a_user.Role = m_context.UserRoles.First(i => i.RoleId== a_user.RoleId);
//a_user.Password = BCrypt.Net.BCrypt.HashPassword(a_user.Password);
//m_context.Users.Add(a_user);
//var result = m_context.SaveChangesAsync();
//result.Wait();
//if(result.Result > 0)
//{
// return AuthEnums.Successful;
//}
//return AuthEnums.Error;
}
/// <summary>
/// Deletes a user account
/// </summary>
/// <exception cref="NotImplementedException"></exception>
public void DeleteUser(int a_id)
{
throw new NotImplementedException();
}
public List<Clientbusiness> GetClientbusiness(int a_clientId, int userId)
{
return (from b in m_context.Clientbusinesses
join p in m_context.Siteaccesspermissions on new { b.ClientId, b.BusinessId } equals new { p.ClientId, p.BusinessId }
where p.UserId == userId && p.ClientId == a_clientId
select b).ToList();
}
public Databasemap GetClientDB(int a_clientId)
{
return m_context.Databasemaps.First(t => t.ClientId == a_clientId);
}
public Contract? GetContract(int a_clientId, List<int> a_businessId)
{
return m_context.Contracts.FirstOrDefault(c => c.ClientId == a_clientId && a_businessId.Contains(c.BusinessId!.Value) && c.EndDate >= DateTime.Now);
}
public List<Siteaccesspermission> GetSiteaccesspermission(int a_clientId, int a_userId)
{
return m_context.Siteaccesspermissions.Where(t => t.ClientId == a_clientId && t.UserId == a_userId).ToList();
}
}
}