This commit is contained in:
2020-12-22 19:31:02 +01:00
parent 07a73fbeef
commit d788822b06
3 changed files with 12 additions and 4 deletions

View File

@ -1,3 +1,8 @@
# RBU_account # RBU_account
RBU account system 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".

View File

@ -8,7 +8,6 @@ type accountApiResponse struct {
DiscordUserId string `json:"discordUserId"` DiscordUserId string `json:"discordUserId"`
Email string `json:"email"` Email string `json:"email"`
} }
const apiPassword string = "hezgf42gfgwfg"
func accountApi(w http.ResponseWriter, r *http.Request) { func accountApi(w http.ResponseWriter, r *http.Request) {
var accountKey string = r.FormValue("accountkey") var accountKey string = r.FormValue("accountkey")
var password string = r.FormValue("password") var password string = r.FormValue("password")

View File

@ -12,10 +12,14 @@ var sessions hashmap.HashMap
const sessionName string = "session" const sessionName string = "session"
const sessionTimeout time.Duration = 10 * 24 * time.Hour const sessionTimeout time.Duration = 10 * 24 * time.Hour
func login(w http.ResponseWriter, r *http.Request) { func login(w http.ResponseWriter, r *http.Request) {
var redirectUrl = r.FormValue("redirecturl")
if redirectUrl == "" {
redirectUrl = "dash"
}
loginStruct := loginStruct{} loginStruct := loginStruct{}
var login bool = false var login bool = false
if loggedIn(r) { if loggedIn(r) {
http.Redirect(w, r, "dash", http.StatusSeeOther) http.Redirect(w, r, redirectUrl, http.StatusSeeOther)
return return
} }
if r.Method == http.MethodPost { if r.Method == http.MethodPost {
@ -40,7 +44,7 @@ func login(w http.ResponseWriter, r *http.Request) {
http.SetCookie(w, &cookie) http.SetCookie(w, &cookie)
sessions.Set(key, username) sessions.Set(key, username)
go deleteSession(key) go deleteSession(key)
http.Redirect(w, r, "dash", http.StatusSeeOther) http.Redirect(w, r, redirectUrl, http.StatusSeeOther)
} }
} }
if r.Method == http.MethodGet || !login { if r.Method == http.MethodGet || !login {