Ejemplo n.º 1
0
        public BaseResponse <bool> AddUser(AddUserParameter parameter)
        {
            BaseResponse <bool> response = new BaseResponse <bool>();

            try
            {
                #region 输入合法性验证
                if (string.IsNullOrEmpty(parameter.UserToken))
                {
                    response.IsSuccessful = false;
                    response.Reason       = "账户ID不能为空";
                    return(response);
                }

                if (string.IsNullOrEmpty(parameter.PWD))
                {
                    response.IsSuccessful = false;
                    response.Reason       = "账户密码不能为空";
                    return(response);
                }
                if (parameter.PWD.Length < 6)
                {
                    response.IsSuccessful = false;
                    response.Reason       = "密码长度至少是6位";
                    return(response);
                }

                var isExisted = hbUserReosiory.GetDatas <HBUser>(t => !t.IsDeleted && !string.IsNullOrEmpty(t.UserToken) && t.UserToken.Equals(parameter.UserToken), true).Any();
                if (isExisted)
                {
                    response.IsSuccessful = false;
                    response.Reason       = "账户已存在";
                    return(response);
                }
                #endregion

                HBUser user = new HBUser();
                user.UserToken        = parameter.UserToken;
                user.PWD              = MD5Helper.MD5Encrypt64(Utilitys.DecodeBase64("UTF-8", parameter.PWD));//密码MD5加密
                user.RoleID           = parameter.RoleID;
                user.OrganizationID   = parameter.OrganizationID;
                user.AddUserID        = parameter.AddUserID;
                user.LastUpdateDate   = DateTime.Now;
                user.LastUpdateUserID = parameter.AddUserID;
                user.UseStatus        = true;

                OperationResult operationResult = hbUserReosiory.AddNew <HBUser>(user);
                if (operationResult.ResultType != EnumOperationResultType.Success)
                {
                    throw new Exception("添加用户异常");
                }

                return(response);
            }
            catch (Exception e)
            {
                response.IsSuccessful = false;
                return(response);
            }
        }
        public BaseResponse <bool> AddUser(AddUserParameter parameter)
        {
            BaseResponse <bool> response = new BaseResponse <bool>();

            try
            {
                HBUser user = new HBUser();
                user.UserToken      = parameter.UserToken;
                user.PWD            = parameter.PWD;
                user.RoleID         = parameter.RoleID;
                user.OrganizationID = parameter.OrganizationID;
                user.AddUserID      = parameter.AddUserID;
                user.LastUpdateDate = DateTime.Now;
                user.LastUpdateID   = parameter.AddUserID;

                OperationResult operationResult = hbUserReosiory.AddNew <HBUser>(user);
                if (operationResult.ResultType != EnumOperationResultType.Success)
                {
                    throw new Exception("添加用户异常");
                }

                return(response);
            }
            catch (Exception e)
            {
                response.IsSuccessful = false;
                return(response);
            }
            throw new NotImplementedException();
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new HBUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var defaultRole = "User";

                    await UserManager.AddToRoleAsync(user.Id, defaultRole);

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);



                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 4
0
#pragma warning disable IDE0060 // Remove unused parameter
        public async Task <IActionResult> GetCustomerActiveTokens([FromBody] TokenOperationRequest request)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            SingleResponse <CustomerTokenResponse> response = new SingleResponse <CustomerTokenResponse>()
            {
                ResultCode = ResultCodes.normal
            };
            byte language = 1;

            if (!string.IsNullOrEmpty(Request.Headers["language"]))
            {
                byte.TryParse(Request.Headers["language"], out language);
            }
            AuthorizedCustomer     authorizedCustomer = _cacheHelper.GetAuthorizedCustomer();
            List <HBToken>         hBTokens           = new List <HBToken>();
            HBUser                 hBUser             = new HBUser();
            Task <List <HBToken> > hBTokensTask       = null;
            Task <HBUser>          hBUserTask         = null;

            _xBService.Use(client =>
            {
                hBTokensTask = client.GetFilteredHBTokensAsync(authorizedCustomer.UserId, HBTokenQuality.Active);
            });
            _xBService.Use(client =>
            {
                hBUserTask = client.GetHBUserAsync(authorizedCustomer.UserId);
            });
            hBUser   = await hBUserTask;
            hBTokens = await hBTokensTask;
            if ((hBTokens?.Count ?? 0) == 0)
            {
                response.ResultCode  = ResultCodes.validationError;
                response.Description = (Languages)language == Languages.hy ? "Փոխարինման հայտը հնարավոր չէ ուղարկել: Խնդրում ենք դիմել Բանկ:" : "Can't send replacement request. Please contact the Bank.";
                return(ResponseExtensions.ToHttpResponse(response));
            }
            response.Result = new CustomerTokenResponse
            {
                IsNewHbUser = hBUser.IsCas,
                Tokens      = new List <CustomerToken>()
            };
            foreach (var token in hBTokens)
            {
                response.Result.Tokens.Add(new CustomerToken
                {
                    TokenSerial           = token.TokenNumber,
                    DeviceTypeDescription = token.DeviceTypeDescription
                });
            }
            return(ResponseExtensions.ToHttpResponse(response));
        }
Ejemplo n.º 5
0
        public async Task <JsonResult> Action(UserActionModel model)
        {
            JsonResult json = new JsonResult();

            IdentityResult result = null;

            if (!string.IsNullOrEmpty(model.ID)) //we are trying to edit a record
            {
                var user = await UserManager.FindByIdAsync(model.ID);

                user.FullName = model.FullName;
                user.Email    = model.Email;
                user.UserName = model.Username;
                user.Country  = model.Country;
                user.City     = model.City;
                user.Address  = model.Address;



                result = await UserManager.UpdateAsync(user);
            }
            else //we are trying to create a record
            {
                var user = new HBUser();

                user.FullName = model.FullName;
                user.Email    = model.Email;
                user.UserName = model.Username;
                user.Country  = model.Country;
                user.City     = model.City;
                user.Address  = model.Address;

                result = await UserManager.CreateAsync(user);
            }

            json.Data = new { Success = result.Succeeded, Message = string.Join(", ", result.Errors) };

            return(json);
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new HBUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Ejemplo n.º 7
0
        public IActionResult VerifyUserAndSendOtpSms([FromBody] VerifyUserAndSendOtpSmsRequest request)
        {
            if (ModelState.IsValid)
            {
                SingleResponse <string> response = new SingleResponse <string>()
                {
                    ResultCode = ResultCodes.normal
                };
                XBSecurity.LoginInfo loginInfo = new XBSecurity.LoginInfo();
                byte       language            = 1;
                SourceType sourceType          = SourceType.MobileBanking;
                //Լեզու
                if (!string.IsNullOrEmpty(Request.Headers["language"]))
                {
                    byte.TryParse(Request.Headers["language"], out language);
                }

                //Տվյալների մուտքագրման աղբյուր
                if (!string.IsNullOrEmpty(Request.Headers["SourceType"]))
                {
                    Enum.TryParse(Request.Headers["SourceType"], out sourceType);
                }

                //Օգտագործող
                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)
                    {
                        HBUser hBUser = new HBUser();
                        _xBService.Use(client =>
                        {
                            hBUser = client.GetHBUserByUserNameAsync(request.UserName).Result;
                        });
                        // Get Customer Reg Phone
                        string regPhone = GetCustomerRegPhone(hBUser.CustomerNumber);
                        // Generate and Send Otp with sms
                        string otp  = SendVerificationCode(regPhone, hBUser.ID, 5, CustomerRegistrationVerificationSMSTypes.NumbersAndLetters);
                        string guid = Guid.NewGuid().ToString();

                        CustomerTokenInfo customerTokenInfo = new CustomerTokenInfo()
                        {
                            CustomerNumber = hBUser.CustomerNumber,
                            SessionId      = guid,
                            Otp            = otp,
                            PhoneNumber    = regPhone,
                            Email          = hBUser?.Email?.email?.emailAddress,
                            UserId         = hBUser.ID,
                            UserName       = hBUser.UserName,
                            SourceType     = sourceType,
                            Language       = language,
                            Checked        = false
                        };
                        // Save Customer Token Info in cache with guid
                        _cacheHelper.SetCustomerTokenInfo(customerTokenInfo);

                        response.Result = guid;
                    }
                    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));
            }
        }
Ejemplo n.º 8
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));
            }
        }