public bool UpdateResetPasswordLog(ResetPasswordLog resetPasswordLog) { CTMS_SYS_RESETPASSWORDLOG resetLog = LoadEntityFromModel(resetPasswordLog); bool result = Update(resetLog); return(result); }
/// <summary> /// 发送手机短信验证码(这里模版id需要修改) /// </summary> /// <param name="req">数据报文</param> /// <returns></returns> public static string SendVercode(SMSRequest req) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(SMSRequest)); StringWriter sw = new StringWriter(); xmlSerializer.Serialize(sw, req); string formData = sw.ToString().Replace("utf-16", "utf-8"); string formUrl = "http://111.13.19.27/smsbill/mt"; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Cmd", "mt"); int timestamp = StringExtension.getTimeStamp(DateTime.Now); dic.Add("TS", timestamp.ToString()); string md5String = (formData + timestamp + "5B04B6DE58D5FE0C4A94BDC0B129AB41").ToMd5(); dic.Add("Authorization", md5String); try { string result = HttpHelper.Post(formUrl, dic, formData); ResetPasswordLog resetLog = new ResetPasswordLog(); string id = Guid.NewGuid().ToString(); resetLog.ID = id; resetLog.InputTime = DateTime.Now; return(result); } catch (Exception ex) { throw ex; } }
/// <summary> /// 通过id获取重置记录信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public ResetPasswordLog GetResetPasswordLogByID(string id) { using (EFResetPasswordLogRepository _reset = new EFResetPasswordLogRepository()) { ResetPasswordLog resetPasswordLog = _reset.GetResetPasswordLogByID(id); return(resetPasswordLog); } }
/// <summary> /// 添加重置密码记录信息 /// </summary> /// <param name="resetLog"></param> /// <returns></returns> public bool AddResetPasswordLog(ResetPasswordLog resetLog) { using (EFResetPasswordLogRepository _reset = new EFResetPasswordLogRepository()) { bool result = _reset.AddResetPasswordLog(resetLog); return(result); } }
/// <summary> /// 发送链接给用户重置密码 /// </summary> /// <param name="user"></param> /// <returns></returns> public ActionResult UserResetPwd(UserInfo user) { try { #region 参数检测 if (user.ResetType == 1) { return(Json(new { Status = -9, Data = string.Empty, Msg = "对不起,该功能暂未实现" })); } if (string.IsNullOrEmpty(user.Email)) { return(Json(new { Status = -8, Data = string.Empty, Msg = "参数错误" })); } if (!StringExtension.IsEmail(user.Email)) { return(Json(new { Status = -7, Data = string.Empty, Msg = "参数格式不正确" })); } #endregion #region 保存重置记录 string id = Guid.NewGuid().ToString(); ResetPasswordLog resetLog = new ResetPasswordLog(); resetLog.ID = id; UserInfo u = _service.GetUserByEmail(user.Email); resetLog.UserID = u.UserId; resetLog.InputTime = DateTime.Now; resetLog.ResetType = user.ResetType; resetLog.Status = 0; bool result = _service.AddResetPasswordLog(resetLog); #endregion if (result) { string host = Request.Url.Host; int port = Request.Url.Port; StringExtension.SendMail(user.Email, "重置密码", "请点击以下链接重置密码:<br/>http://" + host + ":" + port + "/User/Login#/Reset/" + id); return(Json(new { Status = 1, Data = string.Empty, Msg = "操作成功" })); } else { return(Json(new { Status = -6, Data = string.Empty, Msg = "操作失败" })); } } catch (Exception ex) { return(Json(new { Status = -99, Data = string.Empty, Msg = ex.Message })); } }
protected CTMS_SYS_RESETPASSWORDLOG LoadEntityFromModel(ResetPasswordLog model) { if (model == null) { return(null); } CTMS_SYS_RESETPASSWORDLOG entity = new CTMS_SYS_RESETPASSWORDLOG(); entity.ID = model.ID; entity.INPUTTIME = (DateTime?)model.InputTime; entity.USERID = model.UserID; entity.RESETTYPE = (decimal?)model.ResetType; entity.USERSTATUS = (decimal?)model.Status; return(entity); }
protected ResetPasswordLog LoadModelFromEntity(CTMS_SYS_RESETPASSWORDLOG entity) { if (entity == null) { return(null); } ResetPasswordLog model = new ResetPasswordLog(); model.ID = entity.ID; model.InputTime = (DateTime)entity.INPUTTIME; model.UserID = entity.USERID; model.ResetType = (int)entity.RESETTYPE; model.Status = (int)entity.USERSTATUS; return(model); }
/// <summary> /// 重置密码 /// </summary> /// <param name="user"></param> /// <returns></returns> public ActionResult ResetUserPassword(UserInfo user) { try { #region 参数检测 if (user == null) { return(Json(new { Status = -9, Data = string.Empty, Msg = "参数错误1" })); } if (string.IsNullOrEmpty(user.LoginPwd)) { return(Json(new { Status = -8, Data = string.Empty, Msg = "参数错误2" })); } if (string.IsNullOrEmpty(user.ConfirmLoginPwd)) { return(Json(new { Status = -7, Data = string.Empty, Msg = "参数错误3" })); } if (string.IsNullOrEmpty(user.ResetToken)) { return(Json(new { Status = -6, Data = string.Empty, Msg = "参数错误4" })); } if (user.LoginPwd.Trim() != user.ConfirmLoginPwd.Trim()) { return(Json(new { Status = -5, Data = string.Empty, Msg = "参数错误5" })); } #endregion #region 获取重置记录并判断后,获取用户记录 ResetPasswordLog resetLog = _service.GetResetPasswordLogByID(user.ResetToken); if (resetLog == null) { return(Json(new { Status = -4, Data = string.Empty, Msg = "参数错误6" })); } TimeSpan ts = DateTime.Now - resetLog.InputTime; if (ts.TotalHours > ResetPasswordTime) { return(Json(new { Status = -3, Data = string.Empty, Msg = "链接已失效,请重新获取" })); } UserInfo u = _service.GetUserInfoByID(resetLog.UserID); if (u == null) { return(Json(new { Status = -2, Data = string.Empty, Msg = "参数错误7" })); } #endregion #region 重置用户密码 string password = user.LoginPwd.ToMd5(); u.LoginPwd = password; bool result = _service.UpdateUserInfo(u); #endregion #region 返回结果 if (result) { #region 更新记录为已使用 resetLog.Status = 1; _service.UpdateResetPasswordLog(resetLog); #endregion return(Json(new { Status = 1, Data = string.Empty, Msg = "操作成功" })); } return(Json(new { Status = -1, Data = string.Empty, Msg = "操作失败" })); #endregion } catch (Exception ex) { return(Json(new { Status = -99, Data = string.Empty, Msg = ex.Message })); } }