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


Python User.get_user_by_name方法代码示例

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


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

示例1: form_verified

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_name [as 别名]
 def form_verified(self):
     if User.user_login(self.user_name, self.user_password):
         user = User.get_user_by_name(self.user_name)
         self.login(user)
         self.redirect('/welcome')
     else:
         error_message = "User does not exist. Please signup."
         self.render("login.html", error_message=error_message)
开发者ID:AlbertoALopez,项目名称:gae-cookies,代码行数:10,代码来源:LoginHandler.py

示例2: get_user_scores

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_name [as 别名]
 def get_user_scores(self, request):
     """Returns all of an individual User's scores"""
     user = User.get_user_by_name(request.user_name)
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     scores = Score.query(ndb.OR(Score.user_x == user.key,
                                 Score.user_o == user.key))
     return ScoreForms(items=[score.to_form() for score in scores])
开发者ID:DOlearczyk,项目名称:Tic-tac-toe,代码行数:11,代码来源:api.py

示例3: get_user_games

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_name [as 别名]
 def get_user_games(self, request):
     """Return all User's active games"""
     user = User.get_user_by_name(request.user_name)
     if not user:
         raise endpoints.BadRequestException('User not found!')
     games = Game.query(ndb.OR(Game.user_x == user.key,
                               Game.user_o == user.key)). \
         filter(Game.game_over == False)
     return GameForms(items=[game.to_form() for game in games])
开发者ID:DOlearczyk,项目名称:Tic-tac-toe,代码行数:11,代码来源:api.py

示例4: new_game

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_name [as 别名]
    def new_game(self, request):
        """Creates new game"""
        user_x = User.get_user_by_name(request.user_x)
        user_o = User.get_user_by_name(request.user_o)
        # Check if users exist
        if not (user_x and user_o):
            wrong_user = user_x if not user_x else user_o
            raise endpoints.NotFoundException(
                'User %s does not exist!' % wrong_user.name)
        # Check if board size is valid. It should be within 3-100 range.
        board_size = 3
        if request.board_size:
            if request.board_size < 3 or request.board_size > 100:
                raise endpoints.BadRequestException(
                    'Invalid board size! Must be between'
                    ' 3 and 100')
            board_size = request.board_size
        game = Game.new_game(user_x.key, user_o.key, board_size)

        return game.to_form()
开发者ID:DOlearczyk,项目名称:Tic-tac-toe,代码行数:22,代码来源:api.py

示例5: user_timeline

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_name [as 别名]
def user_timeline(username):
    """Display's a users tweets."""
    profile_user = User.get_user_by_name(username=username)
    if profile_user is None:
        abort(404)
    followed = False
    if g.user:
        followed = User.followed(g.user._id, profile_user._id)
    messages = Post.timeline_user(profile_user._id)
    return render_template('timeline.html', messages=messages, followed=followed,
            profile_user=profile_user)
开发者ID:karoon,项目名称:twitter-flask-neo4j,代码行数:13,代码来源:minitwit.py

示例6: create_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_name [as 别名]
 def create_user(self, request):
     """Create a User. Requires a unique username"""
     if User.get_user_by_name(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:DOlearczyk,项目名称:Tic-tac-toe,代码行数:14,代码来源:api.py

示例7: make_move

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_name [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:
            raise endpoints.NotFoundException('Game already over')

        user = User.get_user_by_name(request.user_name)
        if user.key != game.next_move:
            raise endpoints.BadRequestException('It\'s not your turn!')

        # Just a dummy signifier, what type of symbol is going down
        x = True if user.key == game.user_x else False

        move = request.move
        # Verify move is valid
        size = game.board_size * game.board_size - 1
        if move < 0 or move > size:
            raise endpoints.BadRequestException('Invalid move! Must be between'
                                                '0 and %s ' % size)
        if game.board[move] != '':
            raise endpoints.BadRequestException('Invalid move!')

        game.board[move] = 'X' if x else 'O'
        # Append a move to the history
        game.history.append(('X' if x else 'O', move))
        game.next_move = game.user_o if x else game.user_x
        # Check if there's a winner
        winner = check_winner(game.board, game.board_size)
        # If there's winner end game
        if winner:
            game.end_game(user.key)
        else:
            # If there's no winner and game board is full end game with tie
            if check_full(game.board):
                # Game tied
                game.end_game()
            else:
                # If game is still ongoing, send remainder email to player
                taskqueue.add(url='/tasks/send_move_email',
                              params={'user_key': game.next_move.urlsafe(),
                                      'game_key': game.key.urlsafe()})
        game.put()
        # If game is over, update memcache
        if game.game_over:
            taskqueue.add(url='/tasks/update_finished_games')
        return game.to_form()
开发者ID:DOlearczyk,项目名称:Tic-tac-toe,代码行数:50,代码来源:api.py

示例8: get_permissions

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_name [as 别名]
def get_permissions():
    user = User.get_user_by_name(request.get_cookie('user'))
    if not user:
        return {
            'can_add': False,
            'can_see': False,
            'can_edit': False,
            'can_delete': False,
            'username': request.get_cookie('user')
        }
    return {
        'can_add': 'a' in user.authstring,
        'can_see': 's' in user.authstring,
        'can_edit': 'e' in user.authstring,
        'can_delete': 'd' in user.authstring,
        'username': request.get_cookie('user')
    }
开发者ID:cptx032,项目名称:linker,代码行数:19,代码来源:site.py

示例9: form_verified

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_name [as 别名]
    def form_verified(self):
        """Called when form is verified."""
        # Make sure user doesn't already exist
        user = User.get_user_by_name(self.user_name)
        if user:
            message = "That user already exists."
            self.render('signup.html', error_username=message)
        else:
            # Create user object in database
            user = User.register(
                self.user_name,
                self.user_password,
                self.user_email)
            user.put()

            # Log the user in and redirect to welcome page
            self.login(user)
            self.redirect('/welcome')
开发者ID:AlbertoALopez,项目名称:gae-cookies,代码行数:20,代码来源:FormHandler.py


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