//[LoggerOff]
        public IActionResult AuthorizeByPassword(AuthorizeByPasswordRequest request)
        {
            if (ModelState.IsValid)
            {
                SingleResponse <string> response = new SingleResponse <string>();

                byte language  = 1;
                var  loginInfo = new LoginInfo();

                //Օգտագործող
                if (!string.IsNullOrEmpty(request.UserName))
                {
                    loginInfo.UserName = request.UserName;
                }


                //Գաղտնաբառ
                if (!string.IsNullOrEmpty(request.Password))
                {
                    loginInfo.Password = Utils.GetSHA1Hash(request.Password);
                }

                XBS.SourceType sourceType = XBS.SourceType.NotSpecified;
                if (!string.IsNullOrEmpty(Request.Headers["SourceType"]))
                {
                    Enum.TryParse(Request.Headers["SourceType"], out sourceType);
                }

                if (!string.IsNullOrEmpty(Request.Headers["Language"]))
                {
                    byte.TryParse(Request.Headers["Language"], out language);
                }

                if (sourceType == XBS.SourceType.AcbaOnline)
                {
                    loginInfo.PlatformType = PlatformType.OnlineBanking;
                }
                else if (sourceType == XBS.SourceType.MobileBanking)
                {
                    loginInfo.PlatformType = PlatformType.MobileBanking;
                }
                loginInfo.IpAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();

                loginInfo.ForUnlocking = request.ForUnlocking;

                //if (!string.IsNullOrEmpty(Request.HttpContext.Request.Headers["Dev"]))
                //{
                //    loginInfo.AdditionalDetails.Add("OS", Request.HttpContext.Request.Headers["Dev"]);
                //}
                //else
                //{
                //    loginInfo.AdditionalDetails.Add("OS", "0");
                //}

                var aoUserData = _xbSecurity.AuthorizeUserByUserPassword(loginInfo, language, request.HostName);


                if (aoUserData.AuthorizationResult.IsAuthorized)
                {
                    string sessionId = Guid.NewGuid().ToString();
                    _cache.Set(sessionId + "_UserName", loginInfo.UserName);
                    _cache.Set(sessionId + "_LoginResult", aoUserData.AuthorizationResult);

                    if (!string.IsNullOrEmpty(Request.Headers["SourceType"]))
                    {
                        Enum.TryParse(Request.Headers["SourceType"], out sourceType);
                    }
                    _cache.Set(sessionId + "_SourceType", sourceType);
                    response.ResultCode = ResultCodes.normal;
                    response.Result     = sessionId;
                }
                else
                {
                    response.ResultCode  = ResultCodes.validationError;
                    response.Description = aoUserData.AuthorizationResult.DescriptionAM + " " + aoUserData.AuthorizationResult.Description;
                }



                return(ResponseExtensions.ToHttpResponse(response));
            }
            else
            {
                return(ValidationError.GetValidationErrorResponse(ModelState));
            }
        }
Ejemplo n.º 2
0
        public IActionResult SaveAndApproveUserUnlockOrder([FromBody] TokenOperationRequestWithAuthorization request)
        {
            if (ModelState.IsValid)
            {
                SingleResponse <long> response = new SingleResponse <long>()
                {
                    ResultCode = ResultCodes.normal
                };
                XBSecurity.LoginInfo loginInfo = new XBSecurity.LoginInfo()
                {
                    ForUnlocking = true
                };
                byte language = 1;
                //Լեզու
                if (!string.IsNullOrEmpty(Request.Headers["language"]))
                {
                    byte.TryParse(Request.Headers["language"], out language);
                }

                //Օգտագործող
                if (!string.IsNullOrEmpty(request.UserName))
                {
                    loginInfo.UserName = request.UserName;
                }
                else
                {
                    response.ResultCode  = ResultCodes.validationError;
                    response.Description = (Languages)language == Languages.hy ? "Մուտքագրեք ձեր օգտվողի անունը։" : "Please enter your username.";
                }
                //Գաղտնաբառ
                if (!string.IsNullOrEmpty(request.Password))
                {
                    loginInfo.Password = utils.GetSHA1Hash(request.Password);
                }
                else
                {
                    response.ResultCode  = ResultCodes.validationError;
                    response.Description = (Languages)language == Languages.hy ? "Մուտքագրեք ձեր գաղտնաբառը։" : "Please enter your password.";
                }

                if (response.ResultCode == ResultCodes.normal)
                {
                    loginInfo.IpAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();

                    var AuthResponce = _xbSecurity.AuthorizeUserByUserPassword(loginInfo, language);

                    if (AuthResponce.AuthorizationResult.IsAuthorized)
                    {
                        if (AuthResponce.AuthorizationResult.ResultCode == XBSecurity.LoginResultCode.ChangePassword)
                        {
                            response.ResultCode  = ResultCodes.validationError;
                            response.Description = $"{(!string.IsNullOrEmpty(AuthResponce.AuthorizationResult.DescriptionAM) ? AuthResponce.AuthorizationResult.DescriptionAM + " " : "")}{AuthResponce.AuthorizationResult.Description}";
                            return(ResponseExtensions.ToHttpResponse(response));
                        }
                        HBUser hbUser = new HBUser();
                        _xBService.Use(client =>
                        {
                            hbUser = client.GetHBUserByUserNameAsync(request.UserName).Result;
                        });
                        AuthorizeAnonymousMethods(hbUser.CustomerNumber, AuthResponce.AuthorizationResult.SessionID.ToString(), hbUser.ID, hbUser.UserName);
                        if (Request.Headers.ContainsKey("SessionId"))
                        {
                            Request.Headers.Remove("SessionId");
                        }
                        Request.Headers.Add("SessionId", AuthResponce.AuthorizationResult.SessionID.ToString());
                        HBServletRequestOrder hBServletRequestOrder = new HBServletRequestOrder
                        {
                            RegistrationDate = DateTime.Now,
                            OperationDate    = _xBService.GetCurrentOperDay(),
                            ServletAction    = HBServletAction.UnlockUser,
                            Type             = OrderType.HBServletRequestTokenUnBlockOrder,
                            SubType          = 1,
                            ServletRequest   = new TokenOperationsInfo1(),
                            HBtoken          = new HBToken
                            {
                                HBUser = new HBUser
                                {
                                    UserName = hbUser.UserName,
                                    IsCas    = true
                                }
                            },
                            CustomerNumber = hbUser.CustomerNumber,
                            Source         = SourceType.MobileBanking,
                            FilialCode     = 22000,
                            PhoneNumber    = GetCustomerRegPhone(hbUser.CustomerNumber)
                        };
                        ActionResult saveActionResult = _xBService.SaveAndApproveTokenOrder(hBServletRequestOrder);
                        response.ResultCode = ResultCodeFormatter.FromPersonalAccountSecurityService(saveActionResult.ResultCode);
                        response.Result     = saveActionResult.Id;
                        if (response.ResultCode == ResultCodes.normal)
                        {
                            response.Description = (Languages)language == Languages.hy ? "Օգտագործողը ապաբլոկավորված է:" : "User unblocked";
                        }
                        else
                        {
                            response.Description = utils.GetActionResultErrors(saveActionResult.Errors);
                        }
                        return(ResponseExtensions.ToHttpResponse(response));
                    }
                    else
                    {
                        response.ResultCode  = ResultCodes.notAuthorized;
                        response.Description = $"{(!string.IsNullOrEmpty(AuthResponce.AuthorizationResult.DescriptionAM) ? AuthResponce.AuthorizationResult.DescriptionAM + " " : "")}{AuthResponce.AuthorizationResult.Description}";
                    }
                }
                return(ResponseExtensions.ToHttpResponse(response));
            }
            else
            {
                return(ValidationError.GetValidationErrorResponse(ModelState));
            }
        }