Beispiel #1
0
def tower(tower_id, decorator=None):
    try:
        towers.garbage_collection(tower_id)
        tower = towers[tower_id]
    except KeyError:
        log('Bad tower_id')
        abort(404)

    # Make sure the Bearer token for the current user is not expired and pass it to the client html
    # This is how the client will be automatically logged in w/o cross-domain cookies
    user_token = '' if current_user.is_anonymous\
                    else current_user.get_token()

    # Pass in both the tower and the user_name
    return render_template('ringing_room.html',
                            tower = tower,
                            user_id = 0 if current_user.is_anonymous else current_user.id,
                            user_name = '' if current_user.is_anonymous else current_user.username,
                            user_email = '' if current_user.is_anonymous else current_user.email,
                            user_badge = '' if current_user.is_anonymous else current_user.badge,
                            user_settings = Config.DEFAULT_SETTINGS if current_user.is_anonymous else current_user.get_settings_with_defaults(),
                            server_ip=get_server_ip(tower_id),
                            user_token = user_token,
                            host_permissions = current_user.check_permissions(tower_id,'host')\
                                                if current_user.is_authenticated else False,
                            listen_link = False)
Beispiel #2
0
 def wrapper(*args, **kwargs):
     token = request.args.get('token')
     try:
         jwt.decode(token, current_user.get_token())
         return f(*args, **kwargs)
     except:
         return jsonify({'error': 'Need a valid token to view this page'}), 401
Beispiel #3
0
def user_settings():
    form = UserSettingsForm()
    del_form = UserDeleteForm()
    if form.submit.data and form.validate_on_submit():
        if not current_user.check_password(form.password.data):
            flash('Incorrect password.')
            return render_template('user_settings.html',form=form, del_form=del_form)
        if form.new_password.data:
            current_user.set_password(form.new_password.data)
            flash('Password updated.')
        if form.new_email.data:
            current_user.email = form.new_email.data.lower()
            flash('Email updated.')
        if form.new_username.data:
            current_user.username = form.new_username.data.strip()
            flash('Username updated.')
        db.session.commit()
        return redirect(url_for('user_settings'))
    if del_form.delete.data and del_form.validate_on_submit():
        if not current_user.check_password(del_form.delete_password.data):
            flash('Incorrect password.')
            return render_template('user_settings.html',form=form, del_form=del_form)
        current_user.clear_all_towers()
        db.session.delete(current_user)
        db.session.commit()
        logout_user()
        return redirect(url_for('index'))
    return render_template('user_settings.html', 
                           form=form, 
                           del_form=del_form, 
                           user_token=current_user.get_token(),
                           user_settings_flag=True)
def run_bash_script(user_folder, str_mandatory_columns, str_optional_columns,
                    history_id):
    try:
        # print(current_user.get_token())
        # print(current_user.company.idnumber)
        # print(str_mandatory_columns)
        # print(str_optional_columns)
        if len(current_user.company.idnumber) > 0:
            script_dir = current_app.config['UPLOAD_FOLDER'] + "script/"
            os.chdir(current_app.config['UPLOAD_FOLDER'] + user_folder)
            out = subprocess.Popen([
                "qsub " + script_dir + 'script.sh {} {} {} {} {} {}'.format(
                    user_folder, current_user.company.idnumber.replace(
                        " ", ","), str_mandatory_columns, str_optional_columns,
                    current_user.get_token(), history_id) + " > jobID"
            ],
                                   shell=True,
                                   close_fds=True)
            # print(out.communicate())
            return {"message": "Your job has been submitted!"}, 200
        return {
            "message":
            " Please enter your IDNUMBER in the company profile section. "
            "We need your company IDNUMBER to validate .sdf file. "
        }, 400
    except AttributeError:
        return {
            "message":
            " Please enter your IDNUMBER in the company profile section. "
            "We need your company IDNUMBER to validate .sdf file. "
        }, 400
    except:
        print(sys.exc_info())
        return {"message": "1: " + str(sys.exc_info()[0])}, 500
Beispiel #5
0
def index(path):
    # check if application is in maintenance mode
    if app.config['MAINTENANCE_MODE']:
        return render_template('maintenance.html')

    # check whether we have authenticated user
    if not current_user.is_authenticated:
        # render out the login page
        return render_template('login.html',
                               login_link=skautis.get_login_url())

    # get base user data
    data = current_user.get_serialized_data()
    data['logout_link'] = skautis.get_logout_url(current_user.get_token())

    # set some response headers
    response = make_response(render_template('app.html', data=data))
    response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
    response.headers["Pragma"] = "no-cache"
    response.headers["Expires"] = "0"

    # return and render out the application (frontend router will handle path)
    return response
Beispiel #6
0
def user_token():
    token = current_user.get_token()
    return render_template("user/token.html", token=token)
Beispiel #7
0
def get_token():
    if not current_user.is_authenticated:
        return jsonify({"error": "Unauthorized"})
    token = current_user.get_token()
    db.session.commit()
    return jsonify({"token": token})
Beispiel #8
0
def get_user_info():
    user = current_user.get_serialized_data()
    user['logout_link'] = skautis.get_logout_url(current_user.get_token())

    return jsonify(user), 200
Beispiel #9
0
def get_token():
    token = current_user.get_token()
    db.session.commit()
    return jsonify({'token': token})
Beispiel #10
0
 def set_current_user_token():
     if current_user.is_authenticated:
         current_user.get_token()
         db_session.add(current_user)
         db_session.commit()
Beispiel #11
0
def get_token():
    token = current_user.get_token()
    return {'token':token}