Documentation ¶
Index ¶
Constants ¶
const ( PathLogin = "/user/login" PathLogout = "/user/logout" )
paths
Variables ¶
This section is empty.
Functions ¶
func AllowUser ¶
AllowUser will check if this client is a logged user, if not then it will redirect that guest to the login page otherwise it will allow the execution of the next handler.
func GeneratePassword ¶
GeneratePassword will generate a hashed password for us based on the user's input.
Types ¶
type AuthController ¶
type AuthController struct { iris.SessionController Source *DataSource User Model `iris:"model"` }
AuthController is the user authentication controller, a custom shared controller.
func (*AuthController) BeginRequest ¶
func (c *AuthController) BeginRequest(ctx iris.Context)
BeginRequest saves login state to the context, the user id.
type Controller ¶
type Controller struct {
AuthController
}
Controller is responsible to handle the following requests: GET /user/register POST /user/register GET /user/login POST /user/login GET /user/me GET /user/{id:long} | long is a new param type, it's the int64. All HTTP Methods /user/logout
func (*Controller) AnyLogout ¶
func (c *Controller) AnyLogout()
AnyLogout handles any method on path /user/logout.
func (*Controller) GetBy ¶
func (c *Controller) GetBy(userID int64)
GetBy handles GET:/user/{id:long}, i.e http://localhost:8080/user/1
func (*Controller) GetRegister ¶
func (c *Controller) GetRegister()
GetRegister handles GET:/user/register.
func (*Controller) PostRegister ¶
func (c *Controller) PostRegister()
PostRegister handles POST:/user/register.
type DataSource ¶
DataSource is our data store example.
func (*DataSource) GetBy ¶
func (d *DataSource) GetBy(query func(Model) bool) (user Model, found bool)
GetBy returns receives a query function which is fired for every single user model inside our imaginary database. When that function returns true then it stops the iteration.
It returns the query's return last known boolean value and the last known user model to help callers to reduce the loc.
But be carefully, the caller should always check for the "found" because it may be false but the user model has actually real data inside it.
It's actually a simple but very clever prototype function I'm think of and using everywhere since then, hope you find it very useful too.
func (*DataSource) GetByID ¶
func (d *DataSource) GetByID(id int64) (Model, bool)
GetByID returns a user model based on its ID.
func (*DataSource) GetByUsername ¶
func (d *DataSource) GetByUsername(username string) (Model, bool)
GetByUsername returns a user model based on the Username.
func (*DataSource) InsertOrUpdate ¶
func (d *DataSource) InsertOrUpdate(user Model) (Model, error)
InsertOrUpdate adds or updates a user to the (memory) storage.