private void SendEmailIfSubmit(int id) { User user = userService.GetUserById(id); string subject = $"博客园博客申请通知-{user.DisplayName}"; string message = "<p>抱歉!您的博客没有被批准。</p>"; emailUtil.Send(user.Email, subject, message); }
public void Register(RegisterViewModel registerViewModel, string publicKeyJson, string privateKeyJson, string host) { User user = new User(); user.Email = registerViewModel.Email; user.UserName = registerViewModel.UserName; user.DisplayName = registerViewModel.DisplayName; user.Password = registerViewModel.Password; user.CreateTime = DateTime.Now; user.LastModifiedTime = DateTime.Now; user.LastLoginTime = DateTime.Now; user.LoginTimes = 0; user.IsActivate = false; userRepository.Insert(user); User gotUser = userRepository.SelectByUserName(registerViewModel.UserName); // 生成验证码 dataProtectorUtil.PublicKeyJson = publicKeyJson; // 生成激活码,激活码由UserName字段和Password字段合并加密而成 var code = dataProtectorUtil.EncryptString(gotUser.UserName + gotUser.Password); // 解决get不能传“+”的问题 code = code.Replace("+", "_"); // 发送验证邮件并记录 var subject = $"博客园帐户激活邮件-{gotUser.DisplayName}"; var message = new StringBuilder(); message.Append("<div>您好!<br/><br/>"); message.Append("感谢您在博客园注册账号!<br/><br/>"); message.Append("账户需要激活才能使用,赶紧激活成为博客园正式的一员吧:"); message.Append("点击下面的链接立即激活账户(或将网址复制到浏览器中打开):<br/><br/>"); message.Append($"<a href='http://{host}/User/ActivateUser?code={code}&email={gotUser.Email}'>"); message.Append($"http://{host}/User/ActivateUser?code={code}&email={gotUser.Email}"); message.Append("</a></div>"); emailUtil.Send(gotUser.Email, subject, message.ToString()); emailRepository.Insert(new Email() { UserId = gotUser.Id, CreateTime = DateTime.Now, PublicKeyJson = publicKeyJson, PrivateKeyJson = privateKeyJson, ActionType = 0 // 0,表示邮件用于注册 }); }