def game_join(self, request): """ Joins the current user into a game """ auth_user = utils.get_auth_user() user = User.by_email(auth_user.email()) game = Game.by_urlsafe(request.game_key) game.add_player(user) return game.to_form()
def game_new(self, request): """ Creates a new game """ # Check the user is authenticated auth_user = utils.get_auth_user() # Check the authenticated user has registered a username user = User.by_email(auth_user.email()) game = Game.create_game(user, request) return game.to_form()
def game_guess(self, request): """ Have a user submit their guess """ auth_user = utils.get_auth_user() user = User.by_email(auth_user.email()) game = Game.by_urlsafe(request.game_key) message = game.player_guess(user, request) return message
def game_cancel(self, request): """ Sets an active game to cancelled """ auth_user = utils.get_auth_user() user = User.by_email(auth_user.email()) game = Game.by_urlsafe(request.game_key) if not game.has_player(user): raise endpoints.UnauthorizedException( 'You cannot cancel a game that you are not participating in.') return game.cancel_game().to_form()
def get_games_list(self, request): """ Returns a list of games of an optionally supplied state """ auth_user = utils.get_auth_user() user = User.by_email(auth_user.email()) games = Game.by_game_state(request.state, request.limit) return GameListForm(games=[game.to_form() for game in games])
def user_register(self, request): """ Create a User. Requires a unique username """ auth_user = utils.get_auth_user() user = User.create_user(auth_user, request.user_name) return StringMessage(message='User {} created!'.format(user.name))
def get_game(self, request): """ Get info of a specific game """ auth_user = utils.get_auth_user() user = User.by_email(auth_user.email()) game = Game.by_urlsafe(request.game_key) return game.to_form()
def get_game_history(self, request): """ Get a game's history of guesses """ auth_user = utils.get_auth_user() user = User.by_email(auth_user.email()) game = Game.by_urlsafe(request.game_key) return GameHistoryForm(guesses=game.get_history())
def get_user_rankings(self, request): """ Get a listing of users and their win ratings """ auth_user = utils.get_auth_user() user = User.by_email(auth_user.email()) return RankingForm(rankings=User.get_user_rankings())
def get_user_games(self, request): """ Gets a list of the user's games that are active """ auth_user = utils.get_auth_user() user = User.by_email(auth_user.email()) games = Game.get_active_games(user) return GameListForm(games=[game.to_form() for game in games])
def is_accessible(self): user = get_auth_user() return user is not None and user.is_admin
def get_admin_login(): if get_auth_user(): redirect('/admin') return template("admin/login.html")