forked from TF2Stadium/Helen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mumble.go
39 lines (32 loc) · 861 Bytes
/
mumble.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package controllers
import (
"net/http"
"time"
"github.com/TF2Stadium/Helen/config"
chelpers "github.com/TF2Stadium/Helen/controllers/controllerhelpers"
)
func ResetMumblePassword(w http.ResponseWriter, r *http.Request) {
token, err := chelpers.GetToken(r)
if err != nil {
http.Error(w, "You aren't logged in.", http.StatusForbidden)
return
}
player := chelpers.GetPlayer(token)
player.MumbleAuthkey = player.GenAuthKey()
player.Save()
newToken := chelpers.NewToken(player)
cookie := &http.Cookie{
Name: "auth-jwt",
Value: newToken,
Path: "/",
Domain: config.Constants.CookieDomain,
Expires: time.Now().Add(30 * 24 * time.Hour),
}
http.SetCookie(w, cookie)
referer, ok := r.Header["Referer"]
if ok {
http.Redirect(w, r, referer[0], 303)
return
}
http.Redirect(w, r, config.Constants.LoginRedirectPath, 303)
}