Skip to content
Permalink
Browse files

07-Profile-Page add more info

  • Loading branch information...
bonfy committed Sep 28, 2018
1 parent b954926 commit 4e8cba8d0084e6020ded1534ab93026cf919ef14
Showing with 31 additions and 1 deletion.
  1. +6 −0 controller/middle.go
  2. +15 −0 model/user.go
  3. +10 −1 templates/content/profile.html
@@ -3,12 +3,18 @@ package controller
import (
"log"
"net/http"

"github.com/bonfy/go-mega-code/model"
)

func middleAuth(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
username, err := getSessionUser(r)
log.Println("middle:", username)
if username != "" {
log.Println("Last seen:", username)
model.UpdateLastSeen(username)
}
if err != nil {
log.Println("middle get session err and redirect to login")
http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
@@ -49,3 +49,18 @@ func AddUser(username, password, email string) error {
user.SetAvatar(email)
return db.Create(&user).Error
}

// UpdateUserByUsername func
func UpdateUserByUsername(username string, contents map[string]interface{}) error {
item, err := GetUserByUsername(username)
if err != nil {
return err
}
return db.Model(item).Updates(contents).Error
}

// UpdateLastSeen func
func UpdateLastSeen(username string) error {
contents := map[string]interface{}{"last_seen": time.Now()}
return UpdateUserByUsername(username, contents)
}
@@ -3,7 +3,16 @@
<table>
<tr valign="top">
<td><img src="{{.ProfileUser.Avatar}}&s=128"></td>
<td><h1>User: {{.ProfileUser.Username}}</h1></td>
<td>
<h1>User: {{.ProfileUser.Username}}</h1>
{{if .ProfileUser.AboutMe}}
<p>{{ .ProfileUser.AboutMe }}</p>
{{end}}

{{if .ProfileUser.LastSeen}}
<p>Last seen on: {{ .ProfileUser.LastSeen }}</p>
{{end}}
</td>
</tr>
</table>

0 comments on commit 4e8cba8

Please sign in to comment.
You can’t perform that action at this time.