示例#1
0
        public ActionResult UpdatePassword(string username, string password)
        {
            var userToCreate = _userRepository.GetUser(username);
            
            if (userToCreate == null)
                userToCreate = new User() {Username = username};
            else
                userToCreate.EncryptedPassword = EncryptedPassword.Create(password);

            _userRepository.SaveUser(userToCreate);

            return new HttpStatusCodeResult(HttpStatusCode.OK);
        }
示例#2
0
        public ActionResult Create(string username, string password)
        {
            var userToCreate = _userRepository.GetUser(username);
            if(userToCreate != null)
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            
            userToCreate = new User();
            userToCreate.Username = username;
            userToCreate.EncryptedPassword = EncryptedPassword.Create(password);
            _userRepository.SaveUser(userToCreate);

            return new HttpStatusCodeResult(HttpStatusCode.OK);
        }
	    private void MakeSureAdminIsCreated()
	    {
	        var userRepo = new UserRepository();
	        var adminUser = userRepo.GetUser("admin");
            if(adminUser != null)
                return;

            adminUser = new User()
                            {
                                Username = "******",
                                EncryptedPassword = EncryptedPassword.Create("qwerty")
                            };

            userRepo.SaveUser(adminUser);

	    }
	    private IPrincipal ToPrincipal(User user) {
            return user != null ? new GenericPrincipal(new GenericIdentity(user.Username), AllRoles.ToArray()) : null;
	    }