当前位置: 首页>>代码示例>>Python>>正文


Python User.get_current_user方法代码示例

本文整理汇总了Python中models.User.get_current_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_current_user方法的具体用法?Python User.get_current_user怎么用?Python User.get_current_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.User的用法示例。


在下文中一共展示了User.get_current_user方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
 def check_login(self):
     user = User.get_current_user()
     if user is None:
         self.redirect(users.create_login_url("/"))
         return
     self.user = user
     handler_method(self)
开发者ID:lamengao,项目名称:cuoluo-diary,代码行数:9,代码来源:settings.py

示例2: new_game

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
    def new_game(self, request):
        """Creates new game"""
        player_x = User.get_current_user(request.player_x)
        player_o = User.get_current_user(request.player_o)
        if not (player_x and player_o):
            wrong_user = player_x if not player_x else player_o
            raise endpoints.NotFoundException(
              'User % does not exists!' % wrong_user.name)
# Board size
        boardSize = 3
        if not boardSize: 
            raise endpoints.BadRequestException('Board Size not valid')
  
        game = Game.new_game(player_x.key, player_o.key, boardSize)

        return game.to_form()
开发者ID:kcruz2010,项目名称:TTTAPI,代码行数:18,代码来源:TTTAPI.py

示例3: test_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
  def test_user(self):
    self.assertEqual(0, User.all().count())
    self.assertEqual(None, User.get_current_user())

    user = User.get_or_insert_current_user(self.handler)
    self.assertEqual(self.current_user_id, user.key().name())
    self.assert_entities_equal([User(key_name=self.current_user_id)], User.all())
开发者ID:snarfed,项目名称:salmon-unofficial,代码行数:9,代码来源:models_test.py

示例4: get_user_games

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
 def get_user_games(self, request):
     """This returns all of a User's active games."""
     user = User.get_current_user(request.user_name)
     if not user:
         raise endpoints.BadRequestException('User not found!')
     games = Game.query(ndb.OR(Game.player_x == user.key,
                               Game.player_o == user.key)).filter(Game.game_over == False)
     return GameForms(items=[game.to_form() for game in games])
开发者ID:elnobun,项目名称:Tic-Tac-Toe-Game-API,代码行数:10,代码来源:tictactoe_api.py

示例5: new_game

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
    def new_game(self, request):
        """Creates new game"""
        player_x = User.get_current_user(request.player_x)
        player_o = User.get_current_user(request.player_o)
        if not (player_x and player_o):
            wrong_user = player_x if not player_x else player_o
            raise endpoints.NotFoundException(
                    'User % does not exist!' % wrong_user.name)
        # Board Size is 3. Check if board size is valid.
        boardSize = 3
        if request.boardSize:
            if request.boardSize < 3 or request.boardSize > 3:
                raise endpoints.BadRequestException('Board Size not valid!'
                                                'Must have the value of 3 ')
            boardSize = request.boardSize
        game = Game.new_game(player_x.key, player_o.key, boardSize)

        return game.to_form()
开发者ID:elnobun,项目名称:Tic-Tac-Toe-Game-API,代码行数:20,代码来源:tictactoe_api.py

示例6: create_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
 def create_user(self, request):
     """Create a User. Requires a unique username"""
     if User.get_current_user(request.user_name):
         raise endpoints.ConflictException(
             'A User with that name already exists!')
     if not mail.is_email_valid(request.email):
         raise endpoints.BadRequestException(
             'Bad email address')
     user = User(name=request.user_name, email=request.email)
     user.put()
     return StringMessage(message='User: {} created!'.format(
             request.user_name))
开发者ID:elnobun,项目名称:Tic-Tac-Toe-Game-API,代码行数:14,代码来源:tictactoe_api.py

示例7: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
 def get(self, username):
   if username == 'mine':
     user = User.get_current_user()
   else:
     user = get1_by_property(User, 'name', username)
   
   if user:
     balances = self.get_balances(user)
     self.generate('user_profile.html',
                   {'user':user,
                    'balances':balances,
                    'groups':Group.all(),
                    'vendors':Vendor.all()})    
   else:
     self.redirect('/oops/invalid_user')
开发者ID:tchaikov,项目名称:beanfs,代码行数:17,代码来源:user.py

示例8: user_signin

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
    def user_signin(self, request):
        """Exposes an API endpoint to insert new user.

        Args:
            request: An instance of UserRequestMessage parsed from the API
                request.

        Returns:
            An instance of LoginResponseMessage containing new user email
            and JWT token.
        """
        entity = User.get_current_user(request.email, request.password)
        payload = {'email': entity.email}
        token = JWTHelper.get_jwt_token(payload)
        return LoginResponseMessage(email=entity.email,
                                    token=token)
开发者ID:maciekskin,项目名称:endpoints-api-example,代码行数:18,代码来源:api.py

示例9: make_move

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
    def make_move(self, request):
        """Makes a move. Returns a game state with message"""
        game = get_by_urlsafe(request.urlsafe_game_key, Game)
        if not game:
            raise endpoints.NotFoundException('Game not found')
        if game.game_over:
            return game.to_form('Game already over!')

        # prevent a user from playing twice in a row
        user = User.get_current_user(request.user_name)
        if user.key != game.nextMove:
            raise endpoints.BadRequestException('It\'s not your turn!')
        x = True if user.key == game.player_x else False

        # Make a move, and verify if the move is a valid move
        move = request.move
        size = game.boardSize * game.boardSize - 1
        if move < 0 or move > size:
            raise endpoints.BadRequestException('Bad Move!')
        if game.board[move] != '':
            raise endpoints.BadRequestException('Invalid Move')

        # Make a move, and send the move to game history
        game.board[move] = 'X' if x else 'O'
        game.game_history.append(('X' if x else 'O', move))
        game.nextMove = game.player_o if x else game.player_x

        #Check if there is a winner in the game and end the game
        winner = check_winner(game.board, game.boardSize)
        if winner:
            game.end_game(user.key)
        else:
            #If no winner, game ends in a draw
            if check_full(game.board):
                game.end_game()
            else:
                # Send email reminder to player if game still in progress
                taskqueue.add(url='/tasks/send_move_email',
                              params={'user_key': game.nextMove.urlsafe(),
                                      'game_key': game.key.urlsafe()})

        game.put()

        # Upde the Memcache if the game is over
        if game.game_over:
            taskqueue.add(url='/task/cache_games_finished')
        return game.to_form()
开发者ID:elnobun,项目名称:Tic-Tac-Toe-Game-API,代码行数:49,代码来源:tictactoe_api.py

示例10: before_request

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
def before_request():
    g.User = User
    g.user = User.get_current_user()
    g.year = datetime.date.today().year
    g.login_form = LoginForm()
    g.group_by = group_by
开发者ID:ramin32,项目名称:Hangspot,代码行数:8,代码来源:views.py

示例11: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
 def post(self, user_id):
   user = User.get_current_user()
   for group in self.request.POST.getall('group'):
     user.join(Group.get_by_id(long(group)))
   self.redirect('/u/%s/profile' % user.name)
开发者ID:tchaikov,项目名称:beanfs,代码行数:7,代码来源:user.py

示例12: test_no_logged_in_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_current_user [as 别名]
 def test_no_logged_in_user(self):
   self.testbed.setup_env(overwrite=True, user_id='', user_email='')
   self.assertEqual(None, users.get_current_user())
   self.assertEqual(None, User.get_current_user())
   self.assertEqual(None, User.get_or_insert_current_user(self.handler))
开发者ID:snarfed,项目名称:salmon-unofficial,代码行数:7,代码来源:models_test.py


注:本文中的models.User.get_current_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。