/// <summary> /// 忘记密码 /// </summary> /// <param name="code"></param> public void ForgetPassword(string code) { var user = Broker.Retrieve <user_info>("SELECT * FROM user_info WHERE code = @mail OR mailbox = @mail", new Dictionary <string, object>() { { "@mail", code } }); AssertUtil.CheckNull <SpException>(user, "用户不存在", "5E507D9C-47BC-4586-880D-D9E42D02FEA4"); UserIdentityUtil.SetCurrentUser(MapperHelper.Map <CurrentUserModel>(user)); var id = Guid.NewGuid().ToString(); var sms = new mail_vertification() { Id = id, name = "重置密码", content = $@"你好,<br/><br/> 请在两小时内点击该<a href=""{ SystemConfig.Config.Protocol }://{SystemConfig.Config.Domain}/api/MailVertification/ResetPassword?id={id}"">链接</a>重置密码 ", expire_time = DateTime.Now.AddHours(2), is_active = false, mail_address = user.mailbox, mail_type = MailType.ResetPassword.ToString() }; Broker.Create(sms); }
/// <summary> /// 注册 /// </summary> /// <param name="model"></param> /// <returns></returns> public LoginResponse Signup(LoginRequest model) { AssertUtil.CheckIsNullOrEmpty <SpException>(model.code, "账号不能为空", ""); AssertUtil.CheckIsNullOrEmpty <SpException>(model.password, "密码不能为空", ""); return(Broker.ExecuteTransaction(() => { if (!model.code.Contains("@")) { return new LoginResponse(false, "注册失败,请使用邮箱作为账号"); } var vertification = new MailVertificationService(Broker).GetDataByMailAdress(model.code); if (vertification != null) { return new LoginResponse(false, "激活邮件已发送,请前往邮件激活账号,请勿重复注册", LoginMesageLevel.Warning); } var id = Guid.NewGuid().ToString(); model.password = RSAUtil.Decrypt(model.password, model.publicKey); var data = new mail_vertification() { Id = id, name = "账号激活邮件", content = $@"你好,<br/><br/> 请在两小时内点击该<a href=""{ SystemConfig.Config.Protocol }://{SystemConfig.Config.Domain}/api/MailVertification/ActivateUser?id={id}"">链接</a>激活,失效请重新登录注册 ", expire_time = DateTime.Now.AddHours(2), is_active = false, login_request = JsonConvert.SerializeObject(model), mail_address = model.code, mail_type = MailType.Activation.ToString() }; Broker.Create(data); // 返回登录结果、用户信息、用户验证票据信息 return new LoginResponse() { result = false, message = $"已向{data.mail_address}发送激活邮件,请在两个小时内激活", level = LoginMesageLevel.Warning.ToString() }; })); }