public SimpleAjaxResult Save() { try { Name = Name ?? ""; var serialNo = SerialNoHelper.Create(); var user = MembershipService.GetUserByName(Name); if (user == null) { Logger.Error(LogTypes.RecoveryPassword, "用户名 " + Name + " 不存在或电子邮件错!"); return(new SimpleAjaxResult("用户名 " + Name + " 不存在或电子邮件错!")); } if (string.IsNullOrEmpty(user.Email)) { Logger.Error(LogTypes.RecoveryPassword, "用户名 " + Name + " 不存在或电子邮件错!"); return(new SimpleAjaxResult("用户名 " + Name + " 不存在或电子邮件错!")); } var items = TemporaryTokenKeyService.QueryByUser(TokenKeyTypes.RecoveryPassword, user.Name).ToList(); foreach (var item in items) { TemporaryTokenKeyService.Delete(item); } Logger.LogWithSerialNo(LogTypes.RecoveryPassword, serialNo, user.UserId, user.Name); TemporaryTokenKey key = new TemporaryTokenKey { ExpiredDate = DateTime.Now.Date.AddDays(7), TokenKeyType = TokenKeyTypes.RecoveryPassword, UserName = user.Name, Token = Guid.NewGuid().ToString() }; TemporaryTokenKeyService.Create(key); var context = new Dictionary <string, string> { { "userName", user.Name }, { "userDisplayName", user.DisplayName }, { "token", key.Token }, }; EmailService.SendMail("recoveryPassword", user.Email, "重置密码申请", context); return(new SimpleAjaxResult()); } catch (Exception ex) { Logger.Error(LogTypes.RecoveryPassword, ex); return(new SimpleAjaxResult("重置密码失败: " + ex.Message)); } }
public void Delete(TemporaryTokenKey item) { _databaseInstance.Delete(item, TableName); }
public void Create(TemporaryTokenKey item) { item.TemporaryTokenKeyId = _databaseInstance.Insert(item, TableName); }