Mercurial Hosting > disearch
changeset 8:9534dd5eda89
use avatar
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 24 Oct 2023 19:31:33 -0600 |
parents | f29dd482a25a |
children | 88f425d261b3 |
files | src/lib/Shared.luan src/login2.html.luan src/login2.red.luan src/site.css |
diffstat | 4 files changed, 81 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
diff -r f29dd482a25a -r 9534dd5eda89 src/lib/Shared.luan --- a/src/lib/Shared.luan Tue Oct 24 18:59:42 2023 -0600 +++ b/src/lib/Shared.luan Tue Oct 24 19:31:33 2023 -0600 @@ -30,7 +30,7 @@ <% if get_user() == nil then %> <a href="login1.red">login</a> <% else %> - <a href="javascript:logout()">logout</a> + <a href="javascript:logout()"><script>document.write(`<img src="https://cdn.discordapp.com/avatars/${localStorage.user_id}/${localStorage.user_avatar}.png">`)</script></a> <% end %> </div> <hr> @@ -48,7 +48,7 @@ function Shared.discord_redirect_uri() local request = Http.request - return request.scheme.."://"..request.headers["Host"].."/login2.red" + return request.scheme.."://"..request.headers["Host"].."/login2.html" end return Shared
diff -r f29dd482a25a -r 9534dd5eda89 src/login2.html.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/login2.html.luan Tue Oct 24 19:31:33 2023 -0600 @@ -0,0 +1,72 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local stringify = Luan.stringify or error() +local Parsers = require "luan:Parsers.luan" +local json_parse = Parsers.json_parse or error() +local Io = require "luan:Io.luan" +local uri = Io.uri or error() +local Http = require "luan:http/Http.luan" +local Config = require "site:/lib/Config.luan" +local Shared = require "site:/lib/Shared.luan" +local discord_redirect_uri = Shared.discord_redirect_uri or error() +local Logging = require "luan:logging/Logging.luan" +local logger = Logging.logger "login2.red" + + +return function() + local code = Http.request.parameters.code or error() + logger.info("code = "..code) + + local url = "https://discord.com/api/oauth2/token" + local config = Config.get() + local options = { + method = "POST" + headers = { + ["User-Agent"] = "fuck you" -- for retarded Cloudflare + } + authorization = { + username = config.discord.client_id + password = config.discord.client_secret + type = "basic" + } + parameters = { + grant_type = "authorization_code" + code = code + redirect_uri = discord_redirect_uri() + } + } + -- logger.info(stringify(options)) + local result = uri(url,options).read_text() + -- logger.info(result) + result = json_parse(result) + local access_token = result.access_token or error() + logger.info("access_token = "..access_token) + + local url = "https://discord.com/api/users/@me" + local options = { + headers = { + ["User-Agent"] = "fuck you" -- for retarded Cloudflare + Authorization = "Bearer "..access_token + } + } + local result = uri(url,options).read_text() + logger.info(result) + result = json_parse(result) + local user_id = result.id or error() + local user_name = result.username or error() + local user_avatar = result.avatar or error() + + Http.response.set_persistent_cookie("user",user_id) + Io.stdout = Http.response.text_writer() +%> +<!doctype html> +<html> + <script> + localStorage.user_id = '<%=user_id%>'; + localStorage.user_name = '<%=user_name%>'; + localStorage.user_avatar = '<%=user_avatar%>'; + location = '/'; + </script> +</html> +<% +end
diff -r f29dd482a25a -r 9534dd5eda89 src/login2.red.luan --- a/src/login2.red.luan Tue Oct 24 18:59:42 2023 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -local Luan = require "luan:Luan.luan" -local error = Luan.error -local stringify = Luan.stringify or error() -local Parsers = require "luan:Parsers.luan" -local json_parse = Parsers.json_parse or error() -local Io = require "luan:Io.luan" -local uri = Io.uri or error() -local Http = require "luan:http/Http.luan" -local Config = require "site:/lib/Config.luan" -local Shared = require "site:/lib/Shared.luan" -local discord_redirect_uri = Shared.discord_redirect_uri or error() -local Logging = require "luan:logging/Logging.luan" -local logger = Logging.logger "login2.red" - - -return function() - local code = Http.request.parameters.code or error() - logger.info("code = "..code) - --Http.response.set_persistent_cookie("user",code) - - local url = "https://discord.com/api/oauth2/token" - local config = Config.get() - local options = { - method = "POST" - headers = { - ["User-Agent"] = "fuck you" -- for retarded Cloudflare - } - authorization = { - username = config.discord.client_id - password = config.discord.client_secret - type = "basic" - } - parameters = { - grant_type = "authorization_code" - code = code - redirect_uri = discord_redirect_uri() - } - } - -- logger.info(stringify(options)) - local result = uri(url,options).read_text() - -- logger.info(result) - result = json_parse(result) - local access_token = result.access_token or error() - logger.info("access_token = "..access_token) - - local url = "https://discord.com/api/users/@me" - local options = { - headers = { - ["User-Agent"] = "fuck you" -- for retarded Cloudflare - Authorization = "Bearer "..access_token - } - } - local result = uri(url,options).read_text() - logger.info(result) - - Http.response.send_redirect "/" -end
diff -r f29dd482a25a -r 9534dd5eda89 src/site.css --- a/src/site.css Tue Oct 24 18:59:42 2023 -0600 +++ b/src/site.css Tue Oct 24 19:31:33 2023 -0600 @@ -18,3 +18,10 @@ justify-content: space-between; align-items: center; } + +div[header] img { + width: 50px; + height: 50px; + object-fit: cover; + border-radius: 50%; +}