Howto create Simple Login for app ?
You can use the plugin to do the simple login:
var FilterUser = func(ctx *context.Context) {
_, ok := ctx.Input.Session("uid").(int)
if !ok {
ctx.Redirect(302, "/login")
}
}
beego.AddFilter("*","AfterStatic",FilterUser)
Like -> https://github.com/insionng/toropress/blob/master/handlers/LoginHandler.go
Or like http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-v-user-logins
@login_required in function like (Flask Python Framework)
.....There are only two changes to this function. First, we have added the login_required decorator. This will ensure that this page is only seen by logged in users. .......
Migrate from Flask Framework Python to Golang Beego Framework
I think another way is also effect.
type BaseController struct{
beego.Controller
}
func (b *BaseController) Prepare(){
sess_username, _ := self.GetSession("username").(string)
if sess_username == "" {
self.TplNames = "login.html"
self.Render()
} else {
self.Ctx.Redirect(302, "/")
}
}
type MainController struct{
BaseController
}
:+1: Thanks!
Simple and fast, long life for Beego
Most helpful comment
I think another way is also effect.