Пример #1
0
        public ActionResult Register(User user)
        {
            if (string.IsNullOrEmpty(user.Login) || string.IsNullOrEmpty(user.Email))
            {
                if (string.IsNullOrEmpty(user.Login))
                {
                    ModelState.AddModelError("Login", "You must pick a username");
                }
                if (string.IsNullOrEmpty(user.Email))
                {
                    ModelState.AddModelError("Email", "You must provide an email address");
                }

                return(View("Registration", user));
            }

            if (CurrentServiceModel.IsUserNameAvailable(user.Login))
            {
                CurrentServiceModel.CreateUser(user);

                FormsAuthentication.SetAuthCookie(user.Login, true);

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

            ModelState.AddModelError("Name", "This username is not available, please choose another");

            return(View("Registration", user));
        }
Пример #2
0
        public ActionResult AddUser(string login, string password, string email)
        {
            CurrentUserModel.CheckIsSiteAdmin();

            User u = new User();

            u.Email = email;
            u.Login = login;
            u.Name  = login;
            u.SetPassword(password);

            CurrentServiceModel.CreateUser(u);
            return(RedirectToAction("Index"));
        }