public UserSettingsViewModel(User user)
        {
            User = user;

            NewUserInfo = new UserInfo();
            PasswordInputModel = new PasswordInputModel();

            UserInfoTypes = Enum.GetValues(typeof(UserInfoType))
                                .Cast<UserInfoType>()
                                .ToSelectList(x => x.GetDescription(), x => ((int)x).ToString());
        }
Example #2
0
        public User Create(User user)
        {
            var password = GeneratePassword(8);
            user.Password = Encrypter.Encrypt(password);

            _session.Save(user);

            // TODO send the password to the user!

            return user;
        }
Example #3
0
        public ActionResult Create(User user)
        {
            if (string.IsNullOrWhiteSpace(user.Username)) {
                var username = UserService.NameToUsername(user.Name);
                user.Username = username;
            }

            if(!_userService.IsUsernameFree(user.Username))
                ModelState.AddModelError("User.Username", "Användarnamned används redan. Vänligen ange ett annat!");

            if(!_userService.IsEmailFree(user.Email))
                ModelState.AddModelError("User.Email", "E-postadressen används redan. Vänligen ange ett annat!");

            if (!ModelState.IsValid)
                return Create();

            _userService.Create(user);

            FlashSuccess("Användaren har skapats!");
            return RedirectToAction("Index");
        }
Example #4
0
 public CreateViewModel()
 {
     User = new User();
 }
Example #5
0
        /// <summary>
        /// Update all replaceable properties with the props of the parameter. Rekommended only for admins
        /// </summary>
        public virtual void BigUpdate(User user)
        {
            SmallUpdate(user);

            Username = user.Username;
            Type = user.Type;
        }
Example #6
0
 /// <summary>
 /// Updates the properties the user itselves may update.
 /// </summary>
 public virtual void SmallUpdate(User user)
 {
     Name = user.Name;
     Email = user.Email;
 }
Example #7
0
        public ActionResult Settings(User user)
        {
            if (!ModelState.IsValid)
                return Settings();

            var existingUser = _userService.Get(User.Id);

            if(User.IsAdmin)
                existingUser.BigUpdate(user);
            else
                existingUser.SmallUpdate(user);

            _storage.Store(SessionKeys.User, existingUser);

            FlashSuccess("Dina inställningar har uppdaterats!");
            return RedirectToAction("Settings");
        }
Example #8
0
        public ActionResult Settings(int id, User user)
        {
            if (!ModelState.IsValid)
                return Settings(id);

            var existionUser = _userService.Get(id);
            existionUser.BigUpdate(user);

            FlashSuccess("Uppgifterna har uppdaterats!");
            return RedirectToAction("Index");
        }
Example #9
0
        public SettingsViewModel(User user)
        {
            User = user;

            PasswordInputModel = new PasswordInputModel();
        }