Esempio n. 1
0
        public void TestReservation()
        {
            User user = new User()
            {
                FirstName       = "bob",
                LastName        = "builder",
                Username        = "******",
                Email           = "bb",
                Password        = "",
                ConfirmPassword = ""
            };


            Authentication auth    = new Authentication(user.Password);
            UserItem       newUser = new UserItem()
            {
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Email     = user.Email,
                Username  = user.Username,
                Salt      = auth.Salt,
                Hash      = auth.Hash,
                RoleId    = (int)Authorization.eRole.StandardUser
            };

            newUser.Id = _dbUserManager.AddUserItem(newUser);
        }
Esempio n. 2
0
        public void TestUser()
        {
            db    = new UserSecurityDAO("Data Source=localhost\\sqlexpress;Initial Catalog=npcampground;Integrated Security=True");
            _tran = new TransactionScope();

            Authentication auth = new Authentication(Password);

            UserItem useritem = new UserItem()
            {
                FirstName = "Brad",
                LastName  = "Henry",
                Username  = "******",
                Email     = "*****@*****.**",
                Salt      = auth.Salt,
                Hash      = auth.Hash,
                RoleId    = (int)Security.BusinessLogic.Authorization.eRole.StandardUser
            };

            _user_id = db.AddUserItem(useritem);

            var user = db.GetUserItem(_user_id);

            Assert.AreEqual("Brad", user.FirstName);
            Assert.AreEqual("Henry", user.LastName);
            Assert.AreEqual("ash", user.Username);
            Assert.AreEqual("*****@*****.**", user.Email);
        }
Esempio n. 3
0
        public void TestUser()
        {
            Authentication auth = new Authentication("Abcd!234");

            // Test add user
            UserItem item = new UserItem();

            item.FirstName = "Chris";
            item.LastName  = "Rupp";
            item.Username  = "******";
            item.Hash      = auth.Hash;
            item.Salt      = auth.Salt;
            item.Email     = "!@#$%^@tech.com";
            item.RoleId    = (int)Authorization.eRole.StandardUser;
            int id = _db.AddUserItem(item);

            Assert.AreNotEqual(0, id);

            // Test get user item by id
            UserItem itemGet = _db.GetUserItem(id);

            Assert.AreEqual(item.Id, itemGet.Id);
            Assert.AreEqual(item.FirstName, itemGet.FirstName);
            Assert.AreEqual(item.LastName, itemGet.LastName);
            Assert.AreEqual(item.Username, itemGet.Username);
            Assert.AreEqual(item.Hash, itemGet.Hash);
            Assert.AreEqual(item.Salt, itemGet.Salt);
            Assert.AreEqual(item.Email, itemGet.Email);

            // Test update user
            item.FirstName = "What";
            item.LastName  = "What";
            item.Username  = "******";
            item.Email     = "What";
            item.Hash      = "What";
            item.Salt      = "What";
            Assert.IsTrue(_db.UpdateUserItem(item));

            // Test get user item by user name
            itemGet = _db.GetUserItem(item.Username);
            Assert.AreEqual(item.Id, itemGet.Id);
            Assert.AreEqual(item.FirstName, itemGet.FirstName);
            Assert.AreEqual(item.LastName, itemGet.LastName);
            Assert.AreEqual(item.Username, itemGet.Username);
            Assert.AreEqual(item.Hash, itemGet.Hash);
            Assert.AreEqual(item.Salt, itemGet.Salt);
            Assert.AreEqual(item.Email, itemGet.Email);

            // Test delete user
            _db.DeleteUserItem(id);
            var users = _db.GetUserItems();

            foreach (var user in users)
            {
                Assert.AreNotEqual(id, user.Id);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a new user to the vending machine system
        /// </summary>
        /// <param name="userModel">Model that contains all the user information</param>
        public int RegisterUser(User userModel)
        {
            int      id       = 0;
            UserItem userItem = null;

            try
            {
                userItem = _db.GetUserItem(userModel.Email);
            }
            catch (Exception)
            {
            }

            if (userItem != null)
            {
                throw new UserExistsException("The username is already taken.");
            }

            if (userModel.Password != userModel.ConfirmPassword)
            {
                throw new PasswordMatchException("The password and confirm password do not match.");
            }

            Authentication auth    = new Authentication(userModel.Password);
            UserItem       newUser = new UserItem()
            {
                FirstName = userModel.FirstName,
                LastName  = userModel.LastName,
                Email     = userModel.Email,
                Salt      = auth.Salt,
                Hash      = auth.Hash,
                RoleId    = userModel.RoleId,
                Phone     = userModel.Phone,
            };

            id = _db.AddUserItem(newUser);
            LoginUser(newUser.Email, userModel.Password);
            return(id);
        }
        /// <summary>
        /// Adds a new user to the program system
        /// </summary>
        /// <param name="userModel">Model that contains all the user information</param>
        public void RegisterUser(User userModel)
        {
            UserItem userItem = null;

            try
            {
                userItem = _db.GetUserItem(userModel.Username);
            }
            catch (Exception)
            {
            }

            if (userItem != null)
            {
                throw new UserExistsException("The username is already taken.");
            }

            if (userModel.Password != userModel.ConfirmPassword)
            {
                throw new PasswordMatchException("The password and confirm password do not match.");
            }

            Authentication auth    = new Authentication(userModel.Password);
            UserItem       newUser = new UserItem()
            {
                FirstName = userModel.FirstName,
                LastName  = userModel.LastName,
                Email     = userModel.Email,
                Username  = userModel.Username,
                Salt      = auth.Salt,
                Hash      = auth.Hash,
                RoleId    = (int)Authorization.eRole.StandardUser
            };

            _db.AddUserItem(newUser);
            LoginUser(newUser.Username, userModel.Password);
        }