public virtual ActionResult Index(string returnUrl) { if (!string.IsNullOrEmpty(returnUrl)) { if (this.Request.UrlReferrer != null) { var previousUrl = this.Request.UrlReferrer.ToString(); if (previousUrl.Contains("ShoppingBag")) { returnUrl = Url.Action("Index", "ShoppingBag"); } } } var viewModel = new SignInViewModel { ReturnUrl = returnUrl, RegisterViewModel = new SignInRegisterViewModel { ReturnUrl = returnUrl } }; return View(viewModel); }
public virtual ActionResult Index(SignInViewModel viewModel, string returnUrl) { if (viewModel.RegisterViewModel == null) viewModel.RegisterViewModel = new SignInRegisterViewModel { ReturnUrl = returnUrl }; viewModel.ReturnUrl = returnUrl; if (!ModelState.IsValid) return View(viewModel); var pwd = Util.GetMD5Hash(viewModel.Password.Trim()); using (var context = new TTTEntities()) { var user = context.tblaccesses .SingleOrDefault(a => a.Email == viewModel.Email && a.Password == pwd && a.Active); if (user == null) { ModelState.AddModelError("LoginForm", "Invalid Email/Password."); return View(viewModel); } if (!user.ConfirmedEmail) { var verifyEmailModel = new VerifyEmailViewModel { User = user, AfterLogin = true }; return View(MVC.SignIn.Views.VerifyEmail, verifyEmailModel); } Util.SessionAccess = user; FormsAuthentication.SetAuthCookie(viewModel.Email, false); } LinkToAccount(); return RedirectToLocal(viewModel.ReturnUrl); }
public virtual ActionResult Register(SignInViewModel viewModel) { var model = viewModel.RegisterViewModel; tblaccess user; using (var context = new TTTEntities()) { user = context.tblaccesses.Where(a => a.Email == model.Email && a.Active).SingleOrDefault(); if (user == null) { user = new tblaccess { Active = true, CreateDT = DateTime.Now, Email = model.Email, Password = Util.GetMD5Hash(model.Password), FirstName = model.FirstName, LastName = model.LastName, EmailToken = Guid.NewGuid().ToString() }; context.tblaccesses.Add(user); context.SaveChanges(); var verifyEmailModel = new VerifyEmailViewModel { User = user, AfterRegistration = true }; return View(MVC.SignIn.Views.VerifyEmail, verifyEmailModel); } else { ModelState.Clear(); ModelState.AddModelError("RegisterForm", "Email already exists. Please enter a different Email."); return View(Views.Index, viewModel); } } }