示例#1
0
def load_logged_in_user():
    mirs = session.get('mirs')

    if mirs is None:
        g.user = None
    else:
        g.user = get_db().query(User).filter_by(mirs = mirs).one()
示例#2
0
def login():
    if request.method == 'POST':
        mirs = request.form['mirs']
        password = request.form['password']
        
        
        db = get_db()
        error = None
        user = db.query(User).filter_by(mirs = mirs).one();
        if user is None:
            error = 'Incorrect username.'
        elif not user.verify_password(password):
            error = 'Incorrect password.'
        elif not user.is_admin:
            print user.is_admin
            error = "Unauthorized User"

        if error is None:
            session.clear()
            session['mirs'] = user.mirs
            return redirect(url_for('locations.index'))

        flash(error)

    return render_template('auth/login.html')
示例#3
0
def register():
    if request.method == 'POST':
        mirs = request.form['mirs']
        password = request.form['password']
        first_name = request.form['first_name']
        last_name = request.form['lastname_name']
        is_admin = request.form['is_admin']
        db = get_db()
        error = None

        if not mirs:
            error = 'mirs is required.'
        elif not password:
            error = 'Password is required.'
        elif not first_name:
            error = 'First name is required.'
        elif not last_name:
            error = 'Password is required.'
        elif db.query(User).filter_by(mirs = mirs).one() is not None:
            error = 'User {} is already registered.'.format(mirs)

        if error is None:
            new_user = User(mirs=mirs,first_name=first_name,last_name=last_name,is_admin=is_admin)
            new_user.hash_password(password)
            db.add()
            db.commit()
            return redirect(url_for('auth.register'))
        
        flash(error)

    return render_template('auth/register.html')
示例#4
0
def create():
    if request.method == 'POST':
        name = request.form['name']
        altitude = request.form['altitude']
        longitude = request.form['longitude']
        error = None

        if not name or not altitude or not longitude:
            error = 'Missing data'

        if error is not None:
            flash(error)
        else:
            db = get_db()
            new_location = Location(name=name,
                                    altitude=altitude,
                                    longitude=longitude)
            db.add(new_location)
            db.commit()
            return redirect(url_for('locations.index'))

    return render_template('locations/create.html')
示例#5
0
def update(id):
    db = get_db()
    location = db.query(Location).filter_by(id=id).one()

    if request.method == 'POST':
        name = request.form['name']
        altitude = request.form['altitude']
        longitude = request.form['longitude']
        error = None

        if not name or not altitude or not longitude:
            error = 'Missing data'

        if error is not None:
            flash(error)
        else:
            location.name = name
            location.altitude = altitude
            location.longitude = longitude
            db.add(location)
            db.commit()
            return redirect(url_for('locations.index'))

    return render_template('locations/update.html', location=location)
示例#6
0
def delete(id):
    db = get_db()
    location = db.query(Location).filter_by(id=id).one()
    db.delete(location)
    db.commit()
    return redirect(url_for('locations.index'))
示例#7
0
def get_all_locations_json():
    db = get_db()
    locations = db.query(Location).all()
    return jsonify(locations=[l.serialize for l in locations])
示例#8
0
def index():
    db = get_db()
    locations = db.query(Location).all()
    return render_template('locations/index.html', locations=locations)