api doc
This commit is contained in:
@ -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".
|
||||||
|
|||||||
@ -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")
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user