You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ShopNCook/Controllers/ConnectionController.cs

40 lines
1.2 KiB

using Endpoint;
using Models;
namespace ShoopNCook.Controllers
{
public class ConnectionController : LoginController, RegisterController
{
private readonly ConnectionObserver observer;
private readonly IAuthService accounts;
private readonly IUserNotifier notifier;
public ConnectionController(ConnectionObserver observer, IAuthService accounts, IUserNotifier notifier) {
this.observer = observer;
this.accounts = accounts;
this.notifier = notifier;
}
public void Login(string email, string password)
{
Account? acc = accounts.Login(email, password);
if (acc == null)
{
notifier.Error("Email or password invalid.");
return;
}
observer.OnAccountConnected(acc);
}
public void Register(string username, string email, string password)
{
Account? acc = accounts.Register(username, email, password);
if (acc == null)
{
notifier.Error("Invalid credentials.");
return;
}
observer.OnAccountConnected(acc);
}
}
}