/// <summary>
        ///
        /// </summary>
        /// <param name="registerInfo"></param>
        /// <returns></returns>
        public async Task <long> RegisterPassport(DTOAPI_RegisterByPassport registerInfo)
        {
            if (!AccountValidator.bValidPassport(registerInfo.passport))
            {
                throw new Exception("用户名格式不正确");
            }

            if (!AccountValidator.bValidPassword(registerInfo.password))
            {
                throw new Exception("密码格式错误");
            }

            var account = this.accesser.Get(passport: registerInfo.passport).Item1;

            if (account != null)
            {
                throw new Exception("用户名已存在");
            }


            long newId = this.IDGenerator.GetNewID <Account>();

            await this.publishEndpoint.Publish(new RegisterAccountByPassportCommand
            {
                id       = newId,
                passport = registerInfo.passport,
                password = registerInfo.password
            });


            return(newId);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="registerInfo"></param>
        /// <returns></returns>
        public async Task <long> RegisterByEmailVerifyCode(DTOAPI_RegisterByEmailVerifyCode registerInfo)
        {
            if (!EmailHepler.IsValid(registerInfo.email))
            {
                throw new Exception("邮箱格式不正确");
            }

            if (!AccountValidator.bValidPassword(registerInfo.pwd))
            {
                throw new Exception("密码格式错误");
            }

            string key_captcha = $"RegisterCaptcha_{registerInfo.email.ToLower()}";
            string captcha     = this.captchaHelper.GetCaptcha(key_captcha);

            if (String.IsNullOrEmpty(captcha) ||
                !String.Equals(captcha, registerInfo.verifyCode, StringComparison.CurrentCultureIgnoreCase))
            {
                throw new Exception("验证码错误");
            }

            var account = this.accesser.Get(email: registerInfo.email).Item1;

            if (account != null)
            {
                throw new Exception("用户已存在");
            }

            var newId = this.IDGenerator.GetNewID <Account>();

            await this.publishEndpoint.Publish(new RegisterAccountByEmailCommand
            {
                id       = newId,
                email    = registerInfo.email.ToLower(),
                password = registerInfo.pwd
            });

            await this.publishEndpoint.Publish(new DeleteAccountCaptchaCommand
            {
                key = key_captcha
            });

            return(newId);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pwdInfo"></param>
        /// <returns></returns>
        public async Task ForgotPwdCodeByEmail(DTOAPI_ForgotPwdByEmailCaptcha pwdInfo)
        {
            if (!EmailHepler.IsValid(pwdInfo.email))
            {
                throw new Exception("邮箱格式不正确");
            }

            if (!AccountValidator.bValidPassword(pwdInfo.newpwd))
            {
                throw new Exception("密码格式不正确");
            }

            var account = this.accesser.Get(email: pwdInfo.email).Item1;

            if (account == null)
            {
                throw new Exception("用户不存在");
            }

            string key_captcha = $"ForgotPwdCaptcha_{pwdInfo.email.ToLower()}";

            if (!this.captchaHelper.GetCaptcha(key_captcha).Equals(pwdInfo.verifyCode, StringComparison.CurrentCultureIgnoreCase))
            {
                throw new Exception("验证码错误");
            }

            await this.publishEndpoint.Publish(new ChangePasswordCommand
            {
                key         = account.Id,
                newPassword = pwdInfo.newpwd
            });

            await this.publishEndpoint.Publish(new DeleteAccountCaptchaCommand
            {
                key = key_captcha
            });
        }