Beispiel #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.Cookies["SNID"] != null)
        {
            LogStatus.DeleteCookies();
        }

        if (LogStatus.IsLoggedIn() <= 0)
        {
            Response.Redirect("home.aspx");
        }

        randomizer = random.Next(1, 46);

        SqlConnection conn = new SqlConnection(@"Data Source=(local)\sqlexpress;Initial Catalog=friendsforever;Integrated Security=True"); //Create Connection

        conn.Open();

        using (SqlCommand command = new SqlCommand("SELECT quote FROM quotes WHERE q_id = @q_id", conn))
        {
            command.CommandType = CommandType.Text;
            command.Parameters.AddWithValue("@q_id", randomizer);
            SqlDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                quote = reader["quote"].ToString();
            }
        }

        conn.Close();
    }
Beispiel #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (LogStatus.IsLoggedIn() > 0)
     {
         Response.Redirect("profile.aspx");
     }
 }
    protected void LogoutButton_Click(object sender, EventArgs e)
    {
        if (alldevices.Checked)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=(local)\sqlexpress;Initial Catalog=friendsforever;Integrated Security=True"); //Create Connection

            conn.Open();

            using (SqlCommand command = new SqlCommand("DELETE FROM login_tokens WHERE user_id = @user_id", conn))
            {
                command.Parameters.AddWithValue("@user_id", LogStatus.IsLoggedIn());
                command.ExecuteNonQuery();
            }

            conn.Close();

            HttpCookie SNID = new HttpCookie("SNID");
            SNID.Expires = DateTime.Now.AddHours(-1);
            HttpContext.Current.Response.Cookies.Add(SNID);

            HttpCookie SNID_ = new HttpCookie("SNID_");
            SNID_.Expires = DateTime.Now.AddHours(-1);
            HttpContext.Current.Response.Cookies.Add(SNID_);

            Response.Redirect("home.aspx");
        }
        else
        {
            bool cookieExists = HttpContext.Current.Request.Cookies["SNID"] != null;

            if (cookieExists)
            {
                SqlConnection conn = new SqlConnection(@"Data Source=(local)\sqlexpress;Initial Catalog=friendsforever;Integrated Security=True"); //Create Connection

                conn.Open();

                using (SqlCommand command = new SqlCommand("DELETE FROM login_tokens WHERE token = @token", conn))
                {
                    command.Parameters.AddWithValue("@token", HttpContext.Current.Request.Cookies["SNID"].Value);
                    command.ExecuteNonQuery();
                }

                conn.Close();

                HttpCookie SNID = new HttpCookie("SNID");
                SNID.Expires = DateTime.Now.AddHours(-1);
                HttpContext.Current.Response.Cookies.Add(SNID);

                HttpCookie SNID_ = new HttpCookie("SNID_");
                SNID_.Expires = DateTime.Now.AddHours(-1);
                HttpContext.Current.Response.Cookies.Add(SNID_);

                Response.Redirect("home.aspx");
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.Cookies["SNID"] != null)
        {
            LogStatus.DeleteCookies();
        }

        if (LogStatus.IsLoggedIn() <= 0)
        {
            Response.Redirect("home.aspx");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.Cookies["SNID"] != null)
        {
            LogStatus.DeleteCookies();
        }

        if (LogStatus.IsLoggedIn() <= 0)
        {
            Response.Redirect("home.aspx");
        }

        SqlConnection conn = new SqlConnection(@"Data Source=(local)\sqlexpress;Initial Catalog=friendsforever;Integrated Security=True"); //Create Connection

        conn.Open();

        using (SqlCommand command = new SqlCommand("SELECT COUNT(u_name) AS count FROM users WHERE u_id <> @user_id", conn))
        {
            command.Parameters.AddWithValue("@user_id", LogStatus.IsLoggedIn());
            command.CommandType = CommandType.Text;
            SqlDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                count = Convert.ToInt32(reader["count"].ToString());
            }
        }

        conn.Close();

        users = new string[count];

        conn.Open();

        using (SqlCommand command = new SqlCommand("SELECT u_name FROM users WHERE u_id <> @user_id", conn))
        {
            command.Parameters.AddWithValue("@user_id", LogStatus.IsLoggedIn());
            command.CommandType = CommandType.Text;
            SqlDataReader reader = command.ExecuteReader();

            int i = 0;
            while (reader.Read())
            {
                users[i] = reader["u_name"].ToString();
                i++;
            }
        }

        conn.Close();
    }
    protected void post_Click(object sender, EventArgs e)
    {
        if (message.Text.Length > 0)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=(local)\sqlexpress;Initial Catalog=friendsforever;Integrated Security=True");

            conn.Open();

            using (SqlCommand command = new SqlCommand("SELECT u_name FROM users WHERE u_id=@u_id", conn))
            {
                command.Parameters.AddWithValue("@u_id", LogStatus.IsLoggedIn());
                SqlDataReader reader = command.ExecuteReader();

                if (reader.Read())
                {
                    u_name = reader["u_name"].ToString();
                }
            }

            conn.Close();


            conn.Open();

            using (SqlCommand command = new SqlCommand("INSERT INTO messages VALUES (@u_name, @msg, @datetime)", conn))
            {
                command.Parameters.AddWithValue("@u_name", u_name);
                command.Parameters.AddWithValue("@msg", message.Text);
                command.Parameters.AddWithValue("@datetime", dateTime_Indian);
                command.ExecuteNonQuery();
            }

            conn.Close();

            Response.Redirect("posts.aspx");
        }
    }
Beispiel #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.Cookies["SNID"] != null)
        {
            LogStatus.DeleteCookies();
        }

        if (LogStatus.IsLoggedIn() <= 0)
        {
            Response.Redirect("home.aspx");
        }

        SqlConnection conn = new SqlConnection(@"Data Source=(local)\sqlexpress;Initial Catalog=friendsforever;Integrated Security=True"); //Create Connection

        conn.Open();

        using (SqlCommand command = new SqlCommand("SELECT f_name, l_name, u_name, email, dob, gender FROM users WHERE u_id = @user_id", conn))
        {
            command.Parameters.AddWithValue("@user_id", LogStatus.IsLoggedIn());
            command.CommandType = CommandType.Text;
            SqlDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                f_name = reader["f_name"].ToString();
                l_name = reader["l_name"].ToString();
                u_name = reader["u_name"].ToString();
                email  = reader["email"].ToString();
                dob    = reader["dob"].ToString();
                gender = reader["gender"].ToString();
            }
        }

        conn.Close();

        conn.Open();

        using (SqlCommand command = new SqlCommand("SELECT COUNT(following) AS following FROM follow WHERE following=@user_id", conn))
        {
            command.Parameters.AddWithValue("@user_id", LogStatus.IsLoggedIn());
            command.CommandType = CommandType.Text;
            SqlDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                following = Convert.ToInt32(reader["following"].ToString());
            }
        }

        conn.Close();

        conn.Open();

        using (SqlCommand command = new SqlCommand("SELECT COUNT(being_followed) AS followers FROM follow WHERE being_followed=@user_id", conn))
        {
            command.Parameters.AddWithValue("@user_id", LogStatus.IsLoggedIn());
            command.CommandType = CommandType.Text;
            SqlDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                followers = Convert.ToInt32(reader["followers"].ToString());
            }
        }

        conn.Close();
    }
Beispiel #8
0
    protected void followButton_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(@"Data Source=(local)\sqlexpress;Initial Catalog=friendsforever;Integrated Security=True"); //Create Connection

        conn.Open();

        using (SqlCommand command = new SqlCommand("SELECT * FROM follow WHERE being_followed=@ou_id AND following= @u_id", conn))
        {
            command.Parameters.AddWithValue("@ou_id", ou_id);
            command.Parameters.AddWithValue("@u_id", LogStatus.IsLoggedIn());
            command.CommandType = CommandType.Text;
            SqlDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                isFollowing       = true;
                followButton.Text = "Unfollow";
            }
            else
            {
                isFollowing       = false;
                followButton.Text = "Follow";
            }
        }

        conn.Close();


        if (!isFollowing)
        {
            conn.Open();

            using (SqlCommand command = new SqlCommand("INSERT INTO follow VALUES (@following, @being_followed)", conn))
            {
                command.Parameters.AddWithValue("@following", LogStatus.IsLoggedIn());
                command.Parameters.AddWithValue("@being_followed", ou_id);
                command.ExecuteNonQuery();
            }

            conn.Close();

            followButton.Text = "Unfollow";
        }
        else
        {
            conn.Open();

            using (SqlCommand command = new SqlCommand("DELETE FROM follow WHERE following = @following AND being_followed = @being_followed", conn))
            {
                command.Parameters.AddWithValue("@following", LogStatus.IsLoggedIn());
                command.Parameters.AddWithValue("@being_followed", ou_id);
                command.ExecuteNonQuery();
            }

            conn.Close();

            followButton.Text = "Follow";
        }

        Response.Redirect("otherprofiles.aspx?ou_id=" + ou_id);
    }