Пример #1
0
    def userNameRequestReceived(self, host, port, key, payload):
        """The client asks for the display name of a user account."""

        if len(payload) != 8: return

        pilot = User.by_tracking_key(key)
        if pilot is None:
            log.err("No such pilot: %d" % key)
            return

        data = struct.unpack('!II', payload)
        user_id = data[0]

        user = User.get(user_id)
        if user is None:
            response = struct.pack('!IHHQIIIBBBBII', MAGIC, 0,
                                   TYPE_USER_NAME_RESPONSE, 0, user_id,
                                   USER_FLAG_NOT_FOUND, 0, 0, 0, 0, 0, 0, 0)
            response = set_crc(response)
            self.transport.write(response, (host, port))
            return

        name = user.name[:64].encode('utf8', 'ignore')
        club_id = user.club_id or 0

        response = struct.pack('!IHHQIIIBBBBII', MAGIC, 0,
                               TYPE_USER_NAME_RESPONSE, 0, user_id, 0, club_id,
                               len(name), 0, 0, 0, 0, 0)
        response += name
        response = set_crc(response)
        self.transport.write(response, (host, port))
Пример #2
0
    def userNameRequestReceived(self, host, port, key, payload):
        """The client asks for the display name of a user account."""

        if len(payload) != 8: return

        pilot = User.by_tracking_key(key)
        if pilot is None:
            log.err("No such pilot: %d" % key)
            return

        data = struct.unpack('!II', payload)
        user_id = data[0]

        user = User.get(user_id)
        if user is None:
            response = struct.pack('!IHHQIIIBBBBII', MAGIC, 0, TYPE_USER_NAME_RESPONSE, 0,
                                   user_id, USER_FLAG_NOT_FOUND, 0,
                                   0, 0, 0, 0, 0, 0)
            response = set_crc(response)
            self.transport.write(response, (host, port))
            return

        name = user.name[:64].encode('utf8', 'ignore')
        club_id = user.club_id or 0

        response = struct.pack('!IHHQIIIBBBBII', MAGIC, 0, TYPE_USER_NAME_RESPONSE, 0,
                               user_id, 0, club_id,
                               len(name), 0, 0, 0, 0, 0)
        response += name
        response = set_crc(response)
        self.transport.write(response, (host, port))
Пример #3
0
def recover_step1_post(json):
    try:
        data = CurrentUserSchema(only=("email", )).load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    user = User.by_email_address(data["email_address"])
    if not user:
        return jsonify(error="email-unknown"), 422

    user.generate_recover_key(request.remote_addr)

    current_user = User.get(request.user_id) if request.user_id else None
    if current_user.admin:
        url = u"http://skylines.aero/users/recover?key=%x" % user.recover_key
        return jsonify(url=url)

    try:
        send_recover_mail(user)
    except ServiceUnavailable:
        return jsonify(error="mail-service-unavailable"), 503

    db.session.commit()

    return jsonify()
Пример #4
0
def test_admin():
    u = User()
    u.first_name = u'Example'
    u.last_name = u'Manager'
    u.email_address = u'*****@*****.**'
    u.password = u.original_password = u'managepass'
    u.admin = True
    return u
Пример #5
0
def test_admin():
    u = User()
    u.first_name = u"Example"
    u.last_name = u"Manager"
    u.email_address = u"*****@*****.**"
    u.password = u.original_password = u"managepass"
    u.admin = True
    return u
Пример #6
0
def test_user():
    u1 = User()
    u1.first_name = u'Example'
    u1.last_name = u'User'
    u1.email_address = u'*****@*****.**'
    u1.password = u1.original_password = u'test'
    u1.tracking_key = 123456
    return u1
Пример #7
0
def new_post(form):
    user = User(first_name=form.first_name.data,
                last_name=form.last_name.data,
                email_address=form.email_address.data,
                password=form.password.data)

    user.created_ip = request.remote_addr
    db.session.add(user)

    create_new_user_event(user)

    db.session.commit()

    return redirect(url_for('index'))
Пример #8
0
    def new_post(self, display_name, club, email_address, password, **kw):
        if not club:
            club = None

        user = User(display_name=display_name, club_id=club,
                    email_address=email_address, password=password)
        user.created_ip = request.remote_addr
        user.generate_tracking_key()
        DBSession.add(user)

        pilots = DBSession.query(Group).filter(Group.group_name == 'pilots').first()
        if pilots:
            pilots.users.append(user)

        redirect('/')
Пример #9
0
def test_hash_password():
    hash = User._hash_password(u"secret123", salt=b"abcdef")
    assert (
        hash
        == "bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721272b82aa344691fb4037f20617b1d19212042e7e6cb39f4ba0dad95d8137104a"
    )
    assert is_unicode(hash)
Пример #10
0
def test_user(db):
    user = User(email_address=u"*****@*****.**",
                password=u"secret123",
                first_name=u"test")
    db.session.add(user)
    db.session.commit()
    return user
Пример #11
0
 def setup(self):
     self.bill = User(first_name='bill',
                      email_address='*****@*****.**',
                      password='******')
     db.session.add(self.bill)
     db.session.commit()
     self.login('*****@*****.**', 'pass')
Пример #12
0
def check_email():
    current_user = User.get(request.user_id) if request.user_id else None

    json = request.get_json()
    if not json:
        return jsonify(error='invalid-request'), 400

    email = json.get('email', '')

    result = 'available'
    if current_user and email == current_user.email_address:
        result = 'self'
    elif User.exists(email_address=email):
        result = 'unavailable'

    return jsonify(result=result)
Пример #13
0
def check_email():
    current_user = User.get(request.user_id) if request.user_id else None

    json = request.get_json()
    if not json:
        return jsonify(error='invalid-request'), 400

    email = json.get('email', '')

    result = 'available'
    if current_user and email == current_user.email_address:
        result = 'self'
    elif User.exists(email_address=email):
        result = 'unavailable'

    return jsonify(result=result)
Пример #14
0
def new_post(form):
    user = User(
        first_name=form.first_name.data,
        last_name=form.last_name.data,
        email_address=form.email_address.data,
        password=form.password.data
    )

    user.created_ip = request.remote_addr
    db.session.add(user)

    create_new_user_event(user)

    db.session.commit()

    return redirect(url_for('index'))
Пример #15
0
def check_email():
    current_user = User.get(request.user_id) if request.user_id else None

    json = request.get_json()
    if not json:
        return jsonify(error="invalid-request"), 400

    email = json.get("email", "")

    result = "available"
    if current_user and email == current_user.email_address:
        result = "self"
    elif User.exists(email_address=email):
        result = "unavailable"

    return jsonify(result=result)
Пример #16
0
def near(flight_id):
    flight = get_requested_record(Flight, flight_id, joinedload=[Flight.igc_file])

    current_user = User.get(request.user_id) if request.user_id else None
    if not flight.is_viewable(current_user):
        return jsonify(), 404

    try:
        latitude = float(request.args["lat"])
        longitude = float(request.args["lon"])
        time = float(request.args["time"])

    except (KeyError, ValueError):
        abort(400)

    location = Location(latitude=latitude, longitude=longitude)
    time = from_seconds_of_day(flight.takeoff_time, time)

    flights = _get_near_flights(flight, location, time, 1000)

    def add_flight_path(flight):
        trace = _get_flight_path(flight, threshold=0.0001, max_points=10000)
        trace["additional"] = dict(registration=flight.registration, competition_id=flight.competition_id)

        return trace

    return jsonify(flights=map(add_flight_path, flights))
Пример #17
0
def update(club_id):
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error='invalid-token'), 401

    club = get_requested_record(Club, club_id)
    if not club.is_writable(current_user):
        return jsonify(error='forbidden'), 403

    json = request.get_json()
    if json is None:
        return jsonify(error='invalid-request'), 400

    try:
        data = ClubSchema(partial=True).load(json).data
    except ValidationError as e:
        return jsonify(error='validation-failed', fields=e.messages), 422

    if 'name' in data:
        name = data.get('name')

        if name != club.name and Club.exists(name=name):
            return jsonify(error='duplicate-club-name'), 422

        club.name = name

    if 'website' in data:
        club.website = data.get('website')

    db.session.commit()

    return jsonify()
Пример #18
0
def read(user_id):
    user = User.get(user_id)
    if user is None:
        raise NotFound()

    result = user_schema.dump(user)
    return jsonify(result.data)
Пример #19
0
def add_comment(flight_id):
    flight = get_requested_record(Flight, flight_id)

    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(), 403

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = FlightCommentSchema().load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    comment = FlightComment()
    comment.user = current_user
    comment.flight = flight
    comment.text = data["text"]

    create_flight_comment_notifications(comment)

    db.session.commit()

    return jsonify()
Пример #20
0
    def verify_request(self, scopes):
        if request.authorization:
            from skylines.model import User

            username = request.authorization.username
            if is_bytes(username):
                username = username.decode("utf-8")

            password = request.authorization.password
            if is_bytes(password):
                password = password.decode("utf-8")

            user = User.by_credentials(username, password)

            request.user_id = user.id if user else None
            set_sentry_user({"id": request.user_id})

            return (user is not None), None

        else:
            valid, req = super(CustomProvider, self).verify_request(scopes)

            request.user_id = req.access_token.user_id if valid else None
            set_sentry_user({"id": request.user_id})

            return valid, req
Пример #21
0
def test_hash_password():
    hash = User._hash_password(u"secret123", salt=b"abcdef")
    assert (
        hash
        == "bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721272b82aa344691fb4037f20617b1d19212042e7e6cb39f4ba0dad95d8137104a"
    )
    assert is_unicode(hash)
Пример #22
0
def follow(user_id):
    user = get_requested_record(User, user_id)
    current_user = User.get(request.user_id)
    Follower.follow(current_user, user)
    create_follower_notification(user, current_user)
    db.session.commit()
    return jsonify()
Пример #23
0
def test_user(db):
    user = User(email_address=u'*****@*****.**',
                password=u'secret123',
                first_name=u'test')
    db.session.add(user)
    db.session.commit()
    return user
Пример #24
0
def create_club():
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error="invalid-token"), 401

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = ClubSchema(only=("name",)).load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    if Club.exists(name=data.get("name")):
        return jsonify(error="duplicate-club-name"), 422

    # create the new club
    club = Club(**data)
    club.owner_id = current_user.id
    db.session.add(club)
    db.session.flush()

    # assign the user to the new club
    current_user.club = club

    # create the "user joined club" event
    create_club_join_event(club.id, current_user)

    db.session.commit()

    return jsonify(id=club.id)
Пример #25
0
def check_email():
    current_user = User.get(request.user_id) if request.user_id else None

    json = request.get_json()
    if not json:
        return jsonify(error="invalid-request"), 400

    email = json.get("email", "")

    result = "available"
    if current_user and email == current_user.email_address:
        result = "self"
    elif User.exists(email_address=email):
        result = "unavailable"

    return jsonify(result=result)
Пример #26
0
    def validate_email_address(form, field):
        if field.data == field.object_data:
            return

        if User.exists(email_address=field.data):
            raise ValidationError(
                l_('A pilot with this email address exists already.'))
Пример #27
0
def read():
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error='invalid-token'), 401

    schema = CurrentUserSchema(exclude=('id'))
    return jsonify(schema.dump(current_user).data)
Пример #28
0
    def login():
        if g.current_user:
            return redirect(get_next())

        form = g.login_form

        if form.validate_on_submit():
            # Find a user matching the credentials
            user = User.by_credentials(form.email_address.data,
                                       form.password.data)

            # Check if the user wants a cookie
            remember = form.remember_me.data

            # Check if a user was found and try to login
            if user and login_user(user, remember=remember):
                user.login_ip = request.remote_addr
                user.login_time = datetime.utcnow()

                flash(_('You are now logged in. Welcome back, %(user)s!', user=user))
                return redirect(get_next())
            else:
                form.email_address.errors.append(_('Login failed. Please check your eMail address.'))
                form.password.errors.append(_('Login failed. Please check your password.'))

        return render_template('login.jinja', form=form, next=get_next())
Пример #29
0
    def run(self, user_id):
        user = User.get(user_id)
        if not user:
            print 'User with id "{}" not found.'.format(user_id)
            sys.exit(1)

        i = randint(0, 100)
        _longitude = randint(6500, 7500) / 1000.
        _latitude = randint(50500, 51500) / 1000.
        _altitude = 500

        while True:
            longitude = sin(i / 73.) * 0.001 + _longitude
            latitude = sin(i / 50.) * 0.004 + _latitude
            altitude = sin(i / 20.) * 300 + _altitude

            fix = TrackingFix()
            fix.pilot = user
            fix.set_location(longitude, latitude)
            fix.altitude = altitude
            fix.time = datetime.now()
            fix.time_visible = fix.time + timedelta(minutes=user.tracking_delay)

            db.session.add(fix)
            db.session.commit()

            print '.',
            sys.stdout.flush()

            sleep(1)

            i += 1
Пример #30
0
    def trafficRequestReceived(self, host, port, key, payload):
        if len(payload) != 8: return

        pilot = User.by_tracking_key(key)
        if pilot is None:
            log.err("No such pilot: %d" % key)
            return

        data = struct.unpack('!II', payload)
        or_filters = []

        flags = data[0]
        if flags & TRAFFIC_FLAG_FOLLOWEES:
            subq = db.session \
                .query(Follower.destination_id) \
                .filter(Follower.source_id == pilot.id) \
                .subquery()

            or_filters.append(TrackingFix.pilot_id.in_(subq))

        if flags & TRAFFIC_FLAG_CLUB:
            subq = db.session \
                .query(User.id) \
                .filter(User.club_id == pilot.club_id) \
                .subquery()

            or_filters.append(TrackingFix.pilot_id.in_(subq))

        if len(or_filters) == 0:
            return

        query = TrackingFix.query() \
            .distinct(TrackingFix.pilot_id) \
            .filter(and_(TrackingFix.time >= datetime.utcnow() - timedelta(hours=2),
                         TrackingFix.pilot_id != pilot.id,
                         TrackingFix.location_wkt != None,
                         TrackingFix.altitude != None,
                         or_(*or_filters))) \
            .order_by(TrackingFix.pilot_id, TrackingFix.time.desc()) \
            .limit(32)

        response = ''
        count = 0
        for fix in query:
            location = fix.location
            if location is None: continue

            t = fix.time
            t = t.hour * 3600000 + t.minute * 60000 + t.second * 1000 + t.microsecond / 1000
            response += struct.pack('!IIiihHI', fix.pilot_id, t,
                                    int(location.latitude * 1000000),
                                    int(location.longitude * 1000000),
                                    int(fix.altitude), 0, 0)
            count += 1

        response = struct.pack('!HBBI', 0, 0, count, 0) + response
        response = struct.pack('!IHHQ', MAGIC, 0, TYPE_TRAFFIC_RESPONSE,
                               0) + response
        response = set_crc(response)
        self.transport.write(response, (host, port))
Пример #31
0
def follow(user_id):
    user = get_requested_record(User, user_id)
    current_user = User.get(request.user_id)
    Follower.follow(current_user, user)
    create_follower_notification(user, current_user)
    db.session.commit()
    return jsonify()
Пример #32
0
def test_users(n=50):
    fake = Faker(locale='de_DE')
    fake.seed(42)

    users = []
    for i in xrange(n):
        u = User()
        u.first_name = fake.first_name()
        u.last_name = fake.last_name()
        u.email_address = fake.email()
        u.password = u.original_password = fake.password()
        u.tracking_key = fake.random_number(digits=6)

        users.append(u)

    return users
Пример #33
0
def update(club_id):
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error="invalid-token"), 401

    club = get_requested_record(Club, club_id)
    if not club.is_writable(current_user):
        return jsonify(error="forbidden"), 403

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = ClubSchema(partial=True).load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    if "name" in data:
        name = data.get("name")

        if name != club.name and Club.exists(name=name):
            return jsonify(error="duplicate-club-name"), 422

        club.name = name

    if "website" in data:
        club.website = data.get("website")

    db.session.commit()

    return jsonify()
Пример #34
0
def near(flight_id):
    flight = get_requested_record(Flight,
                                  flight_id,
                                  joinedload=[Flight.igc_file])

    current_user = User.get(request.user_id) if request.user_id else None
    if not flight.is_viewable(current_user):
        return jsonify(), 404

    try:
        latitude = float(request.args['lat'])
        longitude = float(request.args['lon'])
        time = float(request.args['time'])

    except (KeyError, ValueError):
        abort(400)

    location = Location(latitude=latitude, longitude=longitude)
    time = from_seconds_of_day(flight.takeoff_time, time)

    flights = _get_near_flights(flight, location, time, 1000)

    def add_flight_path(flight):
        trace = _get_flight_path(flight, threshold=0.0001, max_points=10000)
        trace['additional'] = dict(registration=flight.registration,
                                   competition_id=flight.competition_id)

        return trace

    return jsonify(flights=map(add_flight_path, flights))
Пример #35
0
def add_comment(flight_id):
    flight = get_requested_record(Flight, flight_id)

    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(), 403

    json = request.get_json()
    if json is None:
        return jsonify(error='invalid-request'), 400

    try:
        data = FlightCommentSchema().load(json).data
    except ValidationError as e:
        return jsonify(error='validation-failed', fields=e.messages), 422

    comment = FlightComment()
    comment.user = current_user
    comment.flight = flight
    comment.text = data['text']

    create_flight_comment_notifications(comment)

    db.session.commit()

    return jsonify()
Пример #36
0
def pilots():
    users = User.query(club=g.club).order_by(func.lower(User.name))

    return render_template('clubs/pilots.jinja',
                           active_page='settings',
                           club=g.club,
                           users=users)
Пример #37
0
def create_club():
    '''register new club'''
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error="invalid-token"), 401

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = ClubSchema(only=("name","email","website")).load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    if Club.exists(name=data.get("name")):
        return jsonify(error="duplicate-club-name"), 422

    # create the new club
    club = Club(**data)
    club.owner_id = current_user.id

    db.session.add(club)
    db.session.flush()

    # assign the user to the new club
    current_user.club = club

    # create the "user joined club" event
    create_club_join_event(club.id, current_user)

    db.session.commit()

    return jsonify(id=club.id)
Пример #38
0
    def login():
        if g.current_user:
            return redirect(get_next())

        form = g.login_form

        if form.validate_on_submit():
            # Find a user matching the credentials
            user = User.by_credentials(form.email_address.data,
                                       form.password.data)

            # Check if the user wants a cookie
            remember = form.remember_me.data

            # Check if a user was found and try to login
            if user and login_user(user, remember=remember):
                user.login_ip = request.remote_addr
                user.login_time = datetime.utcnow()

                flash(
                    _('You are now logged in. Welcome back, %(user)s!',
                      user=user))
                return redirect(get_next())
            else:
                form.email_address.errors.append(
                    _('Login failed. Please check your email address.'))
                form.password.errors.append(
                    _('Login failed. Please check your password.'))

        return render_template('login.jinja', form=form, next=get_next())
Пример #39
0
def read():
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error='invalid-token'), 401

    schema = CurrentUserSchema(exclude=('id'))
    return jsonify(schema.dump(current_user).data)
Пример #40
0
    def trafficRequestReceived(self, host, port, key, payload):
        if len(payload) != 8: return

        pilot = User.by_tracking_key(key)
        if pilot is None:
            log.err("No such pilot: %d" % key)
            return

        data = struct.unpack('!II', payload)
        or_filters = []

        flags = data[0]
        if flags & TRAFFIC_FLAG_FOLLOWEES:
            subq = db.session \
                .query(Follower.destination_id) \
                .filter(Follower.source_id == pilot.id) \
                .subquery()

            or_filters.append(TrackingFix.pilot_id.in_(subq))

        if flags & TRAFFIC_FLAG_CLUB:
            subq = db.session \
                .query(User.id) \
                .filter(User.club_id == pilot.club_id) \
                .subquery()

            or_filters.append(TrackingFix.pilot_id.in_(subq))

        if len(or_filters) == 0:
            return

        query = TrackingFix.query() \
            .distinct(TrackingFix.pilot_id) \
            .filter(and_(TrackingFix.time >= datetime.utcnow() - timedelta(hours=2),
                         TrackingFix.pilot_id != pilot.id,
                         TrackingFix.location_wkt != None,
                         TrackingFix.altitude != None,
                         or_(*or_filters))) \
            .order_by(TrackingFix.pilot_id, TrackingFix.time.desc()) \
            .limit(32)

        response = ''
        count = 0
        for fix in query:
            location = fix.location
            if location is None: continue

            t = fix.time
            t = t.hour * 3600000 + t.minute * 60000 + t.second * 1000 + t.microsecond / 1000
            response += struct.pack('!IIiihHI', fix.pilot_id, t,
                                    int(location.latitude * 1000000),
                                    int(location.longitude * 1000000),
                                    int(fix.altitude), 0, 0)
            count += 1

        response = struct.pack('!HBBI', 0, 0, count, 0) + response
        response = struct.pack('!IHHQ', MAGIC, 0, TYPE_TRAFFIC_RESPONSE, 0) + response
        response = set_crc(response)
        self.transport.write(response, (host, port))
    def run(self, user_id):
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        user = User.get(user_id)
        if not user:
            print('User with id "{}" not found.'.format(user_id))
            sys.exit(1)

        start_time = datetime.utcnow()

        i = randint(0, 100)
        _time = (
            start_time.hour * 60 * 60 * 1000
            + start_time.minute * 60 * 1000
            + start_time.second * 1000
        )
        _longitude = randint(6500, 7500) / 1000.0
        _latitude = randint(50500, 51500) / 1000.0
        _altitude = 500

        while True:
            longitude = sin(i / 73.0) * 0.001 + _longitude
            latitude = sin(i / 50.0) * 0.004 + _latitude
            altitude = sin(i / 20.0) * 300 + _altitude

            flags = FLAG_LOCATION | FLAG_ALTITUDE
            fix = TrackingFix()
            fix.pilot_id = user.id
            fix.set_location(longitude, latitude)
            fix.altitude = altitude

            data = struct.pack(
                "!IHHQIIiiIHHHhhH",
                MAGIC,
                0,
                TYPE_FIX,
                user.tracking_key,
                flags,
                _time,
                int(latitude * 1000000),
                int(longitude * 1000000),
                0,
                0,
                0,
                0,
                int(altitude),
                0,
                0,
            )
            data = set_crc(data)
            sock.sendto(data, self.ADDRESS)

            print(".", end="")
            sys.stdout.flush()

            sleep(1)

            i += 1
            _time += 1000
Пример #42
0
 def load_user_from_header(header_val):
     try:
         header_val = header_val.replace('Basic ', '', 1)
         header_val = base64.b64decode(header_val)
         email, password = header_val.split(':', 1)
         return User.by_credentials(email, password)
     except:
         return None
Пример #43
0
def _patch_query(q):
    current_user = User.get(request.user_id) if request.user_id else None

    return (
        q.join(Flight.igc_file)
        .options(contains_eager(Flight.igc_file))
        .filter(Flight.is_viewable(current_user))
    )
Пример #44
0
def _list(args):
    offset = (args['page'] - 1) * args['per_page']
    limit = args['per_page']

    users = User.query().offset(offset).limit(limit)
    result = user_list_schema.dump(users, many=True)

    return jsonify(result.data)
Пример #45
0
def index():
    users = User.query() \
        .options(joinedload(User.club)) \
        .order_by(func.lower(User.name))

    return render_template('users/list.jinja',
                           active_page='settings',
                           users=users)
Пример #46
0
 def load_user_from_header(header_val):
     try:
         header_val = header_val.replace('Basic ', '', 1)
         header_val = base64.b64decode(header_val)
         email, password = header_val.split(':', 1)
         return User.by_credentials(email, password)
     except:
         return None
Пример #47
0
def _patch_query(q):
    current_user = User.get(request.user_id) if request.user_id else None

    return (
        q.join(Flight.igc_file)
        .options(contains_eager(Flight.igc_file))
        .filter(Flight.is_viewable(current_user))
    )
Пример #48
0
def _list(args):
    offset = (args['page'] - 1) * args['per_page']
    limit = args['per_page']

    users = User.query().offset(offset).limit(limit)
    result = user_list_schema.dump(users, many=True)

    return jsonify(result.data)
Пример #49
0
def index():
    users = User.query() \
        .options(joinedload(User.club)) \
        .order_by(func.lower(User.name))

    return render_template('users/list.jinja',
                           active_page='settings',
                           users=users)
Пример #50
0
def mark_user_notifications_read(user):
    if not request.user_id:
        return

    def add_user_filter(query):
        return query.filter(Event.actor_id == user.id)

    Notification.mark_all_read(User.get(request.user_id), filter_func=add_user_filter)
    db.session.commit()
Пример #51
0
    def recover_email(self, email_address, **kw):
        user = User.by_email_address(email_address)
        if user is None:
            raise HTTPNotFound

        recover_user_password(user)

        flash('Check your email, we have sent you a link to recover your password.')
        redirect('/')
Пример #52
0
def tracking_generate_key():
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error='invalid-token'), 401

    current_user.generate_tracking_key()
    db.session.commit()

    return jsonify(key=current_user.tracking_key_hex)
Пример #53
0
def new_post(form):
    user = User(first_name=form.first_name.data,
                last_name=form.last_name.data,
                email_address=form.email_address.data,
                password=form.password.data)

    user.created_ip = request.remote_addr
    db.session.add(user)

    create_new_user_event(user)

    db.session.commit()

    flash(
        _('Welcome to SkyLines, %(user)s! You can now log in and share your flights with the world!',
          user=user))

    return redirect(url_for('index'))
Пример #54
0
def read(club_id):
    current_user = User.get(request.user_id) if request.user_id else None

    club = get_requested_record(Club, club_id)

    json = ClubSchema().dump(club).data
    json["isWritable"] = club.is_writable(current_user) or False

    return jsonify(json)
Пример #55
0
    def run(self, user_id):
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        user = User.get(user_id)
        if not user:
            print('User with id "{}" not found.'.format(user_id))
            sys.exit(1)

        start_time = datetime.utcnow()

        i = randint(0, 100)
        _time = (start_time.hour * 60 * 60 * 1000 +
                 start_time.minute * 60 * 1000 +
                 start_time.second * 1000)
        _longitude = randint(6500, 7500) / 1000.
        _latitude = randint(50500, 51500) / 1000.
        _altitude = 500

        while True:
            longitude = sin(i / 73.) * 0.001 + _longitude
            latitude = sin(i / 50.) * 0.004 + _latitude
            altitude = sin(i / 20.) * 300 + _altitude

            flags = FLAG_LOCATION | FLAG_ALTITUDE
            fix = TrackingFix()
            fix.pilot_id = user.id
            fix.set_location(longitude, latitude)
            fix.altitude = altitude

            data = struct.pack(
                '!IHHQIIiiIHHHhhH',
                MAGIC,
                0,
                TYPE_FIX,
                user.tracking_key,
                flags,
                _time,
                int(latitude * 1000000),
                int(longitude * 1000000),
                0,
                0,
                0,
                0,
                altitude,
                0,
                0,
            )
            data = set_crc(data)
            sock.sendto(data, self.ADDRESS)

            print('.', end='')
            sys.stdout.flush()

            sleep(1)

            i += 1
            _time += 1000
Пример #56
0
def new_post(form):
    user = User(
        first_name=form.first_name.data,
        last_name=form.last_name.data,
        email_address=form.email_address.data,
        password=form.password.data
    )

    user.created_ip = request.remote_addr
    db.session.add(user)

    create_new_user_event(user)

    db.session.commit()

    flash(_('Welcome to SkyLines, %(user)s! You can now log in and share your flights with the world!', user=user))

    return redirect(url_for('index'))
Пример #57
0
def read(club_id):
    current_user = User.get(request.user_id) if request.user_id else None

    club = get_requested_record(Club, club_id)

    json = ClubSchema().dump(club).data
    json["isWritable"] = club.is_writable(current_user) or False

    return jsonify(json)
Пример #58
0
def tracking_generate_key():
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error='invalid-token'), 401

    current_user.generate_tracking_key()
    db.session.commit()

    return jsonify(key=current_user.tracking_key_hex)