Browse Source

Return logout action, action mod

Vova Tkach 6 years ago
parent
commit
e07decb54f
2 changed files with 23 additions and 5 deletions
  1. 13 2
      modules/module_index.go
  2. 10 3
      modules/modules.go

+ 13 - 2
modules/module_index.go

@@ -199,5 +199,16 @@ func (this *Modules) RegisterAction_CpUserLogin() *Action {
 	})
 }
 
-// All actions here...
-// User logout
+func (this *Modules) RegisterAction_CpUserLogout() *Action {
+	return this.newAction(AInfo{
+		WantDB:   true,
+		Mount:    "singout",
+		WantUser: true,
+	}, func(wrap *wrapper.Wrapper) {
+		// Reset session var
+		wrap.S.SetInt("UserId", 0)
+
+		// Reload current page
+		wrap.Write(`window.location.reload(false);`)
+	})
+}

+ 10 - 3
modules/modules.go

@@ -23,9 +23,10 @@ type Module struct {
 }
 
 type AInfo struct {
-	Id     string
-	WantDB bool
-	Mount  string
+	Id       string
+	WantDB   bool
+	Mount    string
+	WantUser bool
 }
 
 type Action struct {
@@ -127,6 +128,12 @@ func (this *Modules) XXXActionFire(wrap *wrapper.Wrapper) bool {
 						}
 						defer wrap.DB.Close()
 					}
+					if act.Info.WantUser {
+						if !wrap.LoadSessionUser() {
+							wrap.MsgError(`You must be loginned to run this action`)
+							return true
+						}
+					}
 					act.Act(wrap)
 					return true
 				} else {