Browse Source

Return CP login page

Vova Tkach 6 years ago
parent
commit
9007c9a357
1 changed files with 11 additions and 0 deletions
  1. 11 0
      engine/engine.go

+ 11 - 0
engine/engine.go

@@ -29,6 +29,11 @@ func Response(l *logger.Logger, m *modules.Modules, w http.ResponseWriter, r *ht
 }
 
 func (this *Engine) Process() bool {
+	// Check and set session user
+	if !this.Wrap.S.IsSetInt("UserId") {
+		this.Wrap.S.SetInt("UserId", 0)
+	}
+
 	this.Wrap.IsBackend = this.Wrap.R.URL.Path == "/cp" || strings.HasPrefix(this.Wrap.R.URL.Path, "/cp/")
 	this.Wrap.ConfMysqlExists = utils.IsMySqlConfigExists(this.Wrap.DConfig + string(os.PathSeparator) + "mysql.json")
 	this.Wrap.UrlArgs = append(this.Wrap.UrlArgs, utils.UrlToArray(this.Wrap.R.URL.Path)...)
@@ -80,6 +85,12 @@ func (this *Engine) Process() bool {
 		return true
 	}
 
+	// Show login page if need
+	if this.Wrap.S.GetInt("UserId", 0) <= 0 {
+		utils.SystemRenderTemplate(this.Wrap.W, assets.TmplCpLogin, nil)
+		return true
+	}
+
 	// Render backend
 	return this.Mods.XXXBackEnd(this.Wrap)
 }