|
|
@@ -29,6 +29,12 @@ type User struct { // User
|
|
|
Mail string
|
|
|
}
|
|
|
|
|
|
+type pageParams struct{
|
|
|
+ HasError string
|
|
|
+ Error string
|
|
|
+ ReqDir string
|
|
|
+ } // {Error: ""} // TODO: OUTSOURCE
|
|
|
+
|
|
|
func (user *User) Login(username string, password string) (string, error) {
|
|
|
hmacSampleSecret := []byte(configutils.Conf.CryptoKey) // crypto key for JWT encryption
|
|
|
row, err := databaseutils.DBUtil.GetRow("*", "users", "username", username) // get user from db
|
|
|
@@ -96,7 +102,7 @@ func VerifyUserLoggedIn(tokenString string) (bool, int, error) { // TODO renew J
|
|
|
intUserID, _ := strconv.Atoi(userID) // convert to int ... god i love scripting languages
|
|
|
sliceID := searchUser(intUserID) // verify that user has a session on the server
|
|
|
if sliceID != -1 { // searchUser returns -1 if there's no such user
|
|
|
- return true, intUserID, nil // logged in
|
|
|
+ return true, intUserID, nil // logged in, TODO: "0" template comparision dynamic
|
|
|
} else {
|
|
|
return false, -1, errors.New(ERR_SESSION_TIMED_OUT) // Session probably expired - may also be faked? TODO more checks?
|
|
|
}
|
|
|
@@ -121,6 +127,9 @@ func AuthHandler(ctx *iris.Context) {
|
|
|
if isAuthed {
|
|
|
ctx.Next() // successfully authed, next handler
|
|
|
} else {
|
|
|
- ctx.Render("login.html", struct{ Error string }{Error: err.Error()}) // failed to auth
|
|
|
+ if err := ctx.Render("login.html", pageParams{"1", err.Error(), "login"}); err != nil {
|
|
|
+ println(err.Error())
|
|
|
+ } // failed to auth
|
|
|
+
|
|
|
}
|
|
|
}
|