示例#1
0
        public async Task <string> SendCheckEmailCode(SendEmailCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                string resultmessage = "";
                foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)))
                {
                    resultmessage += error + Environment.NewLine;
                }
                return(new ResponesResult(false, resultmessage).ToString());
            }
            var account = await new AccountComponent().GetAccountByIdAsync(AccountInfo.Id);

            if (!account.Email.Equals(model.Email, StringComparison.CurrentCultureIgnoreCase))
            {
                return(new ResponesResult(false, AccountResetEmail.EmailNotMatch).ToString());
            }
            var code = SecurityVerify.SendCode <ResetEmailOldVerification>(account.Email.Replace("@", "_"), account.Email);

            if (string.IsNullOrEmpty(code))//一分钟内发送过
            {
                return(new ResponesResult(false, GeneralResource.OptionTooFrequent).ToString());
            }
            var subject = AccountResetEmail.EmailSubject;
            var content = string.Format(AccountResetEmail.OriginalEmailContent, code);

            await new EmailAgent().SendAsync(model.Email, subject, content);
            return(new ResponesResult(true).ToString());
        }
示例#2
0
        public async Task <string> SendFirstSettingEmailCode(SendEmailCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                string resultmessage = "";
                foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)))
                {
                    resultmessage += error + Environment.NewLine;
                }
                return(new ResponesResult(false, resultmessage).ToString());
            }
            if (await new AccountComponent().CheckEmailBind(AccountInfo.Id, model.Email))
            {
                return(new ResponesResult(false, AccountFirstSetting.EmailBindByOtherAccount).ToString());
            }
            var code = SecurityVerify.SendCode <FirstSettingEmailVerification>(model.Email.Replace("@", "_"), model.Email);

            if (string.IsNullOrEmpty(code))//一分钟内发送过
            {
                return(new ResponesResult(false, GeneralResource.OptionTooFrequent).ToString());
            }
            var subject = AccountFirstSetting.EmailSubject;
            var content = string.Format(AccountFirstSetting.EmailContent, code);

            await new EmailAgent().SendAsync(model.Email, subject, content);
            return(new ResponesResult(true).ToString());
        }