public async Task <IHttpActionResult> PasswordReset([FromBody] TD_Login model) { if (!UtilityHelper.VerifyMobileCode(model.Mobile, model.Code, true)) { return(Json(new { Code = 1, Message = "验证码错误或已经失效" })); } DataBaseEntities db = new DataBaseEntities(); var user = db.AspNetUsers.SingleOrDefault(u => u.MyMobilePhone == model.Mobile); if (user == null) { return(Json(new { Code = 1, Message = "没有该手机号码" })); } string resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id); IdentityResult passwordChangeResult = await UserManager.ResetPasswordAsync(user.Id, resetToken, model.Password); if (!passwordChangeResult.Succeeded) { return(Json(new { Code = 1, Message = "修改密码错误" })); } return(Json(new { Code = 10000, Detail = true })); }
public async Task <IHttpActionResult> Login([FromBody] TD_Login model) { DataBaseEntities db = new DataBaseEntities(); string grant_type = "password"; ASCIIEncoding encoding = new ASCIIEncoding(); string postData = "grant_type=" + grant_type; postData += ("&password="******"&username="******"POST"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.ContentLength = data.Length; Stream newStream = myRequest.GetRequestStream(); // Send the data. newStream.Write(data, 0, data.Length); newStream.Close(); // Get response HttpWebResponse myResponse = null; try { myResponse = (HttpWebResponse)myRequest.GetResponse(); } catch (WebException ex) { if (ex.Message.Contains("400")) { return(Json(new { Code = 1, Message = "手机号码或密码错误" })); } else { return(Json(new { Code = 1, Message = "网络访问错误" })); } } StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default); string content = reader.ReadToEnd(); JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> json = (Dictionary <string, object>)serializer.DeserializeObject(content); string username = json["userName"].ToString(); var myuser = db.AspNetUsers.Single(u => u.UserName == username); return(Json(new { Code = 10000, Detail = new { token = json["access_token"].ToString(), IsValid = true, expired = json[".expires"].ToString(), Portrait = myuser.Portrait } })); }