コード例 #1
0
    def get_new_board(difficulty):
        try:
            payload = verify_decode_jwt(get_token_auth_header())

            # Check if the user (auth_id) already exists
            user = None
            user_info = payload["http://www.jordanhuus.com/user_info"]
            if User.query.filter(User.auth_id == payload["sub"]).count() > 0:
                user = User.query.filter(User.auth_id == payload["sub"]) \
                    .first()
            else:
                first_name = user_info["name"].split(" ")[0]
                last_name = first_name if len(user_info["name"].split(" ")) \
                    == 1 else user_info["name"].split(" ")[1]

                user = User(first_name, last_name, user_info["id"])
                user.add()

            # Store the newly created board
            board = SudokuBoard(difficulty, user)
            board.add()

        except KeyError as ke:
            abort(400, f"Request body is missing {ke} dictionary key.")
        except Exception:
            abort(500)

        return jsonify(board.format()), 200
コード例 #2
0
    def get_board_of_the_day():
        try:
            # Retrieve/create fake board-of-the-day user.
            # A user record is required
            # for an associated sudoku board
            user = User.query.filter(User.first_name == "board-of-the-day") \
                .first()
            if user is None:
                user = User("board-of-the-day", "board-of-the-day",
                            "no-auth-id")
                user.add()

            # Retrieve/create a sudoku board of the day
            board_of_the_day = SudokuBoard.query.filter(
                SudokuBoard.user_id == user.id).first()
            if board_of_the_day is None:
                board_of_the_day = SudokuBoard("easy", user)
                board_of_the_day.add()

        except Exception:
            abort(500)

        return jsonify(board_of_the_day.format()), 200