| 
						
						
						
					 | 
				
				 | 
				
					@ -1,4 +1,5 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					using Biskilog_Accounting.Shared.ClientContractModels; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					using BCrypt.Net; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					using Biskilog_Accounting.Shared.ClientContractModels; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					using Biskilog_Accounting.Shared.Enums; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					using Biskilog_Accounting.Shared.Interfaces; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					using Microsoft.EntityFrameworkCore; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -55,7 +56,7 @@ namespace Biskilog_Accounting.Server.Services | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            List<int> businessIds = GetSiteaccesspermission(user.ClientId, user.UserId).Select(t => t.BusinessId).ToList(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            Contract? contract = GetContract(user.ClientId, businessIds); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            List<string> businesses = GetClientbusiness(user.ClientId, user.UserId).Select(t=>t.BusinessExternalId).ToList(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            List<string> businesses = GetClientbusiness(user.ClientId, user.UserId).Select(t => t.BusinessExternalId).ToList(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (contract == null) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                return AuthEnums.Invalid.ToString(); | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -98,7 +99,7 @@ namespace Biskilog_Accounting.Server.Services | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        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} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    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(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -118,28 +119,33 @@ namespace Biskilog_Accounting.Server.Services | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            return m_context.Siteaccesspermissions.Where(t => t.ClientId == a_clientId && t.UserId == a_userId).ToList(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        private async Task<Userauth> GetUserAsync(string username, string password) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        private async Task<Userauth?> GetUserAsync(string username, string password) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //Todo have complete implementation after means of creating user is done
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //try
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //{
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //    string pa = await m_context.Userauths.Where(u => u.Username == username).Select(u => u.Password).FirstAsync();
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //    bool verified = BCrypt.Net.BCrypt.Verify(password, pa);
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //    if (verified)
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //    {
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //TODO have a complete implementation
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            return await m_context.Userauths.FirstAsync(u => u.Username == username && u.Passsword == password); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //    }
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //    else
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //    {
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //        return null;
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //    }
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //}catch(Exception ex)
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //{
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //    //possible is user not found 
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //    return null;
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //}
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            try | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                string? pa = await m_context.Userauths.Where(u => u.Username == username || u.Email == username).Select(u => u.Passsword).FirstOrDefaultAsync(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (String.IsNullOrEmpty(pa)) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    return null; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                bool verified = BCrypt.Net.BCrypt.Verify(password, pa); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (verified) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    return await m_context.Userauths.FirstAsync(u => u.Username == username || u.Email == username); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                else | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    return null; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            catch (Exception ex) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                //possible is user not found 
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                return null; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
					 | 
				
				 | 
				
					
  |