diff --git a/Lab01/app/database/database.go b/Lab01/app/database/database.go index 3104662..bebee4c 100644 --- a/Lab01/app/database/database.go +++ b/Lab01/app/database/database.go @@ -23,3 +23,21 @@ func (db *Database) Initialize() { migrateInitial(orm) db.ORM = orm } + +func (db *Database) CreateUser(username string, password string) error { + user := User{Username: username, Password: password} + result := db.ORM.Create(&user) + return result.Error +} + +func (db *Database) LoginUser(username string, password string) (bool, error) { + user := User{Username: username, Password: password} + result := db.ORM.Where("username = ? AND password = ?", username, password).Find(&user) + if result.Error != nil { + return false, result.Error + } + if result.RowsAffected == 1 { + return true, nil + } + return false, nil +} diff --git a/Lab01/app/templates/index.tmpl b/Lab01/app/templates/index.tmpl index 0d7ffa8..27f45d6 100644 --- a/Lab01/app/templates/index.tmpl +++ b/Lab01/app/templates/index.tmpl @@ -9,10 +9,13 @@ {{template "navbar" .}}
{{template "scripts" .}} @@ -42,9 +45,18 @@ @@ -101,5 +113,9 @@ form.classList.add('was-validated'); }, false); } + + function redirect(location) { + window.location.href = location; + } {{end}} diff --git a/Lab01/app/templates/login.tmpl b/Lab01/app/templates/login.tmpl index fc3c21e..3645e74 100644 --- a/Lab01/app/templates/login.tmpl +++ b/Lab01/app/templates/login.tmpl @@ -17,13 +17,15 @@ {{template "scripts" .}}