Exemplo n.º 1
0
 protected void LoginUser(object sender, EventArgs e)
 {
     DatabaseContext dc = new DatabaseContext();
     IEnumerable<User> getUser = from user in dc.Users
                   where ( user.mail == username.Text ) && (user.password == password.Text)
                   select user;
     if(getUser.Count() > 0)
         Session["user"] = getUser.First();
     if (Session["user"] != null)
         Form.InnerText = "You are logged!";
     if (Session["user"] != null && still_logged.Checked)
     {
         Random r = new Random();
         Models.User _user = Session["user"] as Models.User;
         string id = r.NextDouble().ToString();
         Response.Cookies.Add(new HttpCookie("OpenPasteLogin", id));
         Response.Cookies["OpenPasteLogin"].Expires = DateTime.Now.AddDays(int.Parse(time.Text));
         using(var ctx = new Models.DatabaseContext())
         {
             Models.LoggedByCookie lbc = new Models.LoggedByCookie()
             {
                 mail = _user.mail,
                 session_id = id,
             };
             ctx.LoggedUsers.Add(lbc);
             ctx.SaveChanges();
         }
     }
 }
Exemplo n.º 2
0
 protected List<Models.Paste> getPastes()
 {
     List<Models.Paste> pastes;
     using (var ctx = new DatabaseContext())
     {
         pastes = ctx.Pastes.ToList<Models.Paste>();
     }
     return pastes;
 }
Exemplo n.º 3
0
 protected void RestoreData()
 {
     using (var ctx = new Models.DatabaseContext())
     {
         abuses_list = ctx.Abuses.ToList();
         abuses.DataSource = abuses_list;
         abuses.DataBind();
     }
 }
Exemplo n.º 4
0
 protected void Delete_Paste(object sender, CommandEventArgs args)
 {
     using (var ctx = new Models.DatabaseContext())
     {
         int id = int.Parse((String)args.CommandArgument);
         Models.Abuse a =
             (from abuse in ctx.Abuses where abuse.id == id select abuse).First();
         ctx.Pastes.Remove(a.Paste);
         ctx.SaveChanges();
         RestoreData();
     }
 }
Exemplo n.º 5
0
 protected void Session_Start(object sender, EventArgs e)
 {
     if (Session["user"] == null)
     {
         using (var ctx = new Models.DatabaseContext())
             if (Session["user"] == null && Request.Cookies["OpenPasteLogin"] != null)
             {
                 string id = Request.Cookies["OpenPasteLogin"].Value;
                 var db = (from cookie in ctx.LoggedUsers where cookie.session_id == id select cookie);
                 if (db.Count() == 0) return;
                 Models.User user = db.First().User;
                 Session["user"] = user;
                 Response.Redirect("Pastes.aspx");
             }
     }
 }
Exemplo n.º 6
0
        protected void PostPaste(object sender, EventArgs e)
        {
            using(var ctx = new DatabaseContext())
            {
                User user;
                if (Session["user"] == null)
                    user = (from us in ctx.Users where us.mail == "*****@*****.**" select us).First();
                else
                    user = (User)Session["user"];

                ctx.Pastes.Add(new Models.Paste
                {
                    mail = user.mail,
                    codeType = lang.Text,
                    content = code.Text,
                    paste_time = DateTime.Now
                });
                ctx.SaveChanges();
                Response.Redirect("Pastes.aspx");
            }
        }
Exemplo n.º 7
0
        protected void form_submit_Click(object sender, EventArgs e)
        {
            Validate();
            if(!Page.IsValid)
            {
                return;
            }

            //here will load data
            string name = this.register_name.Text;
            string surname = this.register_surname.Text;
            string email = this.register_mail.Text;
            string password = this.register_password.Text;
            string birthdate = this.register_birth_date.ToString();

            using (var ctx = new DatabaseContext())
            {
                ctx.Users.Add(
                    new User
                    {
                        mail = email,
                        surname = surname,
                        password = password,
                        name = name
                    });
                try
                {
                    ctx.SaveChanges();
                } catch (System.Data.SqlClient.SqlException exception)
                {
                    Form.InnerText = "User is existing";
                }
                    List<User> users = ctx.Users.ToList<User>();
            }

            Form.InnerText = "User was registered, thank you for it!";
            Response.Redirect("Pastes.aspx");
        }
Exemplo n.º 8
0
 public IQueryable<OpenPaste.Models.Paste> GetLastPastes()
 {
     var ctx = new DatabaseContext();
     return ctx.Pastes;
 }
Exemplo n.º 9
0
 protected void Report(object sender, EventArgs e)
 {
     if (Session["user"] == null) return;
     using (var context = new DatabaseContext())
     {
         Models.Paste p = (from paste in context.Pastes where paste.pasteId == pasteId select paste).First();
         Abuse a = new Abuse() {
             Paste = p,
             mail = (Session["user"] as Models.User).mail,
             reason = abuse_text.Text
         };
         context.Abuses.Add(a);
         context.SaveChanges();
         sendMessage("Abuse deposed on " + abuse_text.Text);
     }
 }