Exemplo n.º 1
0
        public bool AddUser(User user)
        {
            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }
            string query = "INSERT INTO SE_GEBRUIKER (GEBRUIKERSNAAM,WACHTWOORD) VALUES (:userName,:password)";

            OracleCommand command = new OracleCommand(query, connection);
            command.Parameters.Add(":userName", user.Username);
            command.Parameters.Add(":password", user.Password);
            command.CommandType = CommandType.Text;

            try
            {
                command.ExecuteNonQuery();
            }
            catch
            {
                return false;
                // Catch if the command was not succesfully executed.
            }
            connection.Close();
            return true;
        }
Exemplo n.º 2
0
 public Playlist(int playlistID, User user,string name)
 {
     this.PlaylistID = playlistID;
     this.User = user;
     this.Name = name;
     Videos = new List<Video>();
 }
Exemplo n.º 3
0
 public Comment(int commentID,Video video, string text, User poster)
 {
     this.CommentID = commentID;
     this.Video = video;
     this.Text = text;
     this.Poster = poster;
     // If possible, change this to date/time on the server.
     this.PostedDate = DateTime.Now.ToShortDateString();
     this.Likes = 0;
 }
Exemplo n.º 4
0
 public void Login(User loginUser)
 {
     lblErrorMessages.Visible = true;
     if (databaseManager.Authenticate(loginUser))
     {
         lblUserloginName.Visible = false;
         lblPassword.Visible = false;
         tbLoginUsername.Visible = false;
         tbPassword.Visible = false;
         BtnLogIn.Visible = false;
         BtnRegister.Visible = false;
         lblErrorMessages.Visible = true;
         lblErrorMessages.ForeColor = System.Drawing.Color.Black;
         lblErrorMessages.Text = "Succesvol ingelogd als " + loginUser.Username + ".";
         currentUser = loginUser;
         Session["User"] = currentUser;
     }
     else
     {
         lblErrorMessages.Visible = true;
         lblErrorMessages.ForeColor = System.Drawing.Color.Red;
         lblErrorMessages.Text = "Foute gebruikersnaam of wachtwoord.";
     }
 }
Exemplo n.º 5
0
 public void TestGoodAuthentication()
 {
     User user = new User("kai","hallo123");
     Assert.AreEqual(true, databasemanager.Authenticate(user));
 }
Exemplo n.º 6
0
 public void TestBadAuthentication()
 {
     User user = new User("kai", "fout");
     Assert.AreEqual(false, databasemanager.Authenticate(user));
 }
Exemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            DatabaseManager databasemanager = new DatabaseManager();
            Video video = new Video(8, string.Empty, string.Empty, string.Empty, false, null, string.Empty);
            Stream stream = new MemoryStream();
            databasemanager.AddVideoAsBlob(video, stream);

            //lblErrorMessages.Visible = true;
            System.Web.HttpBrowserCapabilities browser = Request.Browser;
            if (browser.Browser != "Firefox")
            {
                lblErrorMessages.Visible = true;
                lblErrorMessages.ForeColor = System.Drawing.Color.Red;
                lblErrorMessages.Text = "Please use Firefox";
            }
            if (databaseManager == null)
            {
                databaseManager = new DatabaseManager();
            }
            if (Videos == null)
            {
                Videos = databaseManager.GetAllVideos();
            }
            try
            {
                string username = (string)(Session["Username"]);
                string password = (string)(Session["Password"]);
                if (username != string.Empty && username != null && password != null && password != string.Empty)
                {
                    CurrentUser = new User(username, password);
                }
                if(int.TryParse(Request.QueryString["video"],out currentVideoID))
                {
                    CurrentVideo = databaseManager.GetVideo(currentVideoID);
                }
                else
                {
                    if (Videos.Count != 0)
                    {
                        foreach (Video v in Videos)
                        {
                            if (CurrentVideo == null)
                            {
                                this.CurrentVideo = v;
                            }
                        }
                    }
                }
                if (CurrentUser != null)
                {
                    Login(CurrentUser);
                }
            }
            catch
            {
                // No session found.
            }
            if (CurrentVideo != null)
            {
                ChangeVideo(CurrentVideo);
                databaseManager.AddView(CurrentVideo);
                Comments = databaseManager.GetComments(CurrentVideo);
                AddComments();
            }
            if (CurrentVideo != null && CurrentUser != null)
            {
                if (CurrentVideo.Uploader == CurrentUser.Username)
                {
                    BtnDeleteVideo.Visible = true;
                }
                AddComments();
            }
        }
Exemplo n.º 8
0
 protected void BtnRegister_Click(object sender, EventArgs e)
 {
     if (tbLoginUsername.Text != string.Empty && tbPassword.Text != string.Empty)
     {
         User newuser = new User(tbLoginUsername.Text.ToLower(), tbPassword.Text);
         if (databaseManager.AddUser(newuser))
         {
             Login(newuser);
         }
         else
         {
             lblErrorMessages.Visible = true;
             lblErrorMessages.ForeColor = System.Drawing.Color.Red;
             lblErrorMessages.Text = "Gebruiker niet toegevoegd, deze bestaat mogelijk al.";
         }
     }
     else
     {
         lblErrorMessages.Visible = true;
         lblErrorMessages.ForeColor = System.Drawing.Color.Red;
         lblErrorMessages.Text = "Gebruikersnaam of wachtwoord niet ingevuld.";
     }
 }
Exemplo n.º 9
0
 protected void BtnLogIn_Click(object sender, EventArgs e)
 {
     if (tbLoginUsername.Text != string.Empty && tbPassword.Text != string.Empty)
     {
         User loginUser = new User(tbLoginUsername.Text.ToLower(), tbPassword.Text);
         Login(loginUser);
     }
     else
     {
         lblErrorMessages.Visible = true;
         lblErrorMessages.ForeColor = System.Drawing.Color.Red;
         lblErrorMessages.Text = "Gebruikersnaam of wachtwoord niet ingevuld.";
     }
 }
Exemplo n.º 10
0
 public void Login(User loginUser)
 {
     lblErrorMessages.Visible = true;
     if (databaseManager.Authenticate(loginUser))
     {
         lblUserloginName.Visible = false;
         lblPassword.Visible = false;
         tbLoginUsername.Visible = false;
         tbPassword.Visible = false;
         BtnLogIn.Visible = false;
         BtnRegister.Visible = false;
         tbAddComment.Visible = true;
         BtnAddComment.Visible = true;
         lblCommentInfo.Visible = false;
         BtnPlaylists.Visible = true;
         BtnUpload.Visible = true;
         lblErrorMessages.Visible = true;
         BtnAddtoPlaylist.Visible = true;
         BtnLogout.Visible = true;
         lblErrorMessages.ForeColor = System.Drawing.Color.Black;
         lblErrorMessages.Text = "Succesvol ingelogd als "+loginUser.Username+".";
         CurrentUser = loginUser;
         Session["Username"] = CurrentUser.Username;
         Session["Password"] = CurrentUser.Password;
         if (CurrentVideo != null)
         {
             if (CurrentVideo.Uploader == CurrentUser.Username)
             {
                 BtnDeleteVideo.Visible = true;
             }
         }
         AddComments();
         Session["User"] = CurrentUser;
     }
     else
     {
         lblErrorMessages.Visible = true;
         lblErrorMessages.ForeColor = System.Drawing.Color.Red;
         lblErrorMessages.Text = "Foute gebruikersnaam of wachtwoord.";
     }
 }
Exemplo n.º 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                currentUser = (User)Session["User"];
            }
            catch
            {
            }
            if (currentUser == null)
            {

                lblErrorMessages.Visible = true;
                lblErrorMessages.ForeColor = System.Drawing.Color.Red;
                lblErrorMessages.Text = "Je bent niet ingelogd, ga terug naar de homepage.";
                BtnUpload.Enabled = false;
            }
        }
Exemplo n.º 12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            selectedVideos = new List<Video>();
            playlistID = 0;
            try
            {
                string playlistUser = Request.QueryString["ChooseplaylistUser"];
                int videoID = 0;
                int.TryParse(Request.QueryString["video"], out videoID);
                if (playlistUser != string.Empty)
                {
                    Page.Title = "Afspeellijsten";
                    playlists = databaseManager.GetPlaylists(playlistUser);
                    foreach (Playlist p in playlists)
                    {
                        Label myLabel = new Label();
                        myLabel.Text = p.Name;
                        myLabel.ID = "Label" + p.PlaylistID;
                        Button myButton = new Button();
                        myButton.Text = "Kies";
                        myButton.ID = "Play" + p.PlaylistID+"Vid"+videoID;
                        myButton.Click += new EventHandler(BtnChoosePlaylistClicked);
                            PnlSearchResults.Controls.Add(myLabel);
                            PnlSearchResults.Controls.Add(myButton);
                            PnlSearchResults.Controls.Add(new LiteralControl("<br />"));
                    }
                }
            }
            catch
            {

            }
            try
            {
                string playlistUser = Request.QueryString["playlistUser"];
                if (playlistUser != string.Empty)
                {

                    Page.Title = "Afspeellijsten";
                    playlists = databaseManager.GetPlaylists(playlistUser);
                    foreach (Playlist p in playlists)
                    {
                        Label myLabel = new Label();
                        myLabel.Text = p.Name;
                        myLabel.ID = "Label" + p.PlaylistID;
                        Button myButton = new Button();
                        myButton.Text = "Bekijken";
                        myButton.ID = "Button" + p.PlaylistID;
                        myButton.Click += new EventHandler(BtnPlaylistClicked);
                        PnlSearchResults.Controls.Add(myLabel);
                        PnlSearchResults.Controls.Add(myButton);
                        PnlSearchResults.Controls.Add(new LiteralControl("<br />"));
                    }
                }

            }
            catch
            {
                // No playlist, possibly search
            }
            try
            {
                int.TryParse(Request.QueryString["playlistID"], out playlistID);
                if (playlistID != 0)
                {
                    selectedVideos = databaseManager.GetVideoFromPlaylist(playlistID);
                }

                foreach (Video v in selectedVideos)
                {
                    Label myLabel = new Label();
                    myLabel.Text = v.Title;
                    myLabel.ID = "Label" + v.VideoID;
                    Button myButton = new Button();
                    myButton.Text = "Bekijken";
                    myButton.ID = "Button" + v.VideoID;
                    myButton.Click += new EventHandler(BtnClicked);
                    Control myControl = PnlSearchResults.FindControl("Button" + v.VideoID);
                    if (myControl == null)
                    {
                        PnlSearchResults.Controls.Add(myLabel);
                        PnlSearchResults.Controls.Add(myButton);
                        PnlSearchResults.Controls.Add(new LiteralControl("<br />"));
                    }
                }
                Label lblnewPlaylist = new Label();
                lblnewPlaylist.Text = "Naam nieuwe playlist:";
                lblnewPlaylist.ID = "lblnewPlaylist";
                tbPlaylistName.ID = "TbPlaylistName";
                Button btnNewPlaylist= new Button();
                btnNewPlaylist.Text = "Maak playlist";
                btnNewPlaylist.ID = "BtnNewPlaylist";
                btnNewPlaylist.Click += new EventHandler(BtnNewPlaylistClicked);
                    PnlSearchResults.Controls.Add(lblnewPlaylist);
                    PnlSearchResults.Controls.Add(tbPlaylistName);
                    PnlSearchResults.Controls.Add(btnNewPlaylist);
                    PnlSearchResults.Controls.Add(new LiteralControl("<br />"));
            }
            catch
            {
                // No playlist, possibly search
            }
            try
            {
                search = Request.QueryString["search"].Replace("+", " ");
                if (tbSearchBar.Text == string.Empty)
                {
                    tbSearchBar.Text = search;
                }
                Page.Title = search;
                videos = databaseManager.GetAllVideos();
                foreach (Video v in videos)
                {
                    if (!v.Private)
                    {
                        if (v.Title.ToLower().Contains(search))
                        {
                            selectedVideos.Add(v);
                        }
                    }
                }
                foreach (Video v in selectedVideos)
                {
                    Label myLabel = new Label();
                    myLabel.Text = v.Title;
                    myLabel.ID = "Label" + v.VideoID;
                    Button myButton = new Button();
                    myButton.Text = "Bekijken";
                    myButton.ID = "Button" + v.VideoID;
                    myButton.Click += new EventHandler(BtnClicked);
                    PnlSearchResults.Controls.Add(myLabel);
                    PnlSearchResults.Controls.Add(myButton);
                    PnlSearchResults.Controls.Add(new LiteralControl("<br />"));
                }
            }
            catch
            {
                // No search, possibly playlist
            }
            try
            {
                currentUser = (User)Session["User"];

                if (currentUser != null)
                {
                    Login(currentUser);
                }
            }
            catch
            {

            }
        }
Exemplo n.º 13
0
 public User GetUser(string userName)
 {
     User user;
     if (connection.State != ConnectionState.Open)
     {
         connection.Open();
     }
     string query = "SELECT * FROM SE_GEBRUIKER WHERE GEBRUIKERSNAAM= :username";
     OracleCommand command = new OracleCommand(query, connection);
     command.CommandType = CommandType.Text;
     command.Parameters.Add("username", userName);
     OracleDataReader dataReader;
     string username = string.Empty;
     string password = string.Empty;
     try
     {
         dataReader = command.ExecuteReader();
         while (dataReader.Read())
         {
             username = Convert.ToString(dataReader["GEBRUIKERSNAAM"]);
             password = Convert.ToString(dataReader["WACHTWOORD"]);
         }
     }
     catch
     {
         // Catch if reading from the database doesn't work
     }
     user = new User(username, password);
     // GetUser() is only used for other queries, so the connection shouldn't be closed.
     return user;
 }
Exemplo n.º 14
0
        public bool Authenticate(User user)
        {
            connection.Open();
            string query = "SELECT * FROM SE_GEBRUIKER WHERE GEBRUIKERSNAAM = :userParameter";

            OracleCommand command = new OracleCommand(query, connection);
            command.Parameters.Add("userParameter", user.Username);
            command.CommandType = CommandType.Text;

            OracleDataReader dataReader;
            string username = string.Empty;
            string userpassword = string.Empty;
            try
            {
                dataReader = command.ExecuteReader();

                while (dataReader.Read())
                {
                    username = Convert.ToString(dataReader["GEBRUIKERSNAAM"]);
                    userpassword = Convert.ToString(dataReader["WACHTWOORD"]);
                }
            }
            catch
            {
                // Catch if reading from the database doesn't work
            }

            connection.Close();
            if (user.Username == username && user.Password == userpassword)
            {
                return true;
            }
            else
            {
                return false;
            }
        }