Exemplo n.º 1
0
        protected void LogIn(object sender, EventArgs e)
        {
            user = userData.getUserData(UserName.Text, Password.Text);
            Session["User"] = user;

            lblErrorUsuario.Visible = false;
            lblErrorContraseña.Visible = false;

            if (UserName.Text.Equals("") || Password.Text.Equals(""))
            {
                if (UserName.Text.Equals(""))
                lblErrorUsuario.Visible = true;
                if (Password.Text.Equals(""))
                {
                    lblErrorContraseña.Text = "Contraseña no puede estar vacido";
                    lblErrorContraseña.Visible = true;
                }
            }
            else
            {
                if (user.Role == 0 && user.Name == null && user.Password == null)
                {
                    lblErrorContraseña.Text = "Usuario o Contraseña estan incorrectos";
                    lblErrorContraseña.Visible = true;
                }
                else
                {
                    Response.Redirect("/Default.aspx");
                }
            }
        }
Exemplo n.º 2
0
        public User getUserEdit(int id)
        {
            User user = new User();
            //open database connection
            SqlConnection con = DatabaseConnection("open");
            SqlCommand sqlCommand;
            string databaseCommand = "SELECT id, name, mail, license, password, idRol FROM [LabControl].[dbo].[User] WHERE id =" + id;
            try
            {
                sqlCommand = new SqlCommand(databaseCommand, con);
                SqlDataReader reader = sqlCommand.ExecuteReader();
                if (reader.Read())
                {
                    user.Id = reader.GetInt32(reader.GetOrdinal("id"));
                    user.Name = reader.GetString(reader.GetOrdinal("name"));
                    user.Email = reader.GetString(reader.GetOrdinal("mail"));
                    user.License = reader.GetInt32(reader.GetOrdinal("license"));
                    user.Password = reader.GetString(reader.GetOrdinal("password"));
                    user.Role = reader.GetInt32(reader.GetOrdinal("idRol"));
                }
                sqlCommand.Dispose();
            }
            catch (SqlException sqlException)
            {
                Console.WriteLine("Database error: " + sqlException.ToString());
            }
            finally
            {
                DatabaseConnection("close");

            }
            return user;
        }
Exemplo n.º 3
0
        public Boolean proxyUsuario(User user)
        {
            try
            {
                if (user.Role == 1 || user.Role == 2 || user.Role == 3)
                {

                    return true;
                }
                else
                    return false;
            }
            catch (NullReferenceException)
            {
                return false;
            }
        }
Exemplo n.º 4
0
        public Boolean proxyLogistica(User user)
        {
            try
            {
                if (user.Role == 2)
                {

                    return true;
                }
                else
                    return false;
            }
            catch (NullReferenceException)
            {
                return false;
            }
        }
Exemplo n.º 5
0
        //hola
        public Boolean proxyAdmin(User user)
        {
            try
            {
                if (user.Role == 1)
                {

                    return true;
                }
                else
                    return false;
            }
            catch (NullReferenceException)
            {
                return false;
            }
        }
Exemplo n.º 6
0
        public void deleteUser(User user)
        {
            SqlConnection con = DatabaseConnection("open");
            SqlCommand sqlCommand;
            string databaseCommand = "DELETE FROM Usuario WHERE id ="+user.Id+" AND nombre = '"+user.Name+"' AND correo = '"+user.Email+"' AND carnet = "+user.StudentId+" AND clave = '"+user.Password+"' AND idRol = "+user.Role+"";
            try
            {

                sqlCommand = new SqlCommand(databaseCommand, con);
                SqlDataReader reader = sqlCommand.ExecuteReader();
                sqlCommand.Dispose();
                DatabaseConnection("close");
            }

            catch (SqlException sqlException)
            {
                Console.WriteLine("Database error: " + sqlException.ToString());
            }
        }
Exemplo n.º 7
0
        public User getUserData(string mail, string password)
        {
            User user = new User();

            //open database connection
            SqlConnection con = DatabaseConnection("open");
            SqlCommand sqlCommand;

            sqlCommand = new SqlCommand("readUserData", con);
            sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue("@mail", mail);
            sqlCommand.Parameters.AddWithValue("@password", password);
            SqlDataReader reader = sqlCommand.ExecuteReader();
            try
            {
                if (reader.Read())
                {
                    user.Id = reader.GetInt32(reader.GetOrdinal("id"));
                    user.Name = reader.GetString(reader.GetOrdinal("name"));
                    user.Email = reader.GetString(reader.GetOrdinal("mail"));
                    user.License = reader.GetInt32(reader.GetOrdinal("license"));
                    user.Password = reader.GetString(reader.GetOrdinal("password"));
                    user.Role = reader.GetInt32(reader.GetOrdinal("idRol"));
                }
                sqlCommand.Dispose();
            }
            catch (SqlException sqlException)
            {
                Console.WriteLine("Database error: " + sqlException.ToString());
            }
            finally
            {
                DatabaseConnection("close");

            }
            return user;
        }
Exemplo n.º 8
0
        public User getUserData(string nombre, string clave)
        {
            User user = new User();

            //open database connection
            SqlConnection con = DatabaseConnection("open");
            SqlCommand sqlCommand;
            string databaseCommand = "SELECT id, nombre, correo, carnet, clave, idRol FROM Usuario WHERE nombre = '" + nombre + "' AND clave = '" + clave + "'";
            try
            {

                sqlCommand = new SqlCommand(databaseCommand, con);
                SqlDataReader reader = sqlCommand.ExecuteReader();

                if (reader.Read())
                {

                    user.Id = reader.GetInt32(reader.GetOrdinal("id"));
                    user.Name = reader.GetString(reader.GetOrdinal("nombre"));
                    user.Email = reader.GetString(reader.GetOrdinal("correo"));
                    user.StudentId = reader.GetInt32(reader.GetOrdinal("carnet"));
                    user.Password = reader.GetString(reader.GetOrdinal("clave"));
                    user.Role = reader.GetInt32(reader.GetOrdinal("idRol"));

                }
                sqlCommand.Dispose();
                DatabaseConnection("close");

            }
            catch (SqlException sqlException)
            {
                Console.WriteLine("Database error: " + sqlException.ToString());

            }
            return user;
        }
Exemplo n.º 9
0
 public Register()
 {
     user = new User();
 }
Exemplo n.º 10
0
        public void updatePassword(User user)
        {
            //open database connection
            SqlConnection con = DatabaseConnection("open");
            SqlCommand sqlCommand;

            try
            {
                sqlCommand = new SqlCommand("updatePassword", con);
                sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                sqlCommand.Parameters.AddWithValue("@password", user.Password);
                sqlCommand.Parameters.AddWithValue("@id", user.Id);
                sqlCommand.Parameters.AddWithValue("@name", user.Name);
                sqlCommand.Parameters.AddWithValue("@mail", user.Email);
                sqlCommand.Parameters.AddWithValue("@license", user.License);
                sqlCommand.Parameters.AddWithValue("@idRol", user.Role);
                SqlDataReader reader = sqlCommand.ExecuteReader();
                sqlCommand.Dispose();
            }
            catch (SqlException sqlException)
            {
                Console.WriteLine("Database error: " + sqlException.ToString());
            }
            finally
            {
                DatabaseConnection("close");

            }
        }
Exemplo n.º 11
0
        public List<User> readUser()
        {
            List<User> userList = new List<User>();
            User user = new User();

            //open database connection
            SqlConnection con = DatabaseConnection("open");
            SqlCommand sqlCommand;

            try
            {
                sqlCommand = new SqlCommand("readUser", con);
                SqlDataReader reader = sqlCommand.ExecuteReader();
                while (reader.Read())
                {
                    user.Id = reader.GetInt32(reader.GetOrdinal("id"));
                    user.Name = reader.GetString(reader.GetOrdinal("name"));
                    user.Email = reader.GetString(reader.GetOrdinal("mail"));
                    user.License = reader.GetInt32(reader.GetOrdinal("license"));
                    user.Password = reader.GetString(reader.GetOrdinal("password"));
                    user.Role = reader.GetInt32(reader.GetOrdinal("idRol"));
                    userList.Add(user);
                }
                sqlCommand.Dispose();
            }
            catch (SqlException sqlException)
            {
                Console.WriteLine("Database error: " + sqlException.ToString());
            }
            finally
            {
                DatabaseConnection("close");

            }
            return userList;
        }
Exemplo n.º 12
0
        public List<User> readUser()
        {
            List<User> userList = new List<User>();
            User user = new User();

              //open database connection
            SqlConnection con = DatabaseConnection("open");
            SqlCommand sqlCommand;
            string databaseCommand = "SELECT * FROM Usuario";
            try
            {

                sqlCommand = new SqlCommand(databaseCommand, con);
                SqlDataReader reader = sqlCommand.ExecuteReader();

                while (reader.Read())
                {

                    user.Id = reader.GetInt32(reader.GetOrdinal("id"));
                    user.Name = reader.GetString(reader.GetOrdinal("nombre"));
                    user.Email = reader.GetString(reader.GetOrdinal("correo"));
                    user.StudentId = reader.GetInt32(reader.GetOrdinal("carnet"));
                    user.Password = reader.GetString(reader.GetOrdinal("clave"));
                    user.Role = reader.GetInt32(reader.GetOrdinal("idRol"));

                    userList.Add(user);
                }
                sqlCommand.Dispose();
                DatabaseConnection("close");

            }
            catch (SqlException sqlException)
            {
                Console.WriteLine("Database error: " + sqlException.ToString());

            }
            return userList;
        }
Exemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            user = (User)Session["User"];
            try
            {
                if (proxy.proxyAdmin(user))
                {
                    admin.Visible = true;
                }

                else
                {
                    admin.Visible = false;
                }
            }
            catch (NullReferenceException)
            {
                admin.Visible = false;
            }

            try
            {
                if (proxy.proxyUsuario(user))
                {
                    userP.Visible = true;
                }

                else
                {
                    userP.Visible = false;
                }
            }
            catch (NullReferenceException)
            {
                userP.Visible = false;
            }

            try
            {
                if (proxy.proxyUsuario(user))
                {
                    login.Visible = false;
                }
                else
                    login.Visible = true;
            }
            catch (NullReferenceException)
            {
                login.Visible = true;

            }

            try
            {
                if (proxy.proxyUsuario(user))
                {
                    logout.Visible = true;
                }
                else
                    logout.Visible = false;
            }
            catch (NullReferenceException)
            {
                logout.Visible = false;

            }
        }