public ActionResult SignUp(RegisterModel regModel)
 {
     if (ModelState.IsValid)
     {
         User newUser = new User(regModel.Email, Util.GeneratePassword(regModel.Password));
         if (DependencyResolver.Current.GetService<IAuthenticationService>().Register(newUser))
         {
             return RedirectToAction("SignIn", "Home");
         }
         else
         {
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return Content("Error during user registration", MediaTypeNames.Text.Plain);
         }
     }
     else
     {
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return Content("registration data is not valid", MediaTypeNames.Text.Plain);
     }
 }
 public ActionResult SignUp(RegisterModel regModel)
 {
     if (ModelState.IsValid)
     {
         User newUser = new User(regModel.Email, Util.GeneratePassword(regModel.Password));
         if (DependencyResolver.Current.GetService<IAuthenticationService>().Register(newUser))
         {
             _logger.Trace("New user sucsessfully signed up");
             return RedirectToAction("SignIn", "Home");
         }
         else
         {
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             _logger.Trace("New user failed sign up: Some error occured. Response.StatusCode: " + Response.StatusCode);
             return Content("Error during user registration", MediaTypeNames.Text.Plain);
         }
     }
     else
     {
         _logger.Trace("New user failed to fill sign up form");
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return Content("registration data is not valid", MediaTypeNames.Text.Plain);
     }
 }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    var mgr = new ElDataManager();
                    var userId = mgr.Create(new User()
                        {
                            DisplayName = model.UserName,
                            Username = model.UserName,
                            Password = model.Password
                        });
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { EverliveGuid = userId });
                    Roles.AddUsersToRoles(new[] { model.UserName }, new[] { "Dispatcher" });

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

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Попытка зарегистрировать пользователя
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return View(model);
        }
        public ActionResult Register(RegisterModel model)
        {
            if (model.ConfirmPassword != model.Password)
            {
                ModelState.AddModelError("", "");
                return View(model);
            }
            if (ModelState.IsValid)
            {

                int id = userService.CreateUser(model.ToUserEntity(),model.Email);
                if (id>0)
                {
                    authService.CreateAuthorization(model.ToAuthorizationEntity(id));
                    SendEmail(model.Email, id);
                    return RedirectToAction("Confirm", "Account", new { email = model.Email });
                }
                ModelState.AddModelError("", "");

            }
              return View(model);
        }
        public ActionResult Registration(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                bool error = false;
                var c = (string)Session["CaptchaString"];
                if ((string)Session["CaptchaString"] != model.RegCaptchaText)
                {
                    ViewData.ModelState.AddModelError("RegCaptchaError", Resources.Feedback.Index.CaptchaError);
                    error = true;
                }

                if (model.RegUserName.ToLower().Contains("vialpando") || model.RegUserName.ToLower().Contains("vi4lp4ndo") || db.Users.Where(e => e.Username == model.RegUserName).FirstOrDefault() != null)
                {
                    ViewData.ModelState.AddModelError("RegUserName", Resources.Common.UsernameUsed);
                    error = true;
                }

                if (error)
                {
                    model.RegCaptchaText = "";
                    TempData["RegisterModel"] = model;
                    TempData["ViewData"] = ViewData;

                    return RedirectToAction("Index", "Home");
                }

                string code = Guid.NewGuid().ToString();
                db.Users.Add(new User { IsActivated = false, ActivationCode = code, Username = model.RegUserName, Password = Common.CalculateMD5Hash(model.RegPassword), EmailAddress = model.RegEmail, RegistrationDate = DateTime.Now, Type = (int)UserTypes.Reader });

                try
                {
                    db.SaveChanges();

                    Common.SendValidationMail(model.RegEmail, code, model.RegUserName);

                    TempData["GlobalMessageType"] = MessageTypes.Success;
                    TempData["ViewBag.GlobalMessage"] = Resources.Common.ActivationSent + " (" + model.RegEmail + ")";
                    TempData["ViewBag.GlobalHeader"] = Resources.Common.Success;

                    return RedirectToAction("Index", "Home");
                }
                catch (Exception e)
                {
                    TempData["GlobalMessageType"] = MessageTypes.Error;
                    TempData["ViewBag.GlobalMessage"] = Resources.Common.ErrorDatabase;
                    TempData["ViewBag.GlobalHeader"] = Resources.Common.Error;

                    return RedirectToAction("Index", "Home");
                }

            }

            if ((string)Session["RegCaptchaString"] != model.RegCaptchaText)
            {
                ViewData.ModelState.AddModelError("CaptchaError", Resources.Feedback.Index.CaptchaError);
                model.RegCaptchaText = "";
            }
            if (db.Users.Where(e => e.Username == model.RegUserName).FirstOrDefault() != null)
            {
                ViewData.ModelState.AddModelError("UserName", Resources.Common.UsernameUsed);
            }
            model.RegCaptchaText = "";
            TempData["RegisterModel"] = model;
            TempData["ViewData"] = ViewData;
            return RedirectToAction("Index", "Home");
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    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);
        }