public ActionResult Register(RegisterViewModel model) { int usernameMin = SiteConfig.UsernameMin.ToInt(); int usernameMax = SiteConfig.UsernameMax.ToInt(); int passwordMinimum = SiteConfig.PasswordMin.ToInt(); if (model.Username == null || model.Username.Length > usernameMax || model.Username.Length < usernameMin) { string message = string.Format("Username length must be between {0} and {1} characters long", usernameMin, usernameMax); ModelState.AddModelErrorFor <RegisterViewModel>(m => m.Username, message); } else if (_userServices.GetUser(model.Username) != null) { ModelState.AddModelErrorFor <RegisterViewModel>(m => m.Username, "Username already taken"); } if (_userServices.EmailInUse(model.Email)) { ModelState.AddModelErrorFor <RegisterViewModel>(m => m.Email, "Email is already in use by another user"); } if (model.Password == null || model.Password.Length < passwordMinimum) { string message = string.Format("Password must be at least {0}", passwordMinimum); ModelState.AddModelErrorFor <RegisterViewModel>(m => m.Password, message); } if (IsModelValidAndPersistErrors()) { string ActivationType = SiteConfig.AccountActivation.Value; User user = _userServices.Register(model.Username, model.Password, model.Email); string CreateSucess = "User <b>" + user.Username + "</b> was created."; if (ActivationType == "Email") { CreateSucess += " An activation email has been sent to <b>" + user.Email + "</b> with details on how to activate the account"; string confirm_url = Url.Action("ActivateUser", "Auth", new { uname = user.Username, code = user.ActivationCode }); _emailServices.Registration(user, confirm_url); } else if (ActivationType == "Admin") { CreateSucess += " Admin activation is required. You will not be able to login until an admin activates your account"; } SetSuccess(CreateSucess); return(RedirectToAction("Login")); } return(RedirectToSelf()); }