Esempio n. 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))
Esempio n. 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))
Esempio n. 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()
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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'))
Esempio n. 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('/')
Esempio n. 9
0
def test_hash_password():
    hash = User._hash_password(u"secret123", salt=b"abcdef")
    assert (
        hash
        == "bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721272b82aa344691fb4037f20617b1d19212042e7e6cb39f4ba0dad95d8137104a"
    )
    assert is_unicode(hash)
Esempio n. 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
Esempio n. 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')
Esempio n. 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)
Esempio n. 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)
Esempio n. 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'))
Esempio n. 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)
Esempio n. 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))
Esempio n. 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()
Esempio n. 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)
Esempio n. 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()
Esempio n. 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
Esempio n. 21
0
def test_hash_password():
    hash = User._hash_password(u"secret123", salt=b"abcdef")
    assert (
        hash
        == "bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721272b82aa344691fb4037f20617b1d19212042e7e6cb39f4ba0dad95d8137104a"
    )
    assert is_unicode(hash)
Esempio n. 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()
Esempio n. 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
Esempio n. 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)
Esempio n. 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)
Esempio n. 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.'))
Esempio n. 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)
Esempio n. 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())
Esempio n. 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
Esempio n. 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))
Esempio n. 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()
Esempio n. 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
Esempio n. 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()
Esempio n. 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))
Esempio n. 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()
Esempio n. 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)
Esempio n. 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)
Esempio n. 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())
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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))
    )
Esempio n. 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)
Esempio n. 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)
Esempio n. 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
Esempio n. 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))
    )
Esempio n. 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)
Esempio n. 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)
Esempio n. 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()
Esempio n. 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('/')
Esempio n. 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)
Esempio n. 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'))
Esempio n. 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)
Esempio n. 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
Esempio n. 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'))
Esempio n. 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)
Esempio n. 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)