go - Better (general) auth implementation -


Currently I have a method in my BaseController and I need the user in each controller method Being authenticated I always leave this piece of code with the call:

  User, err: = c.getUser () If mistake! = Zero {return c.Redirect (UserController.Login)}  

which just checks

  strong. Interrupt Methi ((* User Controller). Check-on, Revert.backup)  

(in Init.go) .RenderArgs ["user"] .

has added a valid user. Anyways, I can put this redirect in the login page. Matthew checks in a filter / intercept method, so I do not have to repeat the above code 10 times? (I have developed this code around v0.9 ~ 0.10)

A solution I came up with would be to insert a module / app just like a new CSRF module.

Edit on 4.11.2015: This question was posted some time ago, please look back to the official, because there is a lot of development

< / Div>

Do not just request your controllers unless the authentication is done properly. You have to implement one for this. This means that

init.go:

  the revil. Filter = [] revel.Filter {session filter, // preferably a secure implementation that does not have plain text cookies etc. Mypackage.Authenticator}  

mypackage.go:

 < Code> package mypackage func authenticator (c * revel.Controller, fc [] revel.filter) {// If authentication (with session) is found, send the next filter to the stack // If not, then redirect to your authentication UI , And / or handle other parts of authentication requests ... // If authentication succeeds, then session / / otherwise Leave the request (possibly log?)}  

This directive relies entirely on the type of authentication you are installing. Here is one for your reference.


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -