split checker from token-validator
This commit is contained in:
parent
685dc0b0ea
commit
0c661f36f6
20 changed files with 634 additions and 748 deletions
|
@ -8,6 +8,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
|
||||
"git.nemunai.re/lectures/adlin/libadlin"
|
||||
)
|
||||
|
||||
var AuthFunc = checkAuth
|
||||
|
@ -20,17 +22,17 @@ func init() {
|
|||
router.POST("/api/auth/logout", apiRawHandler(logout))
|
||||
}
|
||||
|
||||
func validateAuthToken(s Student, _ httprouter.Params, _ []byte) (interface{}, error) {
|
||||
func validateAuthToken(s adlin.Student, _ httprouter.Params, _ []byte) (interface{}, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func logout(w http.ResponseWriter, ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: "auth",
|
||||
Value: "",
|
||||
Path: baseURL,
|
||||
Expires: time.Unix(0,0),
|
||||
Secure: true,
|
||||
Name: "auth",
|
||||
Value: "",
|
||||
Path: baseURL + "/",
|
||||
Expires: time.Unix(0, 0),
|
||||
Secure: true,
|
||||
HttpOnly: true,
|
||||
})
|
||||
|
||||
|
@ -42,18 +44,18 @@ type loginForm struct {
|
|||
Password string
|
||||
}
|
||||
|
||||
func completeAuth(w http.ResponseWriter, username string, session *Session) (err error) {
|
||||
var std Student
|
||||
if !studentExists(username) {
|
||||
if std, err = NewStudent(username); err != nil {
|
||||
func completeAuth(w http.ResponseWriter, username string, session *adlin.Session) (err error) {
|
||||
var std adlin.Student
|
||||
if !adlin.StudentExists(username) {
|
||||
if std, err = adlin.NewStudent(username); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if std, err = getStudentByLogin(username); err != nil {
|
||||
} else if std, err = adlin.GetStudentByLogin(username); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if session == nil {
|
||||
var s Session
|
||||
var s adlin.Session
|
||||
s, err = std.NewSession()
|
||||
session = &s
|
||||
} else {
|
||||
|
@ -65,11 +67,11 @@ func completeAuth(w http.ResponseWriter, username string, session *Session) (err
|
|||
}
|
||||
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: "auth",
|
||||
Value: base64.StdEncoding.EncodeToString(session.Id),
|
||||
Path: baseURL,
|
||||
Expires: time.Now().Add(30 * 24 * time.Hour),
|
||||
Secure: true,
|
||||
Name: "auth",
|
||||
Value: base64.StdEncoding.EncodeToString(session.Id),
|
||||
Path: baseURL + "/",
|
||||
Expires: time.Now().Add(30 * 24 * time.Hour),
|
||||
Secure: true,
|
||||
HttpOnly: true,
|
||||
})
|
||||
|
||||
|
@ -91,7 +93,7 @@ func checkAuth(w http.ResponseWriter, _ httprouter.Params, body []byte) (interfa
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if r, err := http.NewRequest("GET", "https://fic.srs.epita.fr/2021/", nil); err != nil {
|
||||
if r, err := http.NewRequest("GET", "https://owncloud.srs.epita.fr/remote.php/dav/", nil); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
r.SetBasicAuth(lf.Username, lf.Password)
|
||||
|
|
Reference in a new issue