mirror of
https://github.com/h44z/wg-portal.git
synced 2025-12-14 10:36:18 +00:00
WIP: support for multiple WireGuard devices (#2)
This commit is contained in:
@@ -49,22 +49,15 @@ func (s *Server) GetAdminUsersIndex(c *gin.Context) {
|
||||
|
||||
dbUsers := s.users.GetFilteredAndSortedUsersUnscoped(currentSession.SortedBy["users"], currentSession.SortDirection["users"], currentSession.Search["users"])
|
||||
|
||||
c.HTML(http.StatusOK, "admin_user_index.html", struct {
|
||||
Route string
|
||||
Alerts []FlashData
|
||||
Session SessionData
|
||||
Static StaticData
|
||||
Users []users.User
|
||||
TotalUsers int
|
||||
Device Device
|
||||
}{
|
||||
Route: c.Request.URL.Path,
|
||||
Alerts: GetFlashes(c),
|
||||
Session: currentSession,
|
||||
Static: s.getStaticData(),
|
||||
Users: dbUsers,
|
||||
TotalUsers: len(s.users.GetUsers()),
|
||||
Device: s.peers.GetDevice(),
|
||||
c.HTML(http.StatusOK, "admin_user_index.html", gin.H{
|
||||
"Route": c.Request.URL.Path,
|
||||
"Alerts": GetFlashes(c),
|
||||
"Session": currentSession,
|
||||
"Static": s.getStaticData(),
|
||||
"Users": dbUsers,
|
||||
"TotalUsers": len(s.users.GetUsers()),
|
||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
||||
"DeviceNames": s.wg.Cfg.DeviceNames,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -77,21 +70,14 @@ func (s *Server) GetAdminUsersEdit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "admin_edit_user.html", struct {
|
||||
Route string
|
||||
Alerts []FlashData
|
||||
Session SessionData
|
||||
Static StaticData
|
||||
User users.User
|
||||
Device Device
|
||||
Epoch time.Time
|
||||
}{
|
||||
Route: c.Request.URL.Path,
|
||||
Alerts: GetFlashes(c),
|
||||
Session: currentSession,
|
||||
Static: s.getStaticData(),
|
||||
User: currentSession.FormData.(users.User),
|
||||
Device: s.peers.GetDevice(),
|
||||
c.HTML(http.StatusOK, "admin_edit_user.html", gin.H{
|
||||
"Route": c.Request.URL.Path,
|
||||
"Alerts": GetFlashes(c),
|
||||
"Session": currentSession,
|
||||
"Static": s.getStaticData(),
|
||||
"User": currentSession.FormData.(users.User),
|
||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
||||
"DeviceNames": s.wg.Cfg.DeviceNames,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -160,21 +146,14 @@ func (s *Server) GetAdminUsersCreate(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "admin_edit_user.html", struct {
|
||||
Route string
|
||||
Alerts []FlashData
|
||||
Session SessionData
|
||||
Static StaticData
|
||||
User users.User
|
||||
Device Device
|
||||
Epoch time.Time
|
||||
}{
|
||||
Route: c.Request.URL.Path,
|
||||
Alerts: GetFlashes(c),
|
||||
Session: currentSession,
|
||||
Static: s.getStaticData(),
|
||||
User: currentSession.FormData.(users.User),
|
||||
Device: s.peers.GetDevice(),
|
||||
c.HTML(http.StatusOK, "admin_edit_user.html", gin.H{
|
||||
"Route": c.Request.URL.Path,
|
||||
"Alerts": GetFlashes(c),
|
||||
"Session": currentSession,
|
||||
"Static": s.getStaticData(),
|
||||
"User": currentSession.FormData.(users.User),
|
||||
"Device": s.peers.GetDevice(currentSession.DeviceName),
|
||||
"DeviceNames": s.wg.Cfg.DeviceNames,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -218,7 +197,7 @@ func (s *Server) PostAdminUsersCreate(c *gin.Context) {
|
||||
formUser.IsAdmin = c.PostForm("isadmin") == "true"
|
||||
formUser.Source = users.UserSourceDatabase
|
||||
|
||||
if err := s.CreateUser(formUser); err != nil {
|
||||
if err := s.CreateUser(formUser, currentSession.DeviceName); err != nil {
|
||||
_ = s.updateFormInSession(c, formUser)
|
||||
SetFlashMessage(c, "failed to add user: "+err.Error(), "danger")
|
||||
c.Redirect(http.StatusSeeOther, "/admin/users/create?formerr=create")
|
||||
|
||||
Reference in New Issue
Block a user