From d788822b066eab1a5deb9edf060658d0a4ad209e Mon Sep 17 00:00:00 2001 From: MrGeorgen Date: Tue, 22 Dec 2020 19:31:02 +0100 Subject: [PATCH] api doc --- README.md | 7 ++++++- src/api.go | 1 - src/login.go | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1aba382..f47a29d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ # RBU_account -RBU account system \ No newline at end of file +RBU account system + +# api +use `/login?redirect=someurl` to redirect the user after the login is finnished. +Use `api/accountinfo?accountkey=key&password=password` to get information about the user. +accountKey is the value of the cookie with the key "session". diff --git a/src/api.go b/src/api.go index b0d15fb..9d58d65 100644 --- a/src/api.go +++ b/src/api.go @@ -8,7 +8,6 @@ type accountApiResponse struct { DiscordUserId string `json:"discordUserId"` Email string `json:"email"` } -const apiPassword string = "hezgf42gfgwfg" func accountApi(w http.ResponseWriter, r *http.Request) { var accountKey string = r.FormValue("accountkey") var password string = r.FormValue("password") diff --git a/src/login.go b/src/login.go index a99cc6f..9fc634d 100644 --- a/src/login.go +++ b/src/login.go @@ -12,10 +12,14 @@ var sessions hashmap.HashMap const sessionName string = "session" const sessionTimeout time.Duration = 10 * 24 * time.Hour func login(w http.ResponseWriter, r *http.Request) { + var redirectUrl = r.FormValue("redirecturl") + if redirectUrl == "" { + redirectUrl = "dash" + } loginStruct := loginStruct{} var login bool = false if loggedIn(r) { - http.Redirect(w, r, "dash", http.StatusSeeOther) + http.Redirect(w, r, redirectUrl, http.StatusSeeOther) return } if r.Method == http.MethodPost { @@ -40,7 +44,7 @@ func login(w http.ResponseWriter, r *http.Request) { http.SetCookie(w, &cookie) sessions.Set(key, username) go deleteSession(key) - http.Redirect(w, r, "dash", http.StatusSeeOther) + http.Redirect(w, r, redirectUrl, http.StatusSeeOther) } } if r.Method == http.MethodGet || !login {