public async Task <IHttpActionResult> ResetPassword(ReqResetPassword req) { string agent = Request.Headers.UserAgent.ToString(); var response = new ResponseBaseModel(); if (!await this._userRepo.ResetPassword(req.submitToken, req.mail, req.password, agent)) { Enforce.Throw(new LogicErrorException("重置失败")); } response.SetResponse(ResStatusCode.OK, "重置成功"); return(Ok(response)); }
private async void Forgot_Click(object sender, RoutedEventArgs e) { forgotPassPanel.IsEnabled = false; RecPswrdModel rec = FormModel.RecPswrdModel; rec.Error = ""; bool can = true; if (string.IsNullOrWhiteSpace(rec.Email)) { rec.Error += Res.EmailEmpty + "\n"; can = false; } else if (!Regex.IsMatch(rec.Email, @".+@.+\..+")) { rec.Error += Res.EmailInvalid + "\n"; can = false; } rec.Error = rec.Error.Trim(); if (can) { try { ReqResetPassword model = new ReqResetPassword() { Email = rec.Email }; await Account.ResetPassword(model); await Task.Delay(200); Open_AuthPanel(null, null); } catch (WebException we) { rec.Error = GetError(we); } catch (Exception err) { Logger.Error("Auth_ResetPassword", err); } } forgotPassPanel.IsEnabled = true; }
private async void Forgot_Click(object sender, RoutedEventArgs e) { forgotPassPanel.IsEnabled = false; backButton.IsEnabled = false; try { ReqResetPassword model = new ReqResetPassword() { Email = emailForgot.Text }; await Account.ResetPassword(model); await Task.Delay(200); Clear(); } catch (WebException we) { var s = we.Response; using (var reader = new StreamReader(s.GetResponseStream())) { string raw = reader.ReadToEnd(); try { JArray jObject = JArray.Parse(raw); foreach (JToken par in jObject.Children()) { NotifyController.Show(PopupNotify.Error, par.Value <string>("property"), ((JProperty)par.Value <JToken>("constraints").First()).Value.ToString(), 4000); } } catch { NotifyController.Show(PopupNotify.Error, Res.Error, raw, 5000); } } } catch (Exception err) { Logger.Error("Auth_ResetPassword", err); } forgotPassPanel.IsEnabled = true; backButton.IsEnabled = true; }
public static Task ResetPassword(ReqResetPassword model) { return(Request($"{URL_Api}users/reset-password", "POST", false, JsonConvert.SerializeObject(model))); }
/// <summary> /// 重置用户密码 /// </summary> /// <param name="data"></param> /// <returns></returns> public Stream ResetPassword(Stream data) { bool success = false; ResResetPassword response = new ResResetPassword(); try { DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(ReqResetPassword)); //读取器 StreamReader sr = new StreamReader(data); string dataString = String.Empty; while (!sr.EndOfStream) { dataString = sr.ReadToEnd(); Console.WriteLine(dataString); #region 日志输出 CommonInfo.Log(dataString); #endregion //反序列化json为对象注意顺序很重要 ReqResetPassword request = new ReqResetPassword(); MemoryStream temp = new MemoryStream(Encoding.UTF8.GetBytes(dataString)); request = json.ReadObject(temp) as ReqResetPassword; //关闭临时流 temp.Close(); //调用用户更新密码接口 if (request != null) { //*.数据合法性检查 //*.更新 if (request.account != null && request.user_id != null) { success = PatrolUserInfoRule.ResetPassword(request.user_id, request.account); } } } sr.Close(); Console.WriteLine(data); } catch (Exception ex) { Console.WriteLine(ex.Message); #region 日志输出 CommonInfo.Error("重置密码错误" + ex.Message); #endregion } //返回消息体 if (success) { response.SetSuccess(); } else { ////默认是失败 //response.SetFailed(); } //将消息序列化为Json格式数据 DataContractJsonSerializer obj2Json = new DataContractJsonSerializer(typeof(ResResetPassword)); MemoryStream ms = new MemoryStream(); obj2Json.WriteObject(ms, response); //注意一定要设置流的位置到开始位置,否则没有消息输出 ms.Position = 0; return(ms); }