public virtual ActionResult Register(RegisterRequest request, string returnUrl) { // I think it should be obvious why we don't want the current URL to be the return URL here ;) ViewData[Constants.ReturnUrlViewDataKey] = returnUrl; if (User != null && User.Identity != null && User.Identity.IsAuthenticated) { ModelState.AddModelError(String.Empty, "You are already logged in!"); return View(); } if (!ModelState.IsValid) { return View(); } User user; try { user = UserService.Create( request.Username, request.Password, request.EmailAddress); } catch (EntityException ex) { ModelState.AddModelError(String.Empty, ex.Message); return View(); } SetAuthenticationCookie(user); if (RedirectHelper.SafeRedirectUrl(Url, returnUrl) != RedirectHelper.SafeRedirectUrl(Url, null)) { // User was on their way to a page other than the home page. Redirect them with a thank you for registering message. TempData["Message"] = "Your account is now registered!"; return new RedirectResult(RedirectHelper.SafeRedirectUrl(Url, returnUrl)); } // User was not on their way anywhere in particular. Show them the thanks/welcome page. return RedirectToAction(MVC.Users.Thanks()); }
public virtual ActionResult Register(RegisterRequest request) { // If we have to render a view, we don't want Login to have us as a return URL // By having this value present in the dictionary BUT null, we don't put "returnUrl" on the Login link at all ViewData[Constants.ReturnUrlViewDataKey] = null; // TODO: consider client-side validation for unique username // TODO: add email validation if (!ModelState.IsValid) { return(View()); } User user; try { user = UserService.Create( request.Username, request.Password, request.EmailAddress); } catch (EntityException ex) { ModelState.AddModelError(String.Empty, ex.Message); return(View()); } if (Config.ConfirmEmailAddresses) { // Passing in scheme to force fully qualified URL var confirmationUrl = Url.ConfirmationUrl( MVC.Users.Confirm(), user.Username, user.EmailConfirmationToken, protocol: Request.Url.Scheme); MessageService.SendNewAccountEmail(new MailAddress(request.EmailAddress, user.Username), confirmationUrl); } return(RedirectToAction(MVC.Users.Thanks())); }
public virtual ActionResult Register(RegisterRequest request) { // TODO: consider client-side validation for unique username // TODO: add email validation if (!ModelState.IsValid) { return View(); } User user; try { user = _userService.Create( request.Username, request.Password, request.EmailAddress); } catch (EntityException ex) { ModelState.AddModelError(String.Empty, ex.Message); return View(); } if (_settings.ConfirmEmailAddresses) { // Passing in scheme to force fully qualified URL var confirmationUrl = Url.ConfirmationUrl( MVC.Users.Confirm(), user.Username, user.EmailConfirmationToken, protocol: Request.Url.Scheme); _messageService.SendNewAccountEmail(new MailAddress(request.EmailAddress, user.Username), confirmationUrl); } return RedirectToAction(MVC.Users.Thanks()); }
public virtual ActionResult Register(RegisterRequest request) { // If we have to render a view, we don't want Login to have us as a return URL // By having this value present in the dictionary BUT null, we don't put "returnUrl" on the Login link at all ViewData[Constants.ReturnUrlViewDataKey] = null; // TODO: consider client-side validation for unique username // TODO: add email validation if (!ModelState.IsValid) { return View(); } User user; try { user = _userService.Create( request.Username, request.Password, request.EmailAddress); } catch (EntityException ex) { ModelState.AddModelError(String.Empty, ex.Message); return View(); } if (_config.ConfirmEmailAddresses) { // Passing in scheme to force fully qualified URL var confirmationUrl = Url.ConfirmationUrl( MVC.Users.Confirm(), user.Username, user.EmailConfirmationToken, protocol: Request.Url.Scheme); _messageService.SendNewAccountEmail(new MailAddress(request.EmailAddress, user.Username), confirmationUrl); } return RedirectToAction(MVC.Users.Thanks()); }