public async Task <IActionResult> Register([FromBody] AuthModels.Register register) { // check passwords if (register.Password != register.ConfirmPassword) { return(ErrorResponse("Passwords not matched.")); } // define user var newuser = new core.Domain.User { Username = register.Username, Password = register.Password, FirstName = register.FirstName, LastName = register.LastName }; // register user var res = await Authservice.Register(newuser); if (res.Success) { return(SuccessResponse("/")); } // return error return(ErrorResponse(res.Errors)); }
// logout public async Task <IActionResult> Logout() { if (await CheckAccess()) { Authservice.Logout(GetCurrentUser()); } // clear auth cookies RemoveAuth(); return(Redirect("/")); }
public async Task <IActionResult> Login([FromBody] AuthModels.Login login) { // login var res = await Authservice.Login(login.Username, login.Password); if (res.Success) { // set auth key for session SetAuth(res.UserId, res.AuthKey); // return to listing screen on login return(SuccessResponse("/employee/listing")); } // return error return(ErrorResponse(res.Errors)); }
public APIControllerAuthservice(DatabaseContext context) { _authservice = Authservice.getInstance(context); }