コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: pieper126/SE22
        public void InlogTest()
        {
            // Arrange
            string password = "******";
            string username = "******";
            User user;
            User userUsedToReference;

            //act
            user = SE22.Tests.DatabaseManager.LogIn(username, password);
            userUsedToReference = new User("example1", "*****@*****.**", new System.Collections.Generic.List<Rights> { });

            //assert
            Assert.AreEqual(user.Username, userUsedToReference.Username);
            Assert.AreEqual(user.Functions.Count, userUsedToReference.Functions.Count);
            Assert.AreEqual(user.Email, userUsedToReference.Email);
        }
コード例 #2
0
ファイル: DatabaseManager.cs プロジェクト: pieper126/SE22
        /// <summary>
        /// checks if the given user 
        /// </summary>
        /// <param name="username">username of the user you are trying to log in</param>
        /// <param name="password">password of the user you are trying to log in</param>
        /// <returns>Gives back the user if he is verified</returns>
        public static User LogIn(string username, string password)
        {
            OracleConnection conn = MakeConnection();
            conn.Open();

            string mainQuery = "SELECT * FROM GEBRUIKER WHERE USERNAME = :USERNAME AND PASSWORD = :PASSWORD";
            string redactorQuery = "SELECT * FROM REDACTEUR WHERE USERNAME = :USERNAME";
            string moderatoryQuery = "SELECT * FROM MODERATOR WHERE USERNAME = :USERNAME";

            OracleCommand command = new OracleCommand(mainQuery, conn);
            command.Parameters.Add(new OracleParameter("USERNAME", username));
            command.Parameters.Add(new OracleParameter("PASSWORD", password));
            OracleCommand redactorCommand = new OracleCommand(redactorQuery, conn);
            redactorCommand.Parameters.Add(new OracleParameter("USERNAME", username));
            OracleCommand moderatorCommand = new OracleCommand(moderatoryQuery, conn);
            moderatorCommand.Parameters.Add(new OracleParameter("USERNAME", username));
            OracleDataReader dataReader;
            User returnUser = null;

            List<Rights> functions = new List<Rights>();

            try
            {
                dataReader = redactorCommand.ExecuteReader();
                if (dataReader.HasRows)
                {
                    functions.Add(Rights.Editor);
                }

                dataReader = moderatorCommand.ExecuteReader();
                if (dataReader.HasRows)
                {
                    functions.Add(Rights.Moderator);
                }

                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    returnUser = new User(dataReader["USERNAME"].ToString(), dataReader["email"].ToString(), functions);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }

            return returnUser;
        }
コード例 #3
0
ファイル: MainAdministration.cs プロジェクト: pieper126/SE22
 /// <summary>
 /// Creates a new thread
 /// </summary>
 /// <param name="user"> User that posted this thread</param>
 /// <param name="content">content of the first post</param>
 /// <param name="category">category this thread belongs to</param>
 /// <param name="threadName">name of this thread</param>
 public static void CreateNewThread(User user, string content, ForumCategory category, string threadName)
 {
     DatabaseManager.CreateNewThread(user.Username, category.ID, content, threadName);
 }
コード例 #4
0
ファイル: MainAdministration.cs プロジェクト: pieper126/SE22
 /// <summary>
 /// create a new post
 /// </summary>
 /// <param name="user">User that posted this post</param>
 /// <param name="content">Content of this post</param>
 /// <param name="thread">thread this post belongs to</param>
 public static void CreateNewPost(User user, string content, ForumThread thread)
 {
     DatabaseManager.CreateNewPost(thread.ID, content, user.Username);
 }