public async Task <ActionResult> RestorePassword(string guid) { RestorePasswordEntry entry = new RestorePasswordEntry(); using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.BaseAddress = new Uri("http://localhost:13384"); HttpResponseMessage msg = await client.GetAsync("/api/Account/GetPasswordRestoreEntry?guid=" + guid); if (msg.IsSuccessStatusCode) { entry = msg.Content.ReadAsAsync <RestorePasswordEntry>().Result; if (entry.AddingTime == default(DateTime)) { ViewData["message"] = "Guid has already been used. Please send another restoration letter"; } else if ((DateTime.Now - entry.AddingTime).TotalHours > 24) { ViewData["message"] = "Guid has expired. Please send another restoration letter"; } } else { ViewData["message"] = msg.Content.ReadAsAsync <string>().Result; } } return(View(entry)); }
public async Task <HttpResponseMessage> SetPassword(RestorePasswordEntry model) { bool res = await SetNullPassword(model.UserId); if (res) { IdentityResult result = await UserManager.AddPasswordAsync(model.UserId, model.NewPassword); if (!result.Succeeded) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Internal server error occured.Please try again")); } return(Request.CreateResponse(HttpStatusCode.OK, "OK")); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Internal server error occured.Please try again")); } }
public async Task <HttpResponseMessage> GetPasswordRestoreEntry([FromUri] string guid) { try { using (SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) { string cmdString = @"select A.Guid, A.Email, A.AddingTime, B.Id as UserId from RestorePasswordLog A inner join AspNetUsers B On A.Email = B.Email where A.Guid=@guid"; using (SqlCommand cmd = new SqlCommand(cmdString, con)) { cmd.Parameters.AddWithValue("@guid", guid); await con.OpenAsync(); using (SqlDataReader rdr = await cmd.ExecuteReaderAsync()) { RestorePasswordEntry en = new RestorePasswordEntry(); if (rdr.Read()) { en.UserId = rdr["UserId"].ToString(); en.AddingTime = Convert.ToDateTime(rdr["AddingTime"].ToString()); en.Email = rdr["Email"].ToString(); en.Guid = rdr["Guid"].ToString(); } return(Request.CreateResponse(HttpStatusCode.OK, en)); } } } } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message)); } }