Esempio n. 1
0
        public ActionResult SignUp(SignUpModel model)
        {
            // Validate the token
            if (!string.IsNullOrWhiteSpace(model.Token) && model.Token == InviteTokenCreator.Create())
            {
                // Check for "admin" in the username
                if (model.Username.ToLower().Contains("admin"))
                {
                    return(CreateValidationError("Username", "Invalid username"));
                }

                // Check if the username and email exists
                if (AccountsManager.UsernameExists(model.Username))
                {
                    return(CreateValidationError("Username", "The username does already exist."));
                }
                if (AccountsManager.EmailExists(model.Email))
                {
                    return(CreateValidationError("Email", "The email address does already exist."));
                }

                // Create the account
                bool ok = AccountsManager.CreateAccount(model.Username.Trim().ToLower(), model.Email.Trim().ToLower(), model.Password);
                if (!ok)
                {
                    return(CreateValidationError("Failed to create the user"));
                }

                // Set the authentication cookie
                FormsAuthentication.SetAuthCookie(model.Username, true);

                // OK
                return(JsonOK());
            }
            else
            {
                // Invalid token, show error on client
                return(CreateValidationError("Invalid token"));
            }
        }