Fix cookies
This commit is contained in:
parent
d2a2c3cd5b
commit
4407801a36
|
@ -9,7 +9,7 @@
|
||||||
return;
|
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"];
|
ViewData["Title"] = Request.Query["c"];
|
||||||
var wc = new WebClient();
|
var wc = new WebClient();
|
||||||
var conference = c3stream.Conferences.First(c => c.Acronym == Request.Query["c"]);
|
var conference = c3stream.Conferences.First(c => c.Acronym == Request.Query["c"]);
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var talk in Request.Query["orderby"] == "published" ? conference.Talks.OrderByDescending(p => p.ReleaseDate) : conference.Talks.OrderBy(p => p.Date)) {
|
@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 isWatched = state == "watched";
|
||||||
var isMarked = state == "marked";
|
var isMarked = state == "marked";
|
||||||
var file = $"{talk.Slug}.mp4";
|
var file = $"{talk.Slug}.mp4";
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
@model IndexModel
|
@model IndexModel
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Home";
|
ViewData["Title"] = "Home";
|
||||||
c3stream.UpdateCookie(Request, Response, "/");
|
var cookie = c3stream.UpdateCookie(Request, Response, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
<div style="text-align: center">
|
<div style="text-align: center">
|
||||||
<h1>Welcome to c3stream!</h1>
|
<h1>Welcome to c3stream!</h1>
|
||||||
Your bookmark link:<br/>
|
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">
|
<div class="btn-group">
|
||||||
@foreach (var conf in c3stream.Conferences) {
|
@foreach (var conf in c3stream.Conferences) {
|
||||||
<a role="button" class="btn btn-primary" href="/Conference?c=@conf.Acronym">@conf.Acronym</a>
|
<a role="button" class="btn btn-primary" href="/Conference?c=@conf.Acronym">@conf.Acronym</a>
|
||||||
|
|
|
@ -10,12 +10,12 @@
|
||||||
return;
|
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();
|
await using var db = new Database.DbConn();
|
||||||
|
|
||||||
var talk = c3stream.GetEventByGuid(Request.Query["guid"]);
|
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) {
|
if (talk == null) {
|
||||||
Response.Redirect("/");
|
Response.Redirect("/");
|
||||||
return;
|
return;
|
||||||
|
|
10
c3stream.cs
10
c3stream.cs
|
@ -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 new bookmark is in uri
|
||||||
if (request.Query.ContainsKey("bookmark") && Guid.TryParseExact(request.Query["bookmark"], "D", out _)) {
|
if (request.Query.ContainsKey("bookmark") && Guid.TryParseExact(request.Query["bookmark"], "D", out _)) {
|
||||||
response.Cookies.Append("bookmark", request.Query["bookmark"], new CookieOptions {Expires = DateTimeOffset.MaxValue});
|
response.Cookies.Append("bookmark", request.Query["bookmark"], new CookieOptions {Expires = DateTimeOffset.MaxValue});
|
||||||
|
cookie = request.Query["bookmark"];
|
||||||
}
|
}
|
||||||
//if no cookie exists or cookie is invalid
|
//if no cookie exists or cookie is invalid
|
||||||
else if (!request.Cookies.ContainsKey("bookmark") || !Guid.TryParseExact(request.Cookies["bookmark"], "D", out _)) {
|
else if (!request.Cookies.ContainsKey("bookmark") || !Guid.TryParseExact(request.Cookies["bookmark"], "D", out _)) {
|
||||||
var guid = Guid.NewGuid().ToString();
|
var guid = Guid.NewGuid().ToString();
|
||||||
response.Cookies.Append("bookmark", guid, new CookieOptions {Expires = DateTimeOffset.MaxValue});
|
response.Cookies.Append("bookmark", guid, new CookieOptions {Expires = DateTimeOffset.MaxValue});
|
||||||
|
cookie = guid;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cookie = request.Cookies["bookmark"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.Query.ContainsKey("bookmark")) {
|
if (request.Query.ContainsKey("bookmark")) {
|
||||||
response.Redirect(redirectUri);
|
response.Redirect(redirectUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return cookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Event GetEventByGuid(string guid) {
|
public static Event GetEventByGuid(string guid) {
|
||||||
|
|
Loading…
Reference in a new issue