Ejemplo n.º 1
0
        public HttpResponseMessage PostLogin(LoginDTO loginDto)
        {
            if (loginDto == null)
            {
                return(BadRequest());
            }

            var loginInfo = new { UserId = -1, LoginSuccessful = false };

            try
            {
                var result = AuthenticateUser(loginDto);

                if (result.Failed)
                {
                    return(result.Error);
                }

                var user = result.Value;

                _applicationAuthenticationState.SetAuthenticatedUser(user, loginDto.RememberMe ? AuthenticationScope.Persistent : AuthenticationScope.Session);

                var response = Map <User, UserDTO>(user);
                loginInfo = new { UserId = user.Id, LoginSuccessful = true };
                Logger.Info($"Uservalidation: Successful {loginInfo}");

                return(Created(response));
            }
            catch (Exception e)
            {
                return(LogError(e));
            }
        }
Ejemplo n.º 2
0
        public override void Handle(FlowEvent @event, FlowContext context)
        {
            switch (@event)
            {
            case FlowEvent.UserSeenBefore:
            case FlowEvent.UserHasRoleInOrganization:
            case FlowEvent.RoleAssigned:
            case FlowEvent.UserAutoProvisioned:
                _authenticationState.SetAuthenticatedUser(User, AuthenticationScope.Session);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(@event), @event, null);
            }
        }