示例#1
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())
}