Пример #1
0
        public CustomerExternalLogin AddExternalLogin(CustomerExternalLoginAddCommand command)
        {
            if (ExternalLogins == null)
            {
                ExternalLogins = new List <CustomerExternalLogin>();
            }
            if (ExternalLogins.Any(
                    p => p.LoginProvider == command.LoginProvider && p.ProviderKey == command.ProviderKey))
            {
                return(null);
            }
            CustomerExternalLogin customerExternalLogin = new CustomerExternalLogin(command.LoginProvider,
                                                                                    command.ProviderKey, command.ProviderDisplayName, command.CustomerId, command.Info);

            ExternalLogins.Add(customerExternalLogin);
            Version = command.Version;
            return(customerExternalLogin);
        }
Пример #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;
            }
        }
Пример #3
0
        public async Task <CommandResult> SendCommand(CustomerExternalLoginAddCommand command)
        {
            CommandResult commandResult = await _commandService.SendAndReceiveResult <CommandResult>(command);

            return(commandResult);
        }
Пример #4
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);
            }
        }