37 lines
974 B
C#
37 lines
974 B
C#
using OFBButte.Application.Database;
|
|
using OFBButte.Entities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace OFBButte.Application.Users
|
|
{
|
|
public class LoginUser
|
|
{
|
|
private readonly IOFBContext context;
|
|
private readonly IPasswordHasher hasher;
|
|
public LoginUser(IOFBContext context, IPasswordHasher hasher)
|
|
{
|
|
this.context = context;
|
|
this.hasher = hasher;
|
|
}
|
|
public User Handle(string email, string password)
|
|
{
|
|
var user = context.Users.FirstOrDefault(u => u.Email == email);
|
|
if (user == null)
|
|
throw new Exception("Could not find email: " + email);
|
|
|
|
var validPassword = hasher.VerifyPassword(user.Password, password);
|
|
|
|
if (validPassword)
|
|
{
|
|
return user;
|
|
} else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|