Merge branch 'h44z:master' into master

This commit is contained in:
philippderdiedas 2022-10-28 20:42:35 +02:00 committed by GitHub
commit 383fc8cb58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -420,11 +420,10 @@ func (s *Server) PostUserCreatePeer(c *gin.Context) {
formPeer = currentSession.FormData.(wireguard.Peer)
}
formPeer.Email = currentSession.Email;
formPeer.Identifier = currentSession.Email;
formPeer.DeviceType = wireguard.DeviceTypeServer;
formPeer.PrivateKey = "";
formPeer.Email = currentSession.Email
formPeer.Identifier = currentSession.Email
formPeer.DeviceType = wireguard.DeviceTypeServer
if err := c.ShouldBind(&formPeer); err != nil {
_ = s.updateFormInSession(c, formPeer)
SetFlashMessage(c, "failed to bind form data: "+err.Error(), "danger")
@ -432,6 +431,11 @@ func (s *Server) PostUserCreatePeer(c *gin.Context) {
return
}
// if public key was manually set, remove the incorrect private key
if formPeer.PublicKey != currentSession.FormData.(wireguard.Peer).PublicKey {
formPeer.PrivateKey = ""
}
disabled := c.PostForm("isdisabled") != ""
now := time.Now()
if disabled {
@ -452,7 +456,6 @@ func (s *Server) PostUserCreatePeer(c *gin.Context) {
func (s *Server) GetUserEditPeer(c *gin.Context) {
peer := s.peers.GetPeerByKey(c.Query("pkey"))
currentSession, err := s.setFormInSession(c, peer)
if err != nil {
s.GetHandleError(c, http.StatusInternalServerError, "Session error", err.Error())
@ -461,7 +464,7 @@ func (s *Server) GetUserEditPeer(c *gin.Context) {
if peer.Email != currentSession.Email {
s.GetHandleError(c, http.StatusUnauthorized, "No permissions", "You don't have permissions to view this resource!")
return;
return
}
c.HTML(http.StatusOK, "user_edit_client.html", gin.H{
@ -486,7 +489,7 @@ func (s *Server) PostUserEditPeer(c *gin.Context) {
if currentPeer.Email != currentSession.Email {
s.GetHandleError(c, http.StatusUnauthorized, "No permissions", "You don't have permissions to view this resource!")
return;
return
}
disabled := c.PostForm("isdisabled") != ""
@ -494,7 +497,7 @@ func (s *Server) PostUserEditPeer(c *gin.Context) {
if disabled && currentPeer.DeactivatedAt == nil {
currentPeer.DeactivatedAt = &now
}
// Update in database
if err := s.UpdatePeer(currentPeer, now); err != nil {
_ = s.updateFormInSession(c, currentPeer)
@ -505,4 +508,4 @@ func (s *Server) PostUserEditPeer(c *gin.Context) {
SetFlashMessage(c, "changes applied successfully", "success")
c.Redirect(http.StatusSeeOther, "/user/peer/edit?pkey="+urlEncodedKey)
}
}