Add logout
This commit is contained in:
parent
1d42e4465c
commit
2490833b6b
2 changed files with 28 additions and 1 deletions
|
@ -164,6 +164,14 @@ spawn do
|
|||
end
|
||||
end
|
||||
|
||||
before_all do |env|
|
||||
if env.request.cookies["SID"]?
|
||||
env.set "authorized", true
|
||||
else
|
||||
env.set "authorized", false
|
||||
end
|
||||
end
|
||||
|
||||
get "/" do |env|
|
||||
templated "index"
|
||||
end
|
||||
|
@ -409,9 +417,15 @@ post "/login" do |env|
|
|||
|
||||
login = client.get(login.headers["Location"], headers)
|
||||
headers = login.cookies.add_request_headers(headers)
|
||||
|
||||
# We are now logged in
|
||||
|
||||
login.cookies.each do |cookie|
|
||||
host = URI.parse(env.request.headers["Host"]).host
|
||||
cookie.extension = cookie.extension.not_nil!.gsub(".youtube.com", host)
|
||||
end
|
||||
|
||||
login.cookies.add_response_headers(env.response.headers)
|
||||
|
||||
env.redirect "/"
|
||||
rescue ex
|
||||
error_message = "Login failed"
|
||||
|
@ -419,6 +433,15 @@ post "/login" do |env|
|
|||
end
|
||||
end
|
||||
|
||||
get "/logout" do |env|
|
||||
env.request.cookies.each do |cookie|
|
||||
cookie.expires = Time.new(1990, 1, 1)
|
||||
end
|
||||
|
||||
env.request.cookies.add_response_headers(env.response.headers)
|
||||
env.redirect "/"
|
||||
end
|
||||
|
||||
get "/redirect" do |env|
|
||||
if env.params.query["q"]?
|
||||
env.redirect env.params.query["q"]
|
||||
|
|
|
@ -25,7 +25,11 @@
|
|||
</form>
|
||||
</div>
|
||||
<div class="pure-u-1 pure-u-md-1-5">
|
||||
<% if env.get "authorized" %>
|
||||
<a href="/logout" class="pure-menu-heading">Logout</a>
|
||||
<% else %>
|
||||
<a href="/login" class="pure-menu-heading">Login</a>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<%= content %>
|
||||
|
|
Loading…
Reference in a new issue