コード例 #1
0
ファイル: FLogin.cs プロジェクト: ugeHidalgo/TrainIt
        //Try to validate password, and then goes into the app.
        private void btAccept_Click(object sender, EventArgs e)
        {
            Boolean sigue = true;

            //Takes user ID clicked
            userNameGiven = txtUser.Text;
            userPassGiven = txtPass.Text;

            //Verify if an user has been entered.
            if (userNameGiven=="")
            {
                MessageBox.Show("No has introducido un nombre de ususario", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Error);
                sigue = false;
            }

            //Verify password
            if (sigue)
            {
                Users aUser = new Users(-1, "", "", DateTime.Now, "", "", "", "");
                aUser = aUser.verifyPass (userNameGiven, userPassGiven, connString);
                userIDGiven = aUser.userID;
                if (aUser.userID == -1)
                {
                    sigue = false;
                    MessageBox.Show("Usuario o contraseña incorrectos", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (aUser.userID == -2)
                {
                    sigue = false;
                    MessageBox.Show("No se puede conectar con el servidor de datos");
                }

            }

            //give or not access depending de result of the query
            if (sigue)
            {
                accessGranted = true;
                Global.userUsed = Global.userUsed.findUserByUserID(connString, userIDGiven);
                Global.userNameWorking = userNameGiven;
                Close();
            }
        }
コード例 #2
0
ファイル: UsersTest.cs プロジェクト: ugeHidalgo/TrainIt
        public void Users_loginTest()
        {
            //Creates an User with data.
            Users aUser = new Users(-1, "name", "", DateTime.Now, "", "", "", "");

            //Try to save first
            aUser = aUser.LoadData(-1, "Nombre", "Apellido", Convert.ToDateTime("12/04/1982"), "NickToDel", "12345678", "12345678", "*****@*****.**");
            aUser = aUser.saveUserData(connString);
            Assert.AreNotEqual(-1, aUser.userID); //1=save data without any problem.

            //Try to find it and take the userID
            //findUserByUserName returns a user if find, if not find return a user wit UserID=-1
            string expectedUserName = aUser.userName;
            Int64 userIDToDelete = aUser.userID;
            aUser = aUser.findUserByUserName(connString, expectedUserName);
            Assert.AreEqual(expectedUserName, aUser.userName);
            Int64 expectedUserID = aUser.userID;

            //Correct login
            string givenPassword = "******";
            aUser = aUser.verifyPass(aUser.userName, givenPassword, connString);
            Assert.AreNotEqual(-1, aUser.userID);

            //Uncorrect Login
            givenPassword = "";
            aUser = aUser.verifyPass(aUser.userName, givenPassword, connString);
            Assert.AreEqual(-1, aUser.userID);

            //Try to Delete previous saved user.
            int res = Users.deleteUserByUserID(connString, userIDToDelete);
            Assert.AreEqual(1, res); //Deleted with success
        }
コード例 #3
0
ファイル: UsersTest.cs プロジェクト: ugeHidalgo/TrainIt
        public void Users_UpdateTestWithPass()
        {
            //Creates an User with data.
            Users aUser = new Users(-1, "name", "", DateTime.Now, "", "", "", "");

            //Try to save first
            aUser = aUser.LoadData(-1, "Nombre", "Apellido", Convert.ToDateTime("12/04/1982"), "NickToDel", "12345678", "12345678", "*****@*****.**");
            aUser = aUser.saveUserData(connString);
            Assert.AreNotEqual(-1, aUser.userID); //1=save data without any problem.

            //Try to find it and take the userID
            //findUserByUserName returns a user if find, if not find return a user wit UserID=-1
            string expectedUserName = aUser.userName;
            aUser = aUser.findUserByUserName(connString, expectedUserName);
            Assert.AreEqual(expectedUserName, aUser.userName); //User finded
            Int64 expectedUserID = aUser.userID;

            //Try to Update previous saved user.
            string newPass="******";
            aUser.userPass = newPass;
            aUser.userConfirmPassword = newPass;
            aUser = aUser.updateUserData(connString, true);
            aUser = aUser.verifyPass(aUser.userName, newPass, connString);
            Assert.AreNotEqual(-1, aUser.userID); //Verify if new password was stored correctly

            //Try to Delete previous saved user.
            Int64 res = Users.deleteUserByUserID(connString, aUser.userID);
            Assert.AreEqual(1, res); //Deleted with success

            ////Try to find it
            ////findUserByUserName returns a user if find, if not find return a user wit UserID=-1
            //expectedUserName = aUser.userName;
            //aUser = aUser.findUserByUserName(connString, expectedUserName);
            //Assert.AreEqual(-1, aUser.userID); //user not found because was deleted
        }