Use new Auth API
This commit is contained in:
parent
38e76d3539
commit
79c17f75cd
16 changed files with 94 additions and 150 deletions
19
Website/Data/AuthenticationProvider.cs
Normal file
19
Website/Data/AuthenticationProvider.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Website.Models;
|
||||
|
||||
namespace Website.Data {
|
||||
public class AuthenticationProvider:ApiClient, IAuthenticationProvider {
|
||||
public AuthenticationProvider(HttpClient client) : base(client) {
|
||||
}
|
||||
|
||||
public async Task<User> Authenticate(LoginRequest request) {
|
||||
try {
|
||||
return await Post<User>("authenticate", request);
|
||||
}
|
||||
catch (ApiCallException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8
Website/Data/IAuthenticationProvider.cs
Normal file
8
Website/Data/IAuthenticationProvider.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
using System.Threading.Tasks;
|
||||
using Website.Models;
|
||||
|
||||
namespace Website.Data {
|
||||
public interface IAuthenticationProvider {
|
||||
Task<User> Authenticate(LoginRequest request);
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
using System.Data;
|
||||
|
||||
namespace Website.Data
|
||||
{
|
||||
public interface IDatabaseProvider
|
||||
{
|
||||
IDbConnection NewConnection();
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
using System.Data;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace Website.Data
|
||||
{
|
||||
public class MySQLDatabaseProvider:IDatabaseProvider
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
|
||||
public MySQLDatabaseProvider(IConfiguration config) => _connectionString = config.GetConnectionString("database");
|
||||
|
||||
public MySQLDatabaseProvider(string connectionString) => _connectionString = connectionString;
|
||||
|
||||
public IDbConnection NewConnection() => new MySqlConnection(_connectionString);
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
namespace Website.Data.States {
|
||||
public class UserState {
|
||||
public string User_Id { get; set; }
|
||||
public string User_Email { get; set; }
|
||||
public string User_Password { get; set; }
|
||||
public string User_Created { get; set; }
|
||||
public string User_Deleted { get; set; }
|
||||
public string Group_Id { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Website.Data.States;
|
||||
using Website.Models;
|
||||
|
||||
namespace Website.Data {
|
||||
public class UserRepository {
|
||||
private readonly IDatabaseProvider _dbProvider;
|
||||
|
||||
public UserRepository(IDatabaseProvider dbProvider) {
|
||||
_dbProvider = dbProvider;
|
||||
}
|
||||
|
||||
public async Task<User> GetUserByEmail(string email) {
|
||||
const string query = "SELECT * FROM users WHERE user_email=@email";
|
||||
|
||||
using (var connection = _dbProvider.NewConnection()) {
|
||||
connection.Open();
|
||||
var result = await connection.QueryAsync<UserState>(query, new {email});
|
||||
return new User(result.Single());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue