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");
        }
예제 #2
0
 public void UpdateUser(User user)
 {
     if (user.Id != User.Id && !IsSiteAdmin)
         throw new InvalidOperationException ("Not authorized");
     db.UpdateObject (user);
 }
예제 #3
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);
        }
예제 #4
0
 public ActionResult Register()
 {
     User user = new User ();
     user.OpenId = Request.QueryString["openid"];
     ViewData["ticket"] = GetIdTicket (user.OpenId);
     return View ("Registration", user);
 }
예제 #5
0
        public ActionResult ProfileSave(User user)
        {
            if (string.IsNullOrEmpty (user.Email))
                ModelState.AddModelError ("Email", "You must provide an email address");

            if (!ModelState.IsValid)
                return View ("Profile", user);

            User cuser = CurrentUserModel.GetUser (user.Id);
            cuser.Name = user.Name;
            cuser.Email = user.Email;
            CurrentUserModel.UpdateUser (cuser);

            return RedirectToAction ("Index", "Home");
        }
예제 #6
0
 public ActionResult Profile(User u)
 {
     if (u.Login == null)
         u = CurrentUserModel.User;
     return View ("Profile", u);
 }
예제 #7
0
 internal void UpdateUser2(User user)
 {
     db.UpdateObject (user);
 }
예제 #8
0
        internal void CreateUser(User user)
        {
            if (Settings.Default.InitialConfiguration)
                user.IsAdmin = true;

            db.InsertObject (user);

            if (Settings.Default.InitialConfiguration)
                EndInitialConfiguration ();

            string subject = "User registered: " + user.Name;
            StringBuilder msg = new StringBuilder ();
            msg.AppendLine ("A new user has been registered.");
            msg.AppendLine ();
            msg.AppendLine ("Name: " + user.Name);
            msg.AppendLine ("E-mail: " + user.Email);
            SendMail (subject, msg.ToString (), SiteNotification.NewUser);
        }