Ejemplo n.º 1
0
        public async Task <IActionResult> SignIn(string email, string passwordHash)
        {
            var result = await taskExecutor.Execute(async() =>
            {
                var authenticationResult = await authenticateUserCommand.Execute(email, passwordHash);

                var now = DateTime.UtcNow;
                var jwt = new JwtSecurityToken(
                    issuer: AuthOptions.ISSUER,
                    audience: AuthOptions.AUDIENCE,
                    notBefore: now,
                    claims: authenticationResult.UserIdentity.Claims,
                    expires: now.Add(TimeSpan.FromMinutes(AuthOptions.LIFETIME)),
                    signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256));
                var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);

                return(new Models.SignInResult
                {
                    UserId = authenticationResult.UserId,
                    Name = authenticationResult.Name,
                    DepartmentId = authenticationResult.DepartmentId,
                    DepartmentName = authenticationResult.DepartmentName,
                    Email = authenticationResult.Email,
                    Token = encodedJwt
                });
            });

            if (result.ErrorMessage == null)
            {
                return(Json(result.Result));
            }

            return(BadRequest(result.ErrorMessage));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetNotifications()
        {
            var result = await taskExecutor.Execute(async() =>
            {
                return(await getNotificationsQuery.Execute());
            });

            if (result.ErrorMessage == null)
            {
                return(Json(result.Result));
            }

            return(BadRequest(result.ErrorMessage));
        }