diff --git a/models/main.go b/models/main.go new file mode 100644 index 0000000..3856cc5 --- /dev/null +++ b/models/main.go @@ -0,0 +1,72 @@ +package main + +import ( + "html/template" + "net/http" + + "github.com/jinzhu/gorm" + _ "github.com/jinzhu/gorm/dialects/sqlite" +) + +var db *gorm.DB + +type UserProfile struct { + gorm.Model + Username string + Email string + Bio string +} + +func profileHandler(w http.ResponseWriter, r *http.Request) { + var user UserProfile + db.First(&user) + renderTemplate(w, "profile.html", user) +} + +func editHandler(w http.ResponseWriter, r *http.Request) { + var user UserProfile + db.First(&user) + renderTemplate(w, "edit.html", user) +} + +func updateHandler(w http.ResponseWriter, r *http.Request) { + var user UserProfile + db.First(&user) + + user.Username = r.FormValue("username") + user.Email = r.FormValue("email") + user.Bio = r.FormValue("bio") + + db.Save(&user) + + http.Redirect(w, r, "/profile", http.StatusSeeOther) +} + +func renderTemplate(w http.ResponseWriter, tmpl string, data interface{}) { + t, err := template.ParseFiles("templates/" + tmpl) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + err = t.Execute(w, data) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} + +func main() { + var err error + db, err = gorm.Open("sqlite3", "test.db") + if err != nil { + panic("failed to connect database") + } + defer db.Close() + db.AutoMigrate(&UserProfile{}) + + http.HandleFunc("/profile", profileHandler) + http.HandleFunc("/edit", editHandler) + http.HandleFunc("/update", updateHandler) + http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) + http.ListenAndServe(":8080", nil) +} diff --git a/public/css/style.css b/public/css/style.css new file mode 100644 index 0000000..6f20386 --- /dev/null +++ b/public/css/style.css @@ -0,0 +1,90 @@ +body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + background-color: #f4f4f4; +} + +.container { + max-width: 800px; + margin: 0 auto; + padding: 20px; + background-color: #fff; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); +} + +h1 { + text-align: center; + color: #333; +} + +.profile-info { + text-align: center; +} + +.profile-info img { + border-radius: 50%; + max-width: 150px; + height: auto; +} + +.profile-info p { + font-size: 18px; + color: #333; + margin-bottom: 10px; +} + +.edit-form { + max-width: 600px; + margin: 0 auto; +} + +.edit-form label { + display: block; + font-size: 16px; + margin-bottom: 8px; + color: #333; +} + +.edit-form input, +.edit-form textarea { + width: calc(100% - 16px); + padding: 8px; + font-size: 16px; + margin-bottom: 16px; + border: 1px solid #ccc; + border-radius: 4px; + box-sizing: border-box; +} + +.edit-form input[type="submit"] { + background-color: #007bff; + color: #fff; + font-size: 16px; + border: none; + border-radius: 4px; + cursor: pointer; + padding: 10px 20px; +} + +.edit-form input[type="submit"]:hover { + background-color: #0056b3; +} + +.edit-form textarea { + height: 100px; +} + +button { + background-color: #dc3545; + color: #fff; + font-size: 16px; + border: none; + border-radius: 4px; + cursor: pointer; + padding: 10px 20px; +} + +button:hover { + background-color: #bd2130; +} diff --git a/views/home/index.html b/views/home/index.html index 7423034..9c71a8e 100644 --- a/views/home/index.html +++ b/views/home/index.html @@ -26,6 +26,7 @@
  • Grind
  • Dashboard
  • Contact
  • +
  • Profile
  • diff --git a/views/profile/index.html b/views/profile/index.html index e69de29..c712c1a 100644 --- a/views/profile/index.html +++ b/views/profile/index.html @@ -0,0 +1,24 @@ + + + + + + Edit Profile + + + +

    Edit Profile

    +
    + +

    + + +

    + +
    +

    + + +
    + +