public ActionResult ResetPassword(ResetPasswordViewModel model) { if (ModelState.IsValid) { var login = _context.Logins.Single(l => l.LoginId == model.LoginId); var salt = AuthenticationLogic.Get_SALT(64); login.Password = AuthenticationLogic.Get_HASH_SHA512(model.Password, login.Email, salt); login.PasswordSalt = salt; login.PasswordResetToken = String.Empty; login.ModifiedTime = DateTime.Now; _context.SaveChanges(); TempData["ViewModel"] = new SuccessPageViewModel { Message = Constants.ResetPasswordSuccessMessage }; return(RedirectToAction("Success", "Home")); } return(View(model)); }
public ActionResult RegisterDriver(RegisterDriverViewModel model) { if (ModelState.IsValid) { //Unqieness validations var checkEmailUniqueness = _context.Logins .SingleOrDefault(l => l.Email == model.Email); if (checkEmailUniqueness != null) { ModelState.AddModelError("Email", "Email id is already registered."); } var checkPhoneUnqiueness = _context.TruckOwners .SingleOrDefault(t => t.Phone == model.Phone); if (checkPhoneUnqiueness != null) { ModelState.AddModelError("Phone", "Phone number is already registered."); } var checkTruckUniqueness = _context.Trucks .SingleOrDefault(t => t.LicensePlate == model.LicensePlate); if (checkTruckUniqueness != null) { ModelState.AddModelError("LicensePlate", "Truck License Number is already registered."); } var checkDLNumberUniqueness = _context.TruckOwners .SingleOrDefault(t => t.DriverLicenseNumber == model.DriverLicenseNumber); if (checkDLNumberUniqueness != null) { ModelState.AddModelError("DriverLicenseNumber", "Driver License Number is already registered."); } var checkVRumberUniqueness = _context.TruckOwners .SingleOrDefault(t => t.VehicleRegNumber == model.VehicleRegNumber); if (checkVRumberUniqueness != null) { ModelState.AddModelError("VehicleRegNumber", "Vehicle Reg Number is already registered."); } var checkDIPNumberUniqueness = _context.TruckOwners .SingleOrDefault(t => t.DriverInsurancePolicy == model.DriverInsurancePolicy); if (checkDIPNumberUniqueness != null) { ModelState.AddModelError("DriverInsurancePolicy", "Driver Insurance Policy is already registered."); } //Unqieness validations if (checkEmailUniqueness == null && checkPhoneUnqiueness == null && checkTruckUniqueness == null && checkDLNumberUniqueness == null && checkVRumberUniqueness == null && checkDIPNumberUniqueness == null) { var salt = AuthenticationLogic.Get_SALT(64); var login = new Login { Email = model.Email.Trim(), Password = AuthenticationLogic.Get_HASH_SHA512(model.Password, model.Email, salt), PasswordSalt = salt, UserType = "D", EmailActivated = false, CreatedTime = DateTime.Now, ModifiedTime = DateTime.Now }; _context.Logins.Add(login); var truckOwner = new TruckOwner { FirstName = model.FirstName.Trim(), LastName = model.LastName.Trim(), Phone = model.Phone.Trim(), Email = model.Email.Trim(), CurrentStatusActive = false, Address1 = model.Address1.Trim(), Address2 = model.Address2, ZipCode = model.ZipCode.Trim(), City = model.City.Trim(), State = model.State.Trim(), DriverLicenseNumber = model.DriverLicenseNumber.Trim(), VehicleRegNumber = model.VehicleRegNumber.Trim(), DriverInsurancePolicy = model.DriverInsurancePolicy.Trim(), CreatedTime = DateTime.Now, ModifiedTime = DateTime.Now }; _context.TruckOwners.Add(truckOwner); var truck = new Truck { TruckOwnerId = truckOwner.TruckOwnerId, TruckTypeId = model.TruckTypeId, TruckMake = model.TruckMake.Trim(), TruckModel = model.TruckModel.Trim(), TruckYear = model.TruckYear.ToString(), LicensePlate = model.LicensePlate.Trim(), TruckColor = model.TruckColor.Trim(), CreatedTime = DateTime.Now, ModifiedTime = DateTime.Now }; _context.Trucks.Add(truck); _context.SaveChanges(); string token = truckOwner.TruckOwnerId + "c45kaa52165hrd84rd"; string verificationUrl = Url.Action("VerifyEmail", "TruckOwners", new { token = token }, Request.Url.Scheme); SendGridEmailService.SendEmailActivationLink("Driver", truckOwner.Email, truckOwner.FirstName, verificationUrl); TempData["ViewModel"] = new SuccessPageViewModel { Message = Constants.RegisterSuccessMessage }; return(RedirectToAction("Success", "Home")); } } model.TruckTypesList = GetTruckTypes(); return(View("../TruckOwners/BecomeDriver", model)); }
public ActionResult Register(RegisterCustomerViewModel model) { if (ModelState.IsValid) { var checkEmailUniqueness = _context.Logins.SingleOrDefault(l => l.Email == model.Email); var checkPhoneUnqiueness = _context.Customers.SingleOrDefault(t => t.Phone == model.Phone); if (checkEmailUniqueness != null) { ModelState.AddModelError("Email", "Email id is already registered."); } if (checkPhoneUnqiueness != null) { ModelState.AddModelError("Phone", "Phone number is already registered."); } if (checkEmailUniqueness == null && checkPhoneUnqiueness == null) { var salt = AuthenticationLogic.Get_SALT(64); var login = new Login { Email = model.Email.Trim(), Password = AuthenticationLogic.Get_HASH_SHA512(model.Password, model.Email, salt), PasswordSalt = salt, UserType = "C", EmailActivated = false, CreatedTime = DateTime.Now, ModifiedTime = DateTime.Now }; _context.Logins.Add(login); var customer = new Customer { FirstName = model.FirstName.Trim(), LastName = model.LastName.Trim(), Phone = model.Phone.Trim(), Email = model.Email.Trim(), Address1 = model.Address1.Trim(), Address2 = model.Address2, ZipCode = model.ZipCode.Trim(), City = model.City.Trim(), State = model.State.Trim(), CreatedTime = DateTime.Now, ModifiedTime = DateTime.Now }; _context.Customers.Add(customer); _context.SaveChanges(); string token = customer.CustomerId + "c45kaa52165hrd84rd"; string verificationUrl = Url.Action("VerifyEmail", "Customers", new { token = token }, Request.Url.Scheme); SendGridEmailService.SendEmailActivationLink("Customer", customer.Email, customer.FirstName, verificationUrl); TempData["ViewModel"] = new SuccessPageViewModel { Message = Constants.RegisterSuccessMessage }; return(RedirectToAction("Success", "Home")); } } return(View(model)); }