forked from dionyself/golang-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.go
39 lines (34 loc) · 936 Bytes
/
profile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package admins
import (
"strconv"
"github.com/chuongnx/golang-cms/models"
)
// ProfileController for users
type ProfileController struct {
BaseController
}
// UserPanelView Display user's homepage
func (CTRL *ProfileController) UserPanelView() {
UID := CTRL.Ctx.Input.Param(":id")
if CTRL.Ctx.Input.Param(":id") == "0" {
CTRL.ConfigPage("user-profile.html")
} else {
UID, err := strconv.Atoi(UID)
if err != nil {
CTRL.Abort("404")
}
CTRL.populateProfileViewData(UID)
CTRL.ConfigPage("profile-view.html")
}
}
// populateProfileViewData Displays profile by id
func (CTRL *ProfileController) populateProfileViewData(UID int) bool {
db := CTRL.GetDB()
userView := models.User{Id: UID}
db.Read(&userView, "Id")
Permissions := userView.Profile.GetPermissions(CTRL.Data["user"].(models.User))
// TODO : populate permissions on CTRL.Data
_ = Permissions
CTRL.Data["Profile"] = userView.Profile
return true
}