public ActionResult EmailConfirm(int regID) { User user = db.Users.FirstOrDefault(x => x.ID == regID); Session["ID"] = user.ID; Session["Email"] = user.Email; FormsAuthentication.SetAuthCookie(user.Email, true); user.IsEmailVerified = true; db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); db.Dispose(); if (user.RoleID == 1) { return(RedirectToAction("Index", "MyProfile")); } else { return(RedirectToAction("Index", "AdminDashboard")); } }
public ActionResult Index(ChangePasswordModel changePassword) { User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name); //Enter Password and Db Password Not Match if (user.Password != changePassword.OldPassword) { ModelState.AddModelError("OldPassword", "Enter Valid Old Password"); return(View(changePassword)); } //New Pass and Confirm Pass not Match if (changePassword.NewPassword != changePassword.ConfirmPassword) { ModelState.AddModelError("confirmpassword", "Password and ConfirmPassword are not Same"); return(View(changePassword)); } if (user.IsActive == true && ModelState.IsValid) { user.Password = changePassword.NewPassword; db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); FormsAuthentication.SignOut(); Session.Abandon(); Session.Clear(); Session.RemoveAll(); Session["ID"] = null; Session["Email"] = null; Session.RemoveAll(); db.Dispose(); return(RedirectToAction("Index", "Login")); } return(View(changePassword)); }
public ActionResult Index([Bind(Include = "FirstName,LastName,Email,Password,ConfirmPassword")] User user) { if (ModelState.IsValid) { Match isPassword = Regex.Match(user.Password, @"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{6,24}", RegexOptions.IgnorePatternWhitespace); Match isFirstName = Regex.Match(user.FirstName, @"^[a-zA-Z]+$", RegexOptions.IgnorePatternWhitespace); Match isLastName = Regex.Match(user.LastName, @"^[a-zA-Z]+$", RegexOptions.IgnorePatternWhitespace); //Email already Exist if (db.Users.Any(x => x.Email == user.Email)) { ModelState.AddModelError("Email", "This Email Already Exist"); return(View(user)); } //Password and ConfirmPassword doesn't Match if (!(user.Password.Equals(user.ConfirmPassword))) { ModelState.AddModelError("ConfirmPassword", "Password and ConfirmPassword are not Same"); return(View(user)); } //Password is not Valid if (!isPassword.Success) { ModelState.AddModelError("Password", "Password shold contain 6 long, 1 - special, digit, upper, lower char"); return(View(user)); } //FirstName And LastName is Not valid if (!isFirstName.Success) { ModelState.AddModelError("FirstName", "Use Only Alphabet"); return(View(user)); } if (!isLastName.Success) { ModelState.AddModelError("LastName", "Use Only Alphabet"); return(View(user)); } user.RoleID = 1; user.IsActive = true; user.CreatedDate = DateTime.Now; user.IsEmailVerified = false; db.Users.Add(user); db.SaveChanges(); //Build Email Template BuildEmailVerifyTemplate(user.ID); //Save Cookie Session["ID"] = user.ID; Session["Email"] = user.Email; ViewBag.Status = 1; ModelState.Clear(); db.Dispose(); return(View()); } else { //If Fail to Signup ViewBag.Status = 1; ViewBag.Class = "danger"; ViewBag.Msg = "Fail to Signup"; return(View(user)); } }
public ActionResult AddNote(AddNoteModel note, string Command) { ViewBag.Class = "white-nav"; User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name); if (user != null && ModelState.IsValid) { SellerNote sellernotes = new SellerNote(); // Save note info in Database sellernotes.SellerID = user.ID; sellernotes.Title = note.Title; sellernotes.Status = Command == "Save" ? 1 : 2; sellernotes.Category = note.Category; sellernotes.NoteType = note.NoteType; sellernotes.NumberofPages = note.NumberofPages; sellernotes.Description = note.Description; sellernotes.UniversityName = note.UniversityName; sellernotes.Country = note.Country; sellernotes.Course = note.Course; sellernotes.CourseCode = note.CourseCode; sellernotes.Professor = note.Professor; sellernotes.IsPaid = note.IsPaid; sellernotes.SellingPrice = sellernotes.IsPaid == false ? 0 : note.SellingPrice; sellernotes.CreatedDate = DateTime.Now; sellernotes.ModifiedDate = DateTime.Now; sellernotes.CreatedBy = user.ID; sellernotes.ModifiedBy = user.ID; sellernotes.IsActive = true; // If seller add unvalid price if (note.IsPaid) { if (note.SellingPrice == null || note.SellingPrice < 1) { ModelState.AddModelError("SellingPrice", "Enter valid Selling price"); AddNoteModel viewModel = GetDD(); return(View(viewModel)); } } if (note.UploadNotes[0] == null) { ModelState.AddModelError("UploadNotes", "Enter Note"); AddNoteModel viewModel = GetDD(); return(View(viewModel)); } db.SellerNotes.Add(sellernotes); db.SaveChanges(); sellernotes = db.SellerNotes.Find(sellernotes.ID); //save note picture if User add if (note.DisplayPicture != null) { string displaypicturefilename = Path.GetFileName(note.DisplayPicture.FileName); string displaypicturepath = "~/Members/" + user.ID + "/" + sellernotes.ID + "/"; CreateDirectoryIfMissing(displaypicturepath); string displaypicturefilepath = Path.Combine(Server.MapPath("~/Members/" + user.ID + "/" + sellernotes.ID + "/"), displaypicturefilename); sellernotes.DisplayPicture = displaypicturepath + displaypicturefilename; note.DisplayPicture.SaveAs(displaypicturefilepath); } else { var filepath = db.SystemConfigurations.Where(x => x.Name == "DefaultNoteDisplayPicture").FirstOrDefault(); sellernotes.DisplayPicture = filepath.Value; } //save note preview if (note.NotesPreview != null) { string notespreviewfilename = System.IO.Path.GetFileName(note.NotesPreview.FileName); string notespreviewpath = "~/Members/" + user.ID + "/" + sellernotes.ID + "/"; CreateDirectoryIfMissing(notespreviewpath); string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename); sellernotes.NotesPreview = notespreviewpath + notespreviewfilename; note.NotesPreview.SaveAs(notespreviewfilepath); } db.SellerNotes.Attach(sellernotes); db.Entry(sellernotes).Property(x => x.DisplayPicture).IsModified = true; db.Entry(sellernotes).Property(x => x.NotesPreview).IsModified = true; db.SaveChanges(); //save note file if (note.UploadNotes[0] != null) { foreach (HttpPostedFileBase file in note.UploadNotes) { if (file != null) { string notesattachementfilename = System.IO.Path.GetFileName(file.FileName); string notesattachementpath = "~/Members/" + user.ID + "/" + sellernotes.ID + "/Attachements/"; CreateDirectoryIfMissing(notesattachementpath); string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename); note.NotesPreview.SaveAs(notesattachementfilepath); //save note file into SellerNotesAttachement table SellerNotesAttachement notesattachements = new SellerNotesAttachement { NoteID = sellernotes.ID, FileName = notesattachementfilename, FilePath = notesattachementpath + notesattachementfilename, CreatedDate = DateTime.Now, CreatedBy = user.ID, ModifiedDate = DateTime.Now, ModifiedBy = user.ID, IsActive = true }; db.SellerNotesAttachements.Add(notesattachements); db.SaveChanges(); } } } db.Dispose(); return(RedirectToAction("Index", "SellNote")); } else { AddNoteModel viewModel = GetDD(); return(View(viewModel)); } }