示例#1
0
        public IActionResult Login([FromForm] LoginRequest?request)
        {
            try {
                ValidateNotNull(request?.Name, request?.Password);

                var(jwt, permissions) = _unitOfWork.WithAuthUserTransaction(tran => {
                    var jwt         = _authService.GenerateJwt(request !.Name, request.Password);
                    var permissions = _authService.PermissionsForJwt(jwt);

                    return(tran.CommitWith((jwt, permissions)));
                });
                AuthContext authContext = AuthContext.AttachToHttpContext(jwt, permissions, HttpContext);

                return(Redirect("/"));
            }
            catch (ManualValidationException) {
                return(ErrorView("password", "Incorrect username or password."));
            }
        }