Exemplo n.º 1
0
def authenticate(username, password):
    user = PAUser.query.filter_by(email_address=username).first()
    if user is None:
        raise Unauthorized()

    if not user.logged:
        raise Unauthorized('User is not logged.')

    return user
Exemplo n.º 2
0
        def login():
            try:
                req_auth = request.authorization
            except Exception as e:
                raise Unauthorized('No authorization token provided.')

            if req_auth is None:
                raise Unauthorized('No authorization token provided')

            user = self.login(req_auth.username, req_auth.password)
            return _get_user(user, user.id)
Exemplo n.º 3
0
        def call(*args, **kwargs):
            try:
                req_auth = request.authorization
            except Exception as e:
                raise Unauthorized('No authorization token provided.')

            if req_auth is None:
                raise Unauthorized('No authorization token provided')

            return func(
                self.authenticate(req_auth.username, req_auth.password), *args,
                **kwargs)
Exemplo n.º 4
0
        def call(user, character_id, *args, **kwargs):
            if user.last_character_id != character_id:
                raise Unauthorized('Cannot modify character.')

            character = self.character_class.query.filter_by(
                id=character_id).first()

            return func(user, character, *args, **kwargs)
Exemplo n.º 5
0
def login(email_address, password):
    user = PAUser.query.filter_by(email_address=email_address).first()
    if user is None:
        raise Unauthorized()

    user.logged = True
    db.session.commit()
    character = Pony.query.filter_by(id=user.last_character_id).first()
    if character is not None:
        if character.energy < 0.1:
            character.location = 'ponyland_kindergarden'
            character.energy = 1
            # TODO set right event
            db.session.commit()
    return user
Exemplo n.º 6
0
            def prepared_func(user, *args, **kwargs):
                if user.role == UserRoles.REGULAR:
                    raise Unauthorized('Not for you, little guy.')

                return func(user, *args, **kwargs)
Exemplo n.º 7
0
 def _get_user(user, user_id):
     if user.id != user_id:
         raise Unauthorized(
             'You are not authorized to get other users info.')
     return jsonify(user.to_json())
Exemplo n.º 8
0
 def call(username, password):
     user = func(username, password)
     if user.state != UserStates.ACTIVE:
         raise Unauthorized('Inactive user.')
     return user