Exemple #1
0
        public async Task <VerifyGetResponse> GetVerifyDetail(VerifyGetRequest request)
        {
            VerifyGetResponse response = new VerifyGetResponse();

            try
            {
                if (!string.IsNullOrEmpty(request.Id))
                {
                    RVerify verify = await _emailSmsService.GetVerifyFromDb(request.Id);

                    if (verify == null)
                    {
                        response.SetFail(BaseResponse.ErrorCodeEnum.VerifyNotFound);
                        return(response);
                    }
                    response.Verify = verify.ToModel();
                }
            }
            catch (Exception e)
            {
                response.SetFail(e);
                _logger.LogError(e, e.Message, request);
            }
            return(response);
        }
Exemple #2
0
        public async Task <VerifyExternalLoginWhenAccountIsExistModel> VerifyExternalLoginWhenAccountIsExist(VerifyExternalLoginWhenAccountIsExistModel model)
        {
            try
            {
                var page = await base.InitPage();

                model.SetInitInfo(page);
                RVerify verify = await _emailSmsService.GetVerifyFromDb(model.VerifyId);

                if (verify == null)
                {
                    model.AddMessage(ResourceKey.Verify_NotExist);
                    return(model);
                }
                if (verify.CheckStatus(EnumDefine.VerifyStatusEnum.Used))
                {
                    model.AddMessage(ResourceKey.Verify_Used);
                    return(model);
                }
                if (verify.CheckStatus(EnumDefine.VerifyStatusEnum.Cancel))
                {
                    model.AddMessage(ResourceKey.Verify_Cancel);
                    return(model);
                }
                if (verify.ExpireDate < Extensions.GetCurrentDateUtc())
                {
                    model.AddMessage(ResourceKey.Verify_Expired);
                    return(model);
                }
                RijndaelSimple rijndaelSimple = new RijndaelSimple();
                string         verifyCode;
                try
                {
                    string code = UnicodeUtility.FromHexString(model.VerifyCode);
                    verifyCode = rijndaelSimple.Decrypt(code, verify.SaltKey);
                }
                catch (Exception e)
                {
                    model.AddMessage(ResourceKey.Verify_CodeNotExact);
                    return(model);
                }
                if (verify.VerifyCode != verifyCode)
                {
                    model.AddMessage(ResourceKey.Verify_CodeNotExact);
                    return(model);
                }
                ActiveCodeWhenAccountIsExistModel activeCodeWhenAccountIsExistModel =
                    verify.GetModel <ActiveCodeWhenAccountIsExistModel>();
                var customer = await _customerService.GetFromDb(activeCodeWhenAccountIsExistModel.CustomerId);

                CustomerExternalLoginAddCommand command = new CustomerExternalLoginAddCommand()
                {
                    LoginProvider       = activeCodeWhenAccountIsExistModel.LoginProvider,
                    ProviderKey         = activeCodeWhenAccountIsExistModel.ProviderKey,
                    ProviderDisplayName = activeCodeWhenAccountIsExistModel.LoginProvider.ToString(),
                    CustomerId          = activeCodeWhenAccountIsExistModel.CustomerId,
                    Info     = activeCodeWhenAccountIsExistModel.Info,
                    VerifyId = verify.Id,
                    Version  = customer.Version
                };
                var result = await _customerService.SendCommand(command);

                if (!result.IsSucess)
                {
                    model.AddMessage(result.Message);
                }
                return(model);
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                throw e;
            }
        }
Exemple #3
0
        public async Task <ICommandResult> Handle(CustomerExternalLoginAddCommand mesage)
        {
            try
            {
                ICommandResult result;
                RCustomer      customerFromDb = await _customerService.GetFromDb(mesage.CustomerId);

                if (customerFromDb == null)
                {
                    result = new CommandResult()
                    {
                        Message      = "",
                        ObjectId     = "",
                        Status       = CommandResult.StatusEnum.Fail,
                        ResourceName = ResourceKey.Customer_NotExist
                    };
                    return(result);
                }
                customerFromDb.CustomerExternalLogins = await _customerService.GetCustomerExternalLoginByCustomerId(customerFromDb.Id);

                Customer customer = new Customer(customerFromDb);
                CustomerExternalLogin customerExternalLogin = customer.AddExternalLogin(mesage);
                if (customerExternalLogin != null)
                {
                    await _customerService.Change(customer, customerExternalLogin);
                }
                if (!string.IsNullOrEmpty(mesage.VerifyId))
                {
                    RVerify rverify = await _emailSmsService.GetVerifyFromDb(mesage.VerifyId);

                    if (rverify != null)
                    {
                        Verify verify = new Verify(rverify);
                        verify.ChangeStatusToVerified();
                        await _emailSmsService.ChangeVerifyStatus(verify.Id, verify.Status);
                    }
                }
                result = new CommandResult()
                {
                    Message  = "",
                    ObjectId = customer.Id,
                    Status   = CommandResult.StatusEnum.Sucess
                };
                return(result);
            }
            catch (MessageException e)
            {
                e.Data["Param"] = mesage;
                ICommandResult result = new CommandResult()
                {
                    Message      = e.Message,
                    Status       = CommandResult.StatusEnum.Fail,
                    ResourceName = e.ResourceName
                };
                return(result);
            }
            catch (Exception e)
            {
                e.Data["Param"] = mesage;
                ICommandResult result = new CommandResult()
                {
                    Message = e.Message,
                    Status  = CommandResult.StatusEnum.Fail
                };
                return(result);
            }
        }