コード例 #1
0
        public IHttpActionResult Login(Credentials credentials)
        {
            if (string.IsNullOrEmpty(credentials.Password) || string.IsNullOrEmpty(credentials.Username))
            {
                return(Unauthorized(new AuthenticationHeaderValue(AuthenticationFault.InvalidCredentials.ToString())));
            }

            var authenticationResult = _customerServiceGateway.AuthenticateUser(credentials.Username, credentials.Password);

            if (authenticationResult.Success)
            {
                _authenticationContext.SetAuthenticationCookie(credentials.Username, authenticationResult.Result.Key.CustomerId);

                return(Ok(RestResult <string> .CreateSuccess(string.Empty)));
            }

            AuthenticationFault authenticationFailure = authenticationResult.FaultCode.Value;

            if (authenticationFailure == AuthenticationFault.LogonAttemptsExceeded)
            {
                return(Unauthorized(new AuthenticationHeaderValue(authenticationFailure.ToString())));
            }

            if (authenticationFailure == AuthenticationFault.AccountLocked)
            {
                return(Unauthorized(new AuthenticationHeaderValue(authenticationFailure.ToString())));
            }

            return(Unauthorized(new AuthenticationHeaderValue(AuthenticationFault.InvalidCredentials.ToString())));
        }
コード例 #2
0
        public void SetRealSession(string name)
        {
            try
            {
                throw new NullReferenceException("Session is null");
            }
            catch (NullReferenceException)
            {
                AuthenticationFault authenticationFault = new AuthenticationFault
                {
                    Reason  = "Exception accessing session",
                    Message = "This is test message"
                };

                throw new FaultException <AuthenticationFault>(authenticationFault);
            }
        }