// AuthorizeAccount checks that the request sender has the right to access these data.
func AuthorizeAccount(c *pi.RequestContext) error {
	account, err := db.AuthorizeAccountByAccessToken(c.GetHeader(apiTokenHeader))
	if err != nil {
		return pi.NewError(401, err)
	}
	c.Data["account"] = account
	return nil
}
Example #2
0
// ConnectCharacterController connects the character to last place he was or the first zone if he never played.
func ConnectCharacterController(c *pi.RequestContext) error {
	account := c.Data["account"].(*models.PlayerAccount)
	idCharacter := c.GetRouteVariable("id")
	character, err := services.ConnectCharacterFromAccountByID(account, idCharacter)
	if err != nil {
		return pi.NewError(404, err)
	}
	return c.WriteDefault(character)
}
// RegisterAccountController registers the user.
func RegisterAccountController(c *pi.RequestContext) error {
	account := &models.PlayerAccount{}
	if err := c.GetDefaultObject(account); err != nil {
		return pi.NewError(400, err)
	}
	account, err := db.CreatePlayerAccount(account)
	if err != nil {
		return pi.NewError(400, err)
	}
	return c.WriteDefault(account.WithRefreshToken())
}
// RefreshAccountController refreshes the token of the user.
func RefreshAccountController(c *pi.RequestContext) error {
	account := &models.PlayerAccount{}
	if err := c.GetDefaultObject(account); err != nil {
		return pi.NewError(400, err)
	}
	account, err := db.RefresPlayerAccount(account)
	if err != nil {
		return pi.NewError(400, err)
	}
	return c.WriteDefault(account.Secure())
}
Example #5
0
// ExtendsSessionInterceptor extends the duration of the session of the player.
func ExtendsSessionInterceptor(c *pi.RequestContext) error {
	if err := db.ExtendsPlayerAccountTTLByAccessToken(c.GetHeader(apiTokenHeader), time.Now().Add(30*time.Minute)); err != nil {
		return pi.NewError(500, err)
	}
	return nil
}