コード例 #1
0
// 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())
}
コード例 #2
0
// 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())
}
コード例 #3
0
// 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
}
コード例 #4
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)
}
コード例 #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
}