public ActionResult ForgotPassword(string EmailID) { string message = ""; bool status = false; using (BookingsModel.ModelBookings db = new BookingsModel.ModelBookings()) { var acc = db.Users.Where(a => a.EmailID == EmailID).FirstOrDefault(); if (acc != null) { string resetCode = Guid.NewGuid().ToString(); SendVerificationLink(acc.EmailID, resetCode, "ResetPassword"); acc.ResetPasswordCode = resetCode; db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); message = "The reset password link has been sent to the email listed on your account!"; } else { message = "Im affraid the account you've requested has not been found"; } } ViewBag.Message = message; return(View()); }
public ActionResult ResetPassword(ResetPasswordModel model) { var message = ""; if (ModelState.IsValid) { using (BookingsModel.ModelBookings db = new BookingsModel.ModelBookings()) { var users = db.Users.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault(); if (User != null) { users.Password = Crypto.Hash(model.NewPassword); users.ResetPasswordCode = ""; db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); message = "Your new password has been updated succesfully!"; } } } else { message = "Invalid request"; } ViewBag.Message = message; return(View(model)); }
public JsonResult SaveEvent(Events e) { var status = false; var r = db.Events.ToList(); using (BookingsModel.ModelBookings db = new BookingsModel.ModelBookings()) { if (e.EventID > 0) { //Update event var v = db.Events.Where(a => a.EventID == e.EventID).FirstOrDefault(); if (v != null) { v.Subject = e.Subject; v.Start = e.Start; v.End = e.End; v.Description = e.Description; v.IsFullDay = e.IsFullDay; v.ThemeColor = e.ThemeColor; } } else { db.Events.Add(e); } db.SaveChanges(); status = true; } return(new JsonResult { Data = new { status = status } }); }
public bool EmailExists(string emailID) { using (BookingsModel.ModelBookings db = new BookingsModel.ModelBookings()) { var v = db.Users.Where(a => a.EmailID == emailID).FirstOrDefault(); return(v != null); } }
public JsonResult GetEvents() { using (BookingsModel.ModelBookings db = new BookingsModel.ModelBookings()) { var events = db.Events.ToList(); return(new JsonResult { Data = events, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } }
public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] Users users) { bool Status = false; String Message = ""; if (ModelState.IsValid) { #region Does the Email exist? var exists = EmailExists(users.EmailID); if (exists) { ModelState.AddModelError("EmailExists", "Email already exists"); return(View(User)); } #endregion #region Generate Activation Code users.ActivationCode = Guid.NewGuid(); #endregion #region Password Hashing users.Password = Crypto.Hash(users.Password); users.ConfirmPassword = Crypto.Hash(users.ConfirmPassword); users.IsEmailVerified = false; #endregion #region Save to db using (BookingsModel.ModelBookings db = new BookingsModel.ModelBookings()) { db.Users.Add(users); db.SaveChanges(); SendVerificationLink(users.EmailID, users.ActivationCode.ToString()); Message = "Registration sucessfully done. Account activation link " + "has been send to your email id " + users.EmailID; Status = true; } } else { Message = "Invalid Request"; } ViewBag.Message = Message; ViewBag.Status = Status; return(View(users)); }
public ActionResult ResetPassword(string id) { using (BookingsModel.ModelBookings db = new BookingsModel.ModelBookings()) { var users = db.Users.Where(a => a.ResetPasswordCode == id).FirstOrDefault(); if (users != null) { ResetPasswordModel model = new ResetPasswordModel(); model.ResetCode = id; return(View(model)); } else { return(HttpNotFound()); } } }
public JsonResult DeleteEvent(int eventID) { var status = false; using (BookingsModel.ModelBookings db = new BookingsModel.ModelBookings()) { var v = db.Events.Where(a => a.EventID == eventID).FirstOrDefault(); if (v != null) { db.Events.Remove(v); db.SaveChanges(); status = true; } } return(new JsonResult { Data = new { status = status } }); }
public ActionResult CustomerLogin(CustomerLogin login, string ReturnUrl) { string message = ""; using (BookingsModel.ModelBookings db = new BookingsModel.ModelBookings()) { var v = db.Users.Where(a => a.EmailID == login.EmailID).FirstOrDefault(); if (v != null) { if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0) { int timeout = login.RememberMe ? 525600 : 20; //525600 min = 1 year var ticket = new FormsAuthenticationTicket(login.EmailID, login.RememberMe, timeout); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(timeout); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { message = "Your Credentials appear to be invalid"; } } else { message = "Your Credentials appear to be invalid"; } } ViewBag.Message = message; return(View()); }
public ActionResult VerifyAccount(string id) { bool Status = false; using (BookingsModel.ModelBookings db = new BookingsModel.ModelBookings()) { db.Configuration.ValidateOnSaveEnabled = false; var v = db.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault(); if (v != null) { v.IsEmailVerified = true; db.SaveChanges(); Status = true; } else { ViewBag.MEssage = "Invalid Request"; } } ViewBag.Status = Status; return(View()); }