public ActionResult ResetPasswordFromEmail(Guid id) { _logger.LogInfo("A password reset request was made for token: " + id); ViewBag.AllowChange = false; try { var existingToken = GTSDataRepository.GetListByQuery <PasswordHelper>("FROM PasswordHelper ph WHERE ph.IsArchived = false AND ph.Token = :token", new Dictionary <string, object> { { "token", id } }).FirstOrDefault(); if (existingToken != null && DateTime.Now.Subtract(existingToken.RequestDate) < new TimeSpan(24, 0, 0)) { ViewBag.AllowChange = true; } return(View()); } catch (Exception ex) { _logger.LogError(ex); throw; } }
/// <summary> /// Gets the open remarks (not archived, not resolved) for a particular assembly. /// </summary> /// <param name="assembly">The assembly.</param> /// <returns></returns> internal List <RemarkSymptom> GetOpenRemarksForAssembly(Guid assemblyId) { return(GTSDataRepository.GetListByQuery <RemarkSymptom>("FROM RemarkSymptom rs WHERE rs.IsArchived = false AND rs.Resolved = false AND rs.ProductAssembly.Id = :id", new Dictionary <string, object> { { "id", assemblyId } }).ToList()); }
public async Task <ActionResult> ResetPasswordJson(string newPassword, Guid token) { try { var helper = GTSDataRepository.GetListByQuery <PasswordHelper>("FROM PasswordHelper ph WHERE ph.IsArchived = false AND ph.Token = :token", new Dictionary <string, object> { { "token", token } }).FirstOrDefault(); if (helper == null && token != Guid.Empty) { throw new InvalidOperationException("Could not find password reset token"); } var users = UserManager.Users; var emailAddress = string.Empty; if (helper == null) { emailAddress = User.Identity.Name; } else { emailAddress = helper.EmailAddress; } var usr = users.Where(x => x.Email == emailAddress).FirstOrDefault(); var validPass = await UserManager.PasswordValidator.ValidateAsync(newPassword); if (validPass.Succeeded) { var user = UserManager.FindByName(usr.Email); user.PasswordHash = UserManager.PasswordHasher.HashPassword(newPassword); var res = UserManager.Update(user); if (res.Succeeded) { GTSDataRepository.ExecuteUpdateQuery("Update PasswordHelper SET IsArchived = true, ArchivedBy = :name, ArchivalDate = :dateNow where EmailAddress = :email", new Dictionary <string, object> { { "name", usr.Email }, { "dateNow", DateTime.Now }, { "email", usr.Email } }); AuthenticationManager.SignOut(); return(new HttpStatusCodeResult(200, "Password change successful.")); } else { var errorMsg = "One or more errors occured during the password change attempt: "; res.Errors.ForEach(x => errorMsg += (x + ". ")); throw new InvalidOperationException(errorMsg); } } else { throw new InvalidOperationException("The password you've provided is not considered strong enough, please choose another."); } } catch (Exception ex) { _logger.LogError(ex); throw; } }
/// <summary> /// Updates an assembly. /// </summary> /// <param name="objectAsString">The object as a json string.</param> /// <returns></returns> /// <exception cref="System.InvalidOperationException"> /// No product serial was found in incoming device data. /// or /// Could not find product with serial: " + postData["productSerial"] /// or /// Data is corrupted: the system found more than one product with serial " + postData["productSerial"] /// or /// Could not find component assemblies for product with serial: " + postData["productSerial"] /// </exception> private ActionResult UpdateAssemblyParsed(string objectAsString) { _logger.LogInfo("Incoming data from a remote device: {0}", objectAsString); try { var postData = (Dictionary <string, object>) new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(objectAsString); if (postData["productSerial"] == null || string.IsNullOrEmpty(postData["productSerial"].ToString())) { throw new InvalidOperationException("No product serial was found in incoming device data."); } var keyWords = postData.Keys.ToList().Where(x => x.ToString() != "productSerial" && x.ToString() != "baseModelId" && x.ToString() != "deviceKey").ToArray <string>(); var doCreateRemark = false; if (postData["createRemark"].ToString().ToLower() == "true") { doCreateRemark = true; } // check if product exists var productAssemblyCriteria = UnitOfWorkSession.CreateCriteria <ProductAssembly>(); productAssemblyCriteria = productAssemblyCriteria.Add(Expression.Eq("ProductSerial", postData["productSerial"])); var productAssembly = productAssemblyCriteria.List <ProductAssembly>(); if (productAssembly.Count() == 0) { throw new InvalidOperationException("Could not find product with serial: " + postData["productSerial"]); } if (productAssembly.Count() > 1) { throw new InvalidOperationException("Data is corrupted: the system found more than one product with serial " + postData["productSerial"]); } var componentAssemblyCriteria = UnitOfWorkSession.CreateCriteria <ComponentAssembly>(); componentAssemblyCriteria = componentAssemblyCriteria.CreateAlias("ProductAssembly", "pa"); componentAssemblyCriteria = componentAssemblyCriteria.Add(Expression.Eq("pa.ProductSerial", postData["productSerial"])); componentAssemblyCriteria = componentAssemblyCriteria.CreateAlias("ProductComponent", "pc"); componentAssemblyCriteria = componentAssemblyCriteria.Add(Expression.In("pc.DeviceKeyword", keyWords)); componentAssemblyCriteria = componentAssemblyCriteria.CreateAlias("pc.ProductModel", "pm"); componentAssemblyCriteria = componentAssemblyCriteria.Add(Expression.Eq("pm.IsReleased", true)); //componentAssemblyCriteria = componentAssemblyCriteria.Add(Expression.Eq("pm.IsArchived", false)); if (postData.Keys.Contains <string>("baseModelId")) { componentAssemblyCriteria = componentAssemblyCriteria.Add(Expression.Eq("pm.BaseModelId", Guid.Parse(postData["baseModelId"].ToString()))); } var filteredComponentAssemblies = componentAssemblyCriteria.List <ComponentAssembly>(); if (filteredComponentAssemblies.Count() == 0) { throw new InvalidOperationException("Could not find component assemblies for product with serial: " + postData["productSerial"]); } // find matching component assemblies for any device keywords in the post data keyWords.ToList().ForEach(x => { filteredComponentAssemblies.Where(y => y.ProductComponent.DeviceKeyword == x).ToList().ForEach(z => { // update component assembly if (postData[x] != null) { z.Revision = postData[x].ToString(); GTSDataRepository.Update <ComponentAssembly>(z); } }); }); // create remark when needed if (doCreateRemark) { var remarkMessage = string.Format("Product with serial {0} failed its automated tests. Reasons given: ", postData["productSerial"].ToString()); if (productAssembly[0].ProductModel.Name.ToLower().Contains("wing")) { if (postData["deviceApproval"] != null && postData["deviceApproval"].ToString() == "no") { remarkMessage += "Product found to be invalid by wing checker tool, "; if (postData["errorMessage"] != null) { remarkMessage += postData["errorMessage"].ToString(); } } if (postData["minmax"] != null && postData["minmax"].ToString() == "no") { remarkMessage += "User did not approve min and / or max, "; } } else if (productAssembly[0].ProductModel.Name.ToLower().Contains("ux11 motor")) { if (!(bool)postData["userApproval"]) { remarkMessage += "User disapproves (" + postData["disapprovalReason"].ToString() + "), "; } if (!(bool)postData["systemApprovalVoltage"]) { remarkMessage += "Measured voltage does not conform to expectations, "; } if (!(bool)postData["systemApprovalCurrent"]) { remarkMessage += "Measured current does not conform to expectations, "; } if (!(bool)postData["systemApprovalRPM"]) { remarkMessage += "Measured rpm does not conform to expectations, "; } if (!(bool)postData["systemApprovalDirection"]) { remarkMessage += "Measured direction of spin does not conform to expectations, "; } } var newRemark = new RemarkSymptom { Id = Guid.NewGuid(), CreationDate = DateTime.Now, ResolutionDate = DateTime.MaxValue, Description = remarkMessage, ProductAssembly = productAssembly[0], EditedBy = postData["user"].ToString(), RemarkSymptomType = GTSDataRepository.GetListByQuery <RemarkSymptomType>("FROM RemarkSymptomType WHERE Name = '" + postData["remarkSymptomType"].ToString() + "'").FirstOrDefault(), }; GTSDataRepository.Create <RemarkSymptom>(newRemark); } return(new HttpStatusCodeResult(200, "Data received")); } catch (Exception ex) { _logger.LogError(ex); return(new HttpStatusCodeResult(500, ex.Message)); } }