Switched to database scheme seperation from MoonCores SingleDb. Updated mooncore versions. Updating to correct Async naming
This commit is contained in:
@@ -45,29 +45,29 @@ public class LocalAuthController : Controller
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("login")]
|
||||
public async Task<IResult> Login()
|
||||
public async Task<ActionResult> LoginAsync()
|
||||
{
|
||||
var html = await ComponentHelper.RenderComponent<Login>(ServiceProvider);
|
||||
var html = await ComponentHelper.RenderToHtmlAsync<Login>(ServiceProvider);
|
||||
|
||||
return Results.Content(html, "text/html");
|
||||
return Content(html, "text/html");
|
||||
}
|
||||
|
||||
[HttpGet("register")]
|
||||
public async Task<IResult> Register()
|
||||
public async Task<ActionResult> RegisterAsync()
|
||||
{
|
||||
var html = await ComponentHelper.RenderComponent<Register>(ServiceProvider);
|
||||
var html = await ComponentHelper.RenderToHtmlAsync<Register>(ServiceProvider);
|
||||
|
||||
return Results.Content(html, "text/html");
|
||||
return Content(html, "text/html");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[HttpPost("login")]
|
||||
public async Task<IResult> Login([FromForm] string email, [FromForm] string password)
|
||||
public async Task<ActionResult> LoginAsync([FromForm] string email, [FromForm] string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Perform login
|
||||
var user = await InternalLogin(email, password);
|
||||
var user = await InternalLoginAsync(email, password);
|
||||
|
||||
// Login user
|
||||
var options = Options.Get(LocalAuthConstants.AuthenticationScheme);
|
||||
@@ -84,34 +84,34 @@ public class LocalAuthController : Controller
|
||||
), new AuthenticationProperties());
|
||||
|
||||
// Redirect back to wasm app
|
||||
return Results.Redirect("/");
|
||||
return Redirect("/");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string errorMessage;
|
||||
|
||||
if (e is HttpApiException apiException)
|
||||
errorMessage = apiException.Title;
|
||||
if (e is AggregateException aggregateException)
|
||||
errorMessage = aggregateException.Message;
|
||||
else
|
||||
{
|
||||
errorMessage = "An internal error occured";
|
||||
Logger.LogError(e, "An unhandled error occured while logging in user");
|
||||
}
|
||||
|
||||
var html = await ComponentHelper.RenderComponent<Login>(ServiceProvider,
|
||||
var html = await ComponentHelper.RenderToHtmlAsync<Login>(ServiceProvider,
|
||||
parameters => { parameters["ErrorMessage"] = errorMessage; });
|
||||
|
||||
return Results.Content(html, "text/html");
|
||||
return Content(html, "text/html");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("register")]
|
||||
public async Task<IResult> Register([FromForm] string email, [FromForm] string password, [FromForm] string username)
|
||||
public async Task<ActionResult> RegisterAsync([FromForm] string email, [FromForm] string password, [FromForm] string username)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Perform register
|
||||
var user = await InternalRegister(username, email, password);
|
||||
var user = await InternalRegisterAsync(username, email, password);
|
||||
|
||||
// Login user
|
||||
var options = Options.Get(LocalAuthConstants.AuthenticationScheme);
|
||||
@@ -128,37 +128,37 @@ public class LocalAuthController : Controller
|
||||
), new AuthenticationProperties());
|
||||
|
||||
// Redirect back to wasm app
|
||||
return Results.Redirect("/");
|
||||
return Redirect("/");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string errorMessage;
|
||||
|
||||
if (e is HttpApiException apiException)
|
||||
errorMessage = apiException.Title;
|
||||
if (e is AggregateException aggregateException)
|
||||
errorMessage = aggregateException.Message;
|
||||
else
|
||||
{
|
||||
errorMessage = "An internal error occured";
|
||||
Logger.LogError(e, "An unhandled error occured while logging in user");
|
||||
}
|
||||
|
||||
var html = await ComponentHelper.RenderComponent<Register>(ServiceProvider,
|
||||
var html = await ComponentHelper.RenderToHtmlAsync<Register>(ServiceProvider,
|
||||
parameters => { parameters["ErrorMessage"] = errorMessage; });
|
||||
|
||||
return Results.Content(html, "text/html");
|
||||
return Content(html, "text/html");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<User> InternalRegister(string username, string email, string password)
|
||||
private async Task<User> InternalRegisterAsync(string username, string email, string password)
|
||||
{
|
||||
email = email.ToLower();
|
||||
username = username.ToLower();
|
||||
|
||||
if (await UserRepository.Get().AnyAsync(x => x.Username == username))
|
||||
throw new HttpApiException("A account with that username already exists", 400);
|
||||
throw new AggregateException("A account with that username already exists");
|
||||
|
||||
if (await UserRepository.Get().AnyAsync(x => x.Email == email))
|
||||
throw new HttpApiException("A account with that email already exists", 400);
|
||||
throw new AggregateException("A account with that email already exists");
|
||||
|
||||
string[] permissions = [];
|
||||
|
||||
@@ -185,7 +185,7 @@ public class LocalAuthController : Controller
|
||||
return finalUser;
|
||||
}
|
||||
|
||||
private async Task<User> InternalLogin(string email, string password)
|
||||
private async Task<User> InternalLoginAsync(string email, string password)
|
||||
{
|
||||
email = email.ToLower();
|
||||
|
||||
@@ -194,10 +194,10 @@ public class LocalAuthController : Controller
|
||||
.FirstOrDefaultAsync(x => x.Email == email);
|
||||
|
||||
if (user == null)
|
||||
throw new HttpApiException("Invalid combination of email and password", 400);
|
||||
throw new AggregateException("Invalid combination of email and password");
|
||||
|
||||
if (!HashHelper.Verify(password, user.Password))
|
||||
throw new HttpApiException("Invalid combination of email and password", 400);
|
||||
throw new AggregateException("Invalid combination of email and password");
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user