Code changes
Did not run code. Had a spur of the moment to try something out.
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
// using JwtAuthentication.Shared.Exceptions;
|
||||
// using JwtAuthentication.Shared.Models;
|
||||
using System.Linq;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
using Icarus.Exceptions;
|
||||
using Icarus.Models.Shared;
|
||||
using Icarus.Services;
|
||||
using Icarus.Repositories;
|
||||
using Icarus.Database.Contexts;
|
||||
|
||||
namespace Icarus.Services
|
||||
{
|
||||
@@ -11,6 +16,7 @@ namespace Icarus.Services
|
||||
{
|
||||
private Microsoft.Extensions.Configuration.IConfiguration _configuration;
|
||||
private readonly UserRepository userRepository;
|
||||
private readonly UserContext _userContext;
|
||||
|
||||
public UserService(UserRepository userRepository, Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
@@ -18,9 +24,17 @@ namespace Icarus.Services
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
// public UserService(UserContext userContext, Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
public UserService(Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
this._configuration = configuration;
|
||||
this._userContext = new UserContext(configuration.GetConnectionString("DefaultConnection"));
|
||||
}
|
||||
|
||||
public void ValidateCredentials(UserCredentials userCredentials)
|
||||
{
|
||||
Icarus.Models.User user = userRepository.GetUser(userCredentials.Username);
|
||||
// Icarus.Models.User user = userRepository.GetUser(userCredentials.Username);
|
||||
var user = _userContext.Users.FirstOrDefault(usr => usr.Username.Equals(userCredentials.Username));
|
||||
bool isValid = user != null && AreValidCredentials(userCredentials, user);
|
||||
|
||||
if (!isValid)
|
||||
@@ -31,8 +45,9 @@ namespace Icarus.Services
|
||||
|
||||
private static bool AreValidCredentials(UserCredentials userCredentials, Icarus.Models.User user)
|
||||
{
|
||||
return user.Username == userCredentials.Username &&
|
||||
user.Password == userCredentials.Password;
|
||||
// TODO: Has the user provided password and compair it to the hash retrieved from
|
||||
// the DB
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user