-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
aaron.allen
authored and
aaron.allen
committed
Nov 15, 2023
1 parent
c093b1f
commit 9ffaea3
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using System.Security.Claims; | ||
|
||
namespace MythicalToyMachine.Data; | ||
|
||
public interface IUserRoleService | ||
{ | ||
// | ||
public bool IsAuthenticated { get; } | ||
public IEnumerable<string> Roles { get; } | ||
public Task LookUpUser(string email, string name, string surname); | ||
public void ResetUser(); | ||
} | ||
|
||
public class UserRoleService : IUserRoleService | ||
{ | ||
public UserRoleService(PostgresContext context) | ||
{ | ||
this.context = context; | ||
} | ||
public bool IsAuthenticated { get; private set; } | ||
|
||
public IEnumerable<string> Roles => roles; | ||
|
||
private PostgresContext context; | ||
|
||
private List<string> roles = new(); | ||
|
||
|
||
public void ResetUser() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public async Task LookUpUser( string email, string name, string surname) | ||
{ | ||
if (email is not null) | ||
{ | ||
string? eCompare = email; | ||
var lCustomer = await context.Customers.FirstOrDefaultAsync(c => c.Useremail == email); | ||
|
||
|
||
|
||
|
||
if (lCustomer is null) | ||
{ | ||
//Make a new Customer | ||
Customer newCustomer = new(); | ||
newCustomer.Surname = surname; | ||
newCustomer.Firstname = name; | ||
newCustomer.Useremail = email; | ||
|
||
//add it to database | ||
context.Customers.Add(newCustomer); | ||
await context.SaveChangesAsync(); | ||
} | ||
//Else, if cEmail is NOT null then the user already exists in the database, so we don't have to add them to the database a second time | ||
IsAuthenticated = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters