public ActionResult Register(LoginRegisterViewModel viewmodel) { if (ModelState.IsValid) { LoginModel model = new LoginModel(); model = Mapper.Map<LoginRegisterViewModel, LoginModel>(viewmodel); bool userexists = db.UserProfiles.Any(x => x.UserName.Equals(model.UserName)); if (userexists) { ModelState.AddModelError("", "There is already an account with that UserName. Please use a different username"); return View("Login"); // return View(viewmodel); } // Attempt to register the user try { string confirmationToken = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, propertyValues: new { FirstName = model.FirstName }, requireConfirmationToken: true); //new {Email=model.Email} //var email = new StandardEmail(); //email.To = model.UserName; //email.Name = model.FirstName; //// email.ConfirmationToken = confirmationToken; //email.ConfirmationToken = ConfigurationManager.AppSettings["funfoodingUrl"] + "/Account/EmailConfirmation/" + confirmationToken; //email.Send(); EmailModel emailmodel = new EmailModel(); emailmodel.To = model.UserName; emailmodel.Subject = "Welcome to Fun Fooding"; StringBuilder sb = new StringBuilder(); sb.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); sb.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); sb.Append("<head>"); sb.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"); sb.Append("</head>"); sb.Append("<body>"); sb.Append("<div style=\"padding:20px; font:normal 14px Arial, Helvetica, sans-serif; color:#333333;\">"); sb.Append("Hi " + model.FirstName + ",<br />"); sb.Append("Thank you for signing up!<br />"); sb.Append("<br />"); sb.Append("To complete the sign up process click "); sb.Append("<a href=" + ConfigurationManager.AppSettings["funfoodingUrl"] + "/Account/EmailConfirmation/" + confirmationToken + " style=\"color:#0066CC\"> here</a>.<br />"); sb.Append("<br />"); sb.Append("If you have any problem completing the process, please contact <a href=\"#\" style=\"color:#0066CC\">[email protected]</a>.<br />"); sb.Append("<br /> "); sb.Append("Best regards,<br />"); sb.Append("Support Team<br />"); sb.Append("<a href=\"http://funfooding.com/\" style=\"color:#0066CC\">www.funfooding.com</a></div>"); sb.Append("</body>"); sb.Append("</html>"); emailmodel.EmailBody = sb.ToString(); Common.sendeMail(emailmodel, true); return RedirectToAction("ConfirmEmail", "Account", new { Name = model.FirstName }); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View("Login", viewmodel); }
public JsonResult Register(LoginRegisterViewModel viewmodel) { bool res = true; //return Json(viewmodel, JsonRequestBehavior.AllowGet); try { LoginModel model = new LoginModel(); model = Mapper.Map<LoginRegisterViewModel, LoginModel>(viewmodel); //return Json(viewmodel, JsonRequestBehavior.AllowGet); // Attempt to register the user string confirmationToken = WebSecurity.CreateUserAndAccount(viewmodel.UserName, viewmodel.Password,propertyValues: new { FirstName = viewmodel.FirstName }, requireConfirmationToken: true); //new {Email=model.Email} EmailModel emailmodel = new EmailModel(); emailmodel.To = viewmodel.UserName; emailmodel.Subject = "Welcome to Fun Fooding"; StringBuilder sb = new StringBuilder(); sb.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); sb.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); sb.Append("<head>"); sb.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"); sb.Append("</head>"); sb.Append("<body>"); sb.Append("<div style=\"padding:20px; font:normal 14px Arial, Helvetica, sans-serif; color:#333333;\">"); sb.Append("Hi " + viewmodel.FirstName + ",<br />"); sb.Append("Thank you for signing up!<br />"); sb.Append("<br />"); sb.Append("To complete the sign up process click "); sb.Append("<a href=" + ConfigurationManager.AppSettings["funfoodingUrl"] + "/Account/EmailConfirmation/" + confirmationToken + " style=\"color:#0066CC\"> here</a>.<br />"); sb.Append("<br />"); sb.Append("If you have any problem completing the process, please contact <a href=\"#\" style=\"color:#0066CC\">[email protected]</a>.<br />"); sb.Append("<br /> "); sb.Append("Best regards,<br />"); sb.Append("Support Team<br />"); sb.Append("<a href=\"http://funfooding.com/\" style=\"color:#0066CC\">www.funfooding.com</a></div>"); sb.Append("</body>"); sb.Append("</html>"); emailmodel.EmailBody = sb.ToString(); Common.sendeMail(emailmodel, true); return Json(new { success = res}, JsonRequestBehavior.AllowGet); } catch (Exception e) { res = false; //ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); return Json(new { success=res, msg = e }, JsonRequestBehavior.AllowGet); } // If we got this far, something failed, redisplay form return Json(res, JsonRequestBehavior.AllowGet); }
public ActionResult Login(LoginRegisterViewModel viewmodel, string returnUrl) { LoginModel model = new LoginModel(); model = Mapper.Map<LoginRegisterViewModel, LoginModel>(viewmodel); if (WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { var user = db.UserProfiles.Where(x => x.UserName.Equals(model.UserName)).First(); int UserID = user.UserId; Session["FirstName"] = user.FirstName; if (Url.IsLocalUrl(returnUrl)) { bool UserExists1 = db.UserProfiles.Any(x => x.UserName.Equals(model.UserName)); if (UserExists1) // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); else ModelState.AddModelError("", "This email Address is not registered with the site. Please complete your registration."); return Redirect(returnUrl); } else { bool UserExists2 = db.UserProfiles.Any(x => x.UserName.Equals(model.UserName)); if (UserExists2) // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); else ModelState.AddModelError("", "This email Address is not registered with the site. Please complete your registration."); return RedirectPage(UserID); } } bool UserExists = db.UserProfiles.Any(x => x.UserName.Equals(model.UserName)); if (UserExists) // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); else ModelState.AddModelError("", "This email Address is not registered with the site. Please complete your registration."); if (model.RememberMe) { return View(viewmodel); } else { viewmodel.UserName = null; viewmodel.Password = null; viewmodel.RememberMe = false; return View(viewmodel); } //return View(viewmodel); }
public JsonResult Login(LoginRegisterViewModel viewmodel) { UsersContext db = new UsersContext(); bool res = true; LoginModel model = new LoginModel(); model = Mapper.Map<LoginRegisterViewModel, LoginModel>(viewmodel); // return Json(viewmodel, JsonRequestBehavior.AllowGet); if (WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { var user = db.UserProfiles.Where(x => x.UserName.Equals(model.UserName)).First(); int UserID = user.UserId; return Json(new { success = res, userData = user }, JsonRequestBehavior.AllowGet); } bool UserExists = db.UserProfiles.Any(x => x.UserName.Equals(model.UserName)); if (UserExists) // If we got this far, something failed, redisplay form // ModelState.AddModelError("", "The user name or password provided is incorrect."); return Json(new { success = res, msg = "The user name or password provided is incorrect." }, JsonRequestBehavior.AllowGet); else //ModelState.AddModelError("", "There is no account with that UserName. Please sign up"); return Json(new { success = res, msg = "There is no account with that UserName. Please sign up" }, JsonRequestBehavior.AllowGet); return Json(res, JsonRequestBehavior.AllowGet); }