public void StepTwo() { // 0、验证码 Html.Captcha.CheckError(ctx); // 1、得到email地址和相应的用户 String email = ctx.Post("Email"); if (strUtil.IsNullOrEmpty(email)) { errors.Add(lang("exEmail")); } else if (new Regex(RegPattern.Email).IsMatch(email) == false) { errors.Add(lang("exEmailFormat")); } if (ctx.HasErrors) { showError(); return; } User user = userService.GetByMail(email); if (user == null) { errors.Add(lang("exUserNotFoundByEmail")); showError(); return; } ctx.SetItem("User", user); // 2、产生唯一code并加入数据库 UserResetPwd userReset = new UserResetPwd(); userReset.User = user; userReset.Code = Guid.NewGuid().ToString().Replace("-", "").ToLower(); userReset.Ip = ctx.Ip; String resetLink = getResetLink(userReset); ctx.SetItem("ResetLink", resetLink); // 3、给此email发送一封重置pwd的邮件 MailClient mail = MailClient.Init(); String title = string.Format(lang("exResetMsgTitle"), config.Instance.Site.SiteName); String body = loadHtml(emailBody); Result sentResult = mail.Send(email, title, body); if (sentResult.HasErrors) { errors.Add(lang("exResetSend")); showError(); } else { resetService.Insert(userReset); showJson(lang("resetSendok")); } }
private String getResetLink(UserResetPwd resetInfo) { String codeFull = resetInfo.User.Id + "_" + resetInfo.Code; codeFull = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(codeFull)); return(strUtil.Join(ctx.url.SiteUrl, to(ResetPwd) + "?c=" + codeFull)); }
public void ResetPwd() { // 1、根据get的code,查询数据库,是否有此重置密码请求 UserResetPwd resetInfo = validateCode(); if (resetInfo == null) { echoRedirect(ctx.errors.ErrorsHtml, sys.Path.Root); return; } // 2、渲染表单 set("ActionLink", to(SavePwd) + "?c=" + ctx.Get("c")); }
public virtual void StepTwo() { // 0、验证码 Html.Captcha.CheckError( ctx ); // 1、得到email地址和相应的用户 String email = ctx.Post( "Email" ); if (strUtil.IsNullOrEmpty( email )) { errors.Add( lang( "exEmail" ) ); } else if (new Regex( RegPattern.Email ).IsMatch( email ) == false) { errors.Add( lang( "exEmailFormat" ) ); } if (ctx.HasErrors) { echoError(); return; } User user = userService.GetByMail( email ); if (user == null) { errors.Add( lang( "exUserNotFoundByEmail" ) ); echoError(); return; } ctx.SetItem( "User", user ); // 2、产生唯一code并加入数据库 UserResetPwd userReset = new UserResetPwd(); userReset.User = user; userReset.Code = Guid.NewGuid().ToString().Replace( "-", "" ).ToLower(); userReset.Ip = ctx.Ip; String resetLink = getResetLink( userReset ); ctx.SetItem( "ResetLink", resetLink ); // 3、给此email发送一封重置pwd的邮件 MailClient mail = MailClient.Init(); String title = string.Format( lang( "exResetMsgTitle" ), config.Instance.Site.SiteName ); String body = loadHtml( emailBody ); Result sentResult = mail.Send( email, title, body ); if (sentResult.HasErrors) { errors.Add( lang( "exResetSend" ) ); echoError(); } else { resetService.Insert( userReset ); echoRedirect( lang( "resetSendok" ), ctx.url.SiteAndAppPath ); } }
private UserResetPwd validateCode() { String code = ctx.Get("c"); if (strUtil.IsNullOrEmpty(code)) { errors.Add("code error"); return(null); } String codestr = null; try { codestr = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(code)); } catch (Exception ex) { logger.Error(lang("exResetError") + ex.Message); errors.Add("code " + lang("error")); return(null); } string[] arrCode = codestr.Split('_'); if (arrCode.Length != 2) { errors.Add("code " + lang("error")); return(null); } int userId = cvt.ToInt(arrCode[0]); if (userId <= 0) { errors.Add("code " + lang("error")); return(null); } String guid = arrCode[1]; UserResetPwd resetInfo = resetService.GetByUserAndCode(userId, guid); if (resetInfo == null) { errors.Add(lang("exResetNotFound")); return(null); } return(resetInfo); }
public void SavePwd() { UserResetPwd resetInfo = validateCode(); if (resetInfo == null) { echoRedirect(ctx.errors.ErrorsHtml); return; } // 1、重设用户的密码 String pwd = ctx.Post("Pwd"); userService.UpdatePwd(resetInfo.User, pwd); // 2、将重设记录改成已设 resetService.UpdateResetSuccess(resetInfo); echoRedirect(lang("opok"), sys.Path.Root); }
private String getResetLink( UserResetPwd resetInfo ) { String codeFull = resetInfo.User.Id + "_" + resetInfo.Code; codeFull = Convert.ToBase64String( System.Text.Encoding.UTF8.GetBytes( codeFull ) ); return strUtil.Join( ctx.url.SiteUrl, to( ResetPwd ) + "?c=" + codeFull ); }
public virtual void UpdateResetSuccess( UserResetPwd resetInfo ) { resetInfo.IsSet = 1; db.update( resetInfo, "IsSet" ); }
public virtual void Insert( UserResetPwd resetInfo ) { db.insert( resetInfo ); }
public virtual void UpdateResetSuccess(UserResetPwd resetInfo) { resetInfo.IsSet = 1; db.update(resetInfo, "IsSet"); }
public virtual void Insert(UserResetPwd resetInfo) { db.insert(resetInfo); }