private async Task <Response> DoRenewPasswordAsync()
        {
            var cmd = this.Bind <RenewPasswordCmd>();

            var timeNow = DateTime.Now;
            var err     = await _loginValidatableService.CheckRenewPasswordCmdValidatableAsync(CurrentMemberId, cmd, ClientIP, timeNow).ConfigureAwait(false);

            if (!err.IsNullOrWhiteSpace())
            {
                return(PreconditionFailed(err));
            }
            var verificationCode = await _verificationCodeService.GetAvailableCode(CurrentMemberId, cmd.CheckCode, CodeType.RenewPassword).ConfigureAwait(false);

            await _verificationCodeService.UpdateVerificationCodeToDisabledByUsed(verificationCode.Id).ConfigureAwait(false);

            var passwordFormat = EnumHelper.Random(PasswordFormatType.None);
            var passwordSalt   = HashGenerator.Salt();
            var password       = HashGenerator.Encode(cmd.Password, passwordFormat, passwordSalt);
            var accounts       = await _memberService.GetMemberAccountsByMemberIdAsync(CurrentMemberId).ConfigureAwait(false);

            foreach (var item in accounts)
            {
                item.Password       = password;
                item.PasswordSalt   = passwordSalt;
                item.PasswordFormat = passwordFormat;
                await _memberService.UpdateMemberAccountAsync(item).ConfigureAwait(false);
            }
            return(Ok(new { message = $"密码已更新,请重新登录!" }));
        }
Example #2
0
        private async Task <Response> DoRegistAsync()
        {
            var cmd = this.Bind <RegistCmd>();

            var timeNow = DateTime.Now;
            var err     = await _loginValidatableService.CheckRegistCmdValidatableAsync(cmd, ClientIP, timeNow).ConfigureAwait(false);

            if (!err.IsNullOrWhiteSpace())
            {
                return(PreconditionFailed(err));
            }
            var verificationCode = await _verificationCodeService.GetAvailableCode(cmd.MobilePhone, cmd.CheckCode, cmd.CodeType).ConfigureAwait(false);

            await _verificationCodeService.UpdateVerificationCodeToDisabledByUsed(verificationCode.Id).ConfigureAwait(false);

            var entity = cmd.Adapt <MemberInfo>();

            if (entity.Realname.IsNullOrWhiteSpace())
            {
                entity.Realname = "待设定";
            }
            entity.MobilePhone = cmd.MobilePhone;
            entity.Id          = ObjectId.NewId();
            entity.CreatedOn   = timeNow;
            entity.ModifiedOn  = timeNow;
            try
            {
                await _memberService.NewMemberInfoAsync(entity).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                _logger.LogError("LoginModule=regist路由出现后端错误:" + e.Message);
            }
            var passwordFormat = EnumHelper.Random(PasswordFormatType.None);
            var passwordSalt   = HashGenerator.Salt();
            var password       = HashGenerator.Encode(cmd.Password, passwordFormat, passwordSalt);
            await _memberService.NewMemberAccountAsync(new MemberAccount
            {
                Account        = cmd.MobilePhone,
                MemberId       = entity.Id,
                Password       = password,
                PasswordFormat = passwordFormat,
                PasswordSalt   = passwordSalt
            });

            return(Ok(entity));
        }