Browse Source

Fix cookies

v5
Laura Hausmann 4 weeks ago
parent
commit
4407801a36
Signed by: zotan GPG Key ID: 5EC1D38FFC321311
4 changed files with 15 additions and 7 deletions
  1. +2
    -2
      Pages/Conference.cshtml
  2. +2
    -2
      Pages/Index.cshtml
  3. +2
    -2
      Pages/Info.cshtml
  4. +9
    -1
      c3stream.cs

+ 2
- 2
Pages/Conference.cshtml View File

@ -9,7 +9,7 @@
return;
}
c3stream.UpdateCookie(Request, Response, $"/Conference?c={Request.Query["c"]}");
var cookie = c3stream.UpdateCookie(Request, Response, $"/Conference?c={Request.Query["c"]}");
ViewData["Title"] = Request.Query["c"];
var wc = new WebClient();
var conference = c3stream.Conferences.First(c => c.Acronym == Request.Query["c"]);
@ -36,7 +36,7 @@
</thead>
<tbody>
@foreach (var talk in Request.Query["orderby"] == "published" ? conference.Talks.OrderByDescending(p => p.ReleaseDate) : conference.Talks.OrderBy(p => p.Date)) {
var state = states.FirstOrDefault(p => p.TalkId == talk.Guid && p.UserId == Request.Cookies["bookmark"])?.State;
var state = states.FirstOrDefault(p => p.TalkId == talk.Guid && p.UserId == cookie)?.State;
var isWatched = state == "watched";
var isMarked = state == "marked";
var file = $"{talk.Slug}.mp4";


+ 2
- 2
Pages/Index.cshtml View File

@ -2,13 +2,13 @@
@model IndexModel
@{
ViewData["Title"] = "Home";
c3stream.UpdateCookie(Request, Response, "/");
var cookie = c3stream.UpdateCookie(Request, Response, "/");
}
<div style="text-align: center">
<h1>Welcome to c3stream!</h1>
Your bookmark link:<br/>
<code onclick="copyToClipboard(this)">https://@Request.Host.Value?bookmark=@Request.Cookies["bookmark"]</code><br/><br/>
<code onclick="copyToClipboard(this)">https://@Request.Host.Value?bookmark=@cookie</code><br/><br/>
<div class="btn-group">
@foreach (var conf in c3stream.Conferences) {
<a role="button" class="btn btn-primary" href="/Conference?c=@conf.Acronym">@conf.Acronym</a>


+ 2
- 2
Pages/Info.cshtml View File

@ -10,12 +10,12 @@
return;
}
c3stream.UpdateCookie(Request, Response, $"/Info?guid={Request.Query["guid"]}");
var cookie = c3stream.UpdateCookie(Request, Response, $"/Info?guid={Request.Query["guid"]}");
await using var db = new Database.DbConn();
var talk = c3stream.GetEventByGuid(Request.Query["guid"]);
var state = db.States.FirstOrDefault(p => p.TalkId == Request.Query["guid"].ToString() && p.UserId == Request.Cookies["bookmark"])?.State;
var state = db.States.FirstOrDefault(p => p.TalkId == Request.Query["guid"].ToString() && p.UserId == cookie)?.State;
if (talk == null) {
Response.Redirect("/");
return;


+ 9
- 1
c3stream.cs View File

@ -86,20 +86,28 @@ namespace c3stream {
}
}
public static void UpdateCookie(HttpRequest request, HttpResponse response, string redirectUri) {
public static string UpdateCookie(HttpRequest request, HttpResponse response, string redirectUri) {
var cookie = "";
//if new bookmark is in uri
if (request.Query.ContainsKey("bookmark") && Guid.TryParseExact(request.Query["bookmark"], "D", out _)) {
response.Cookies.Append("bookmark", request.Query["bookmark"], new CookieOptions {Expires = DateTimeOffset.MaxValue});
cookie = request.Query["bookmark"];
}
//if no cookie exists or cookie is invalid
else if (!request.Cookies.ContainsKey("bookmark") || !Guid.TryParseExact(request.Cookies["bookmark"], "D", out _)) {
var guid = Guid.NewGuid().ToString();
response.Cookies.Append("bookmark", guid, new CookieOptions {Expires = DateTimeOffset.MaxValue});
cookie = guid;
}
else {
cookie = request.Cookies["bookmark"];
}
if (request.Query.ContainsKey("bookmark")) {
response.Redirect(redirectUri);
}
return cookie;
}
public static Event GetEventByGuid(string guid) {


Loading…
Cancel
Save