Esempio n. 1
0
        public async Task <IHttpActionResult> PostSession(string login, [FromBody] string password, bool force = false)
        {
            try
            {
                var decodedLogin    = SystemEncryptions.Decode(login);
                var decodedPassword = SystemEncryptions.Decode(password);
                var user            = await _authenticationRepository.AuthenticateUserAsync(decodedLogin, decodedPassword, false);

                return(await RequestSessionTokenAsync(user, force));
            }
            catch (AuthenticationException ex)
            {
                await _log.LogInformation(WebApiConfig.LogSourceSessions, ex.Message);

                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.CreateHttpError()));
            }
            catch (ApplicationException ex)
            {
                await _log.LogInformation(WebApiConfig.LogSourceSessions, ex.Message);

                return(Conflict());
            }
            catch (ArgumentNullException ex)
            {
                await _log.LogInformation(WebApiConfig.LogSourceSessions, ex.Message);

                return(BadRequest());
            }
            catch (FormatException ex)
            {
                await _log.LogInformation(WebApiConfig.LogSourceSessions, ex.Message);

                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.Message));
            }
            catch (Exception ex)
            {
                await _log.LogError(WebApiConfig.LogSourceSessions, ex);

                return(InternalServerError());
            }
        }
Esempio n. 2
0
        public async Task AuthenticateUserAsync_DatabaseUser_EmptyLogin_InvalidCredentialException()
        {
            // Arrange

            // Act
            await _authenticationRepository.AuthenticateUserAsync("", Password, false);

            // Assert
            // Exception
        }