protected void Auth(object sender, EventArgs e) { try { string pass = passbox.Text; var _db = new SnipContext(); IQueryable<Snip> query = _db.Snips; var d = Codec.Decode(id); query = query.Where(p => p.SnipID == d); if (query != null) { if (query.First().SnipAccessType != 1) Response.Redirect(GetRouteUrl("ViewByID", new { snipid = id })); if (query.First().SnipAccessPass != null && query.First().SnipAccessPass == pass) { Session[id] = "True"; Response.Redirect(GetRouteUrl("ViewByID", new { snipid = id })); } } err.Text = "Wrong password! Try Again."; passbox.Text = null; } catch { err.Text = "Sorry! Something went wrong."; } }
public IQueryable<Snip> GetMySnips() { try { var _db = new SnipContext(); IQueryable<Snip> query = _db.Snips; var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>(); string s = manager.GetEmail(User.Identity.GetUserId()); query = query.Where(p => p.SnipCreatedBy == s); return query; } catch { return null; } }
protected void Button1_Click(object sender, EventArgs e) { try { var _db = new SnipContext(); var newsnip = new Snip(); if (TextBox1.Text == "") newsnip.SnipTitle = "Untitled"; else newsnip.SnipTitle = TextBox1.Text; newsnip.SnipLanguage = langitems[DropDownList1.SelectedIndex].Text; newsnip.SnipCreatedTime = DateTime.Now; if (DropDownList2.SelectedIndex == 6) newsnip.SnipExpirationTime = DateTime.MaxValue; else { TimeSpan result; TimeSpan.TryParse(timeitems[DropDownList2.SelectedIndex].Value, out result); newsnip.SnipExpirationTime = newsnip.SnipCreatedTime.Add(result); } if (User.Identity.IsAuthenticated) { var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>(); newsnip.SnipCreatedBy = manager.GetEmail(User.Identity.GetUserId()); } else { newsnip.SnipCreatedBy = "*****@*****.**"; } if(DropDownList3.SelectedIndex == 2 && !User.Identity.IsAuthenticated) { err.Text = "You cannot create Private Snips!"; return; } else newsnip.SnipAccessType = DropDownList3.SelectedIndex; if(DropDownList3.SelectedIndex == 1 && TextBox2.Text == "") { err.Text = "Password cannot be left empty for Protected mode!"; } else { newsnip.SnipAccessPass = TextBox2.Text; if (TextArea1.Text == "") { err.Text = "Textbox cannot be left empty!"; } else { newsnip.SnipContent = TextArea1.Text; _db.Snips.Add(newsnip); _db.SaveChanges(); string s = Codec.Encode(newsnip.SnipID); TextBox1.Text = s; Response.Redirect(GetRouteUrl("ViewByID", new { snipid = s }),false); } } } catch { err.Text = "Sorry! Something went wrong."; } }