reorganize
git-svn-id: svn://losandesgames.com/alfheim-website@5 15359d88-9307-4e75-a9c1-e5686e5897df
This commit is contained in:
parent
3aefbf7bd7
commit
0da164eb29
19
handlers.go
19
handlers.go
@ -1,3 +1,7 @@
|
|||||||
|
//
|
||||||
|
// Created by vfs on 02.05.2024.
|
||||||
|
//
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
@ -7,14 +11,13 @@ import "html/template"
|
|||||||
//import "strconv"
|
//import "strconv"
|
||||||
import "strings"
|
import "strings"
|
||||||
import "unicode/utf8"
|
import "unicode/utf8"
|
||||||
import "alfheimgame/models"
|
|
||||||
import "errors"
|
import "errors"
|
||||||
import "runtime/debug"
|
import "runtime/debug"
|
||||||
|
|
||||||
type templatedata struct {
|
type templatedata struct {
|
||||||
AuthenticatedUser int32
|
AuthenticatedUser int32
|
||||||
FormErrors map[string]string
|
FormErrors map[string]string
|
||||||
Account models.Account
|
Account Account
|
||||||
}
|
}
|
||||||
|
|
||||||
func favicon(w http.ResponseWriter, r *http.Request) {
|
func favicon(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -45,7 +48,7 @@ func home(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
text, err := template.ParseFiles("base.html", "index.html")
|
text, err := template.ParseFiles("ui/base.html", "ui/index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -70,7 +73,7 @@ func home(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func login(w http.ResponseWriter, r *http.Request) {
|
func login(w http.ResponseWriter, r *http.Request) {
|
||||||
text, err := template.ParseFiles("base.html", "login/index.html")
|
text, err := template.ParseFiles("ui/base.html", "ui/login.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -123,7 +126,7 @@ func login(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func logout(w http.ResponseWriter, r *http.Request) {
|
func logout(w http.ResponseWriter, r *http.Request) {
|
||||||
text, err := template.ParseFiles("base.html", "logout/index.html")
|
text, err := template.ParseFiles("ui/base.html", "ui/logout.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -148,7 +151,7 @@ func logout(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func register(w http.ResponseWriter, r *http.Request) {
|
func register(w http.ResponseWriter, r *http.Request) {
|
||||||
text, err := template.ParseFiles("base.html", "register/index.html")
|
text, err := template.ParseFiles("ui/base.html", "ui/register.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -164,7 +167,7 @@ func register(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case http.MethodPost:
|
case http.MethodPost:
|
||||||
account := models.Account{Username: r.FormValue("username"), Password: []byte(r.FormValue("password")), Firstname: r.FormValue("firstname"), Lastname: r.FormValue("lastname"), Email: r.FormValue("email")}
|
account := Account{Username: r.FormValue("username"), Password: []byte(r.FormValue("password")), Firstname: r.FormValue("firstname"), Lastname: r.FormValue("lastname"), Email: r.FormValue("email")}
|
||||||
|
|
||||||
errors := make(map[string]string)
|
errors := make(map[string]string)
|
||||||
|
|
||||||
@ -208,7 +211,7 @@ func account(w http.ResponseWriter, r *http.Request) {
|
|||||||
id := authenticated_user(r)
|
id := authenticated_user(r)
|
||||||
account, err := users.Get_account(id)
|
account, err := users.Get_account(id)
|
||||||
|
|
||||||
text, err := template.ParseFiles("base.html", "account/index.html")
|
text, err := template.ParseFiles("ui/base.html", "ui/account.html")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
|
|||||||
9
main.go
9
main.go
@ -1,3 +1,7 @@
|
|||||||
|
//
|
||||||
|
// Created by vfs on 02.05.2024.
|
||||||
|
//
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
@ -8,10 +12,9 @@ import _ "github.com/lib/pq"
|
|||||||
import "database/sql"
|
import "database/sql"
|
||||||
import "github.com/gorilla/sessions"
|
import "github.com/gorilla/sessions"
|
||||||
import "regexp"
|
import "regexp"
|
||||||
import "alfheimgame/models"
|
|
||||||
//import "golang.org/x/crypto/bcrypt"
|
//import "golang.org/x/crypto/bcrypt"
|
||||||
|
|
||||||
var users *models.Usermodel
|
var users *Usermodel
|
||||||
|
|
||||||
var key = []byte("super-secret-key")
|
var key = []byte("super-secret-key")
|
||||||
var store = sessions.NewCookieStore(key)
|
var store = sessions.NewCookieStore(key)
|
||||||
@ -55,7 +58,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
users = &models.Usermodel{db}
|
users = &Usermodel{db}
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user