//Hash the passed in password, then check it against the stored user's password
        public bool CheckIfValidLogin(string username, string password)
        {
            bool valid = false;
            UserDAO dao = new UserDAO();
            UserVO loginCompare;
            string hashedPass = HashPassword(password);

            System.Diagnostics.Debug.WriteLine("In checkifvalidlogin, username: " + username);

            //If you can't find a user under that name, throw the exception
            try {
                loginCompare = dao.GetUser(username);
            }
            catch (Exception e) {
                System.Diagnostics.Debug.WriteLine(e);
                throw new Exception(USERNAME_DOES_NOT_EXIST_EXCEPTION);
            }

            //If the password is not equal, throw the exception
            if (hashedPass.Equals(loginCompare.Password)) {
                valid = true;
            }
            else {
                throw new Exception(PASSWORD_INCORRECT_EXCEPTION);
            }

            return valid;
        }
        public void ChangePassword(int userID, string newPass)
        {
            UserDAO dao = new UserDAO();
            UserVO vo = GetUser(userID);

            vo.Password = HashPassword(newPass);
            dao.UpdateUser(vo);
        }
        public void CreateNewComment(string username, string commentContents, int subID, int pcID)
        {
            CommentDAO dao = new CommentDAO();
            UserDAO userDAO = new UserDAO();
            CommentVO comment = new CommentVO();

            if (commentContents == null) {
                throw new Exception("You need to enter a comment");
            }

            comment.UserID = userDAO.GetUser(username).UserID;
            comment.CommentContents = commentContents;
            comment.PostDate = DateTime.Now;
            comment.Rating = 0;
            if (pcID != 0) {
                comment.ParentCommentID = pcID;
            }
            comment.SubmissionID = subID;

            dao.InsertComment(comment);
        }
        public void CreateNewSubmission(string title, string link, string username)
        {
            SubmissionDAO dao = new SubmissionDAO();
            UserDAO userDAO = new UserDAO();
            SubmissionVO newSub = new SubmissionVO();

            if (title == null) {
                throw new Exception("You need to enter a title");
            }

            if (link == null) {
                throw new Exception("You need to enter a link");
            }

            newSub.Title = title;
            newSub.Link = link;
            newSub.Rating = 0;
            newSub.PostTime = DateTime.Now;
            newSub.UserID = userDAO.GetUser(username).UserID;

            dao.InsertSubmission(newSub);
        }
        public void CreateNewUser(string username, string password)
        {
            UserDAO dao = new UserDAO();
            UserVO newUser = new UserVO();

            //Check to see if there's already a user of that name
            if (CheckIfUsernameTaken(username)) {
                throw new Exception(USERNAME_TAKEN_EXCEPTION);
            }

            newUser.Username = username;
            newUser.Password = HashPassword(password);
            newUser.RegisterDate = DateTime.Now;
            newUser.Rating = 0;

            InsertUser(newUser);
        }
        public int CheckIfVoted(int subID, int uID)
        {
            int voted;
            UserDAO dao = new UserDAO();

            voted = dao.CheckIfVoted(uID, subID);

            return voted;
        }
        public void ChangeRating(int userID, int rating)
        {
            UserDAO dao = new UserDAO();

            dao.ChangeRating(userID, rating);
        }
        private UserVO InsertUser(UserVO newUser)
        {
            try {

                using(TransactionScope ts = new TransactionScope()){
                    UserDAO dao = new UserDAO();
                    LogDebug("Inserting Employee " + newUser.Username);
                    newUser = dao.InsertUser(newUser);
                    LogDebug("User succesfully inserted!");
                    ts.Complete();
                }

            }
            catch (Exception e) {
                LogError(e.ToString());
                throw e;
            }

            return newUser;
        }
        //True if taken, false if not taken
        private bool CheckIfUsernameTaken(string username)
        {
            bool taken = true;
            UserDAO dao = new UserDAO();
            UserVO vo;

            //Try to grab a vo with the name passed in. If it throws
            //an exception, that means it couldn't find a user with that name
            try {
                vo = dao.GetUser(username);
                Console.WriteLine("CheckIfUsername: " + vo.Username);
            }
            catch (Exception e) {
                taken = false;
            }

            return taken;
        }
Beispiel #10
0
        public void UpdateComment(UserVO user)
        {
            UserDAO dao = new UserDAO();

            dao.UpdateUser(user);
        }
Beispiel #11
0
        public void SubmitVote(int subID, int uID, int vote)
        {
            UserDAO dao = new UserDAO();

            dao.SubmitVote(uID, subID, vote);
            ChangeRating(uID, vote);
        }
Beispiel #12
0
 public UserVO GetUser(string username)
 {
     UserDAO dao = new UserDAO();
     return dao.GetUser(username);
 }
Beispiel #13
0
 public UserVO GetUser(int uID)
 {
     UserDAO dao = new UserDAO();
     return dao.GetUser(uID);
 }