예제 #1
0
        public UserBo Login(String username, String password)
        {
            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                var message = new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent("Username or Password is not provided")
                };
                throw new HttpResponseException(message);
            }

            try
            {
                IUserBo userBo = new UserBo();
                IUserBo user   = userBo.ValidateUser(username);

                if (PasswordManager.ValidatePassword(password, user.Password))
                {
                    if (user.IsVerified == Verified)
                    {
                        String token = TokenManager.GetToken();

                        if (userBo.UpdateToken(token, username))
                        {
                            user.Token    = token;
                            user.Password = password;
                            return((UserBo)user);
                        }
                    }

                    else
                    {
                        return((UserBo)user);
                    }
                }
                else
                {
                    var message = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                    {
                        Content = new StringContent("Username or Password is Incorrect")
                    };
                    throw new HttpResponseException(message);
                }
            }
            catch (Exception exception)
            {
                _logger.Error("FRONT LAYER =>> CONTROLLER =>> LOGIN,  METHOD =>> LOGIN, EXCEPTION MESSAGE: " + exception.Message);
                HttpResponseHelper.GetInternalServerErrorResponse(exception);
            }

            return(null);
        }