Ejemplo n.º 1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    string msg = WebSecurity.CreateAccount(model.UserName, model.UserName, model.Password, model.FirstName, model.LastName, false);

                    if (msg == String.Empty && !String.IsNullOrEmpty(ConfigurationManager.AppSettings["EnableEmailNotification"]))
                    {
                        if (Convert.ToBoolean(ConfigurationManager.AppSettings["EnableEmailNotification"])) //Check Enable Email Notification
                        {
                            try
                            {
                                SendConfirmationEmail(model.UserName); //Send confirmation email
                            }
                            catch (Exception exp)
                            {
                                //throw (exp);
                            }
                        }
                    }

                    WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Ejemplo n.º 2
0
        //[ValidateAntiForgeryToken]
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid) 
            {
                // Attempt to register the user
                try
                {
                    string confirmationToken =
                        WebSecurity.CreateUserAndAccount(model.UserName, model.Password, model.UserName, model.FirstName,model.LastName,true); //model.UserName = user email as 3rd parameter
                    SendEmailConfirmation(model.Email, model.UserName, model.Password, confirmationToken);

                    return RedirectToAction("RegisterStepTwo", "Account");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }