Esempio n. 1
0
def login():
    destination = request.args.get('next')
    if request.method == 'POST':
        resp_json = api_get("/user", uauth=(request.form['username'], request.form['password']))
        if 'username' in resp_json:
            session['logged_in'] = True
            resp_json['wurd'] = request.form['password']
            session['user'] = User(**resp_json)
            update_status_details()
            logger.info("User %s logged in\n" % session['user'].username)
            # send the user back to their
            # originally requested destination
            if destination and destination != 'None':
                return redirect(destination)
            else:
                return redirect(url_for('index'))
        else:
            logger.info("**** Failed user login %s \n" % request.form['username'])
            flash(format_errors(resp_json['msg']), 'error')
            _status = 401
    else:
        _status = 200
        if 'user' not in session:
            session['user'] = None

    in_ops = 'ESPA_ENV' in os.environ and os.environ['ESPA_ENV'] == 'ops'
    explorer = "http://earthexplorer.usgs.gov" if in_ops else "http://eedevmast.cr.usgs.gov"
    reg_host = "https://ers.cr.usgs.gov" if in_ops else "http://ersdevmast.cr.usgs.gov"

    return render_template('login.html', next=destination,
                           earthexplorer=explorer,
                           register_user=reg_host+"/register",
                           forgot_login=reg_host+"/password/request"), _status
Esempio n. 2
0
def login():
    destination = request.args.get('next')
    if request.method == 'POST':
        resp_json = api_get("/user",
                            uauth=(request.form['username'],
                                   request.form['password']))
        if 'username' in resp_json:
            session['logged_in'] = True
            resp_json['wurd'] = request.form['password']
            session['user'] = User(**resp_json)
            update_status_details()
            logger.info("User %s logged in\n" % session['user'].username)
            # send the user back to their
            # originally requested destination
            if destination and destination != 'None':
                return redirect(destination)
            else:
                return redirect(url_for('index'))
        else:
            logger.info("**** Failed user login %s \n" %
                        request.form['username'])
            flash(format_errors(resp_json['msg']), 'error')
            _status = 401
    else:
        _status = 200
        if 'user' not in session:
            session['user'] = None

    in_ops = 'ESPA_ENV' in os.environ and os.environ['ESPA_ENV'] == 'ops'
    explorer = "http://earthexplorer.usgs.gov" if in_ops else "http://eedevmast.cr.usgs.gov"
    reg_host = "https://ers.cr.usgs.gov" if in_ops else "http://ersdevmast.cr.usgs.gov"

    return render_template('login.html',
                           next=destination,
                           earthexplorer=explorer,
                           register_user=reg_host + "/register",
                           forgot_login=reg_host +
                           "/password/request"), _status
Esempio n. 3
0
    response_data = response.json()
    logger.info('Response from API: {}'.format(response_data))

    # hack till we settle on msg or message
    if 'message' in response_data:
        response_data['msg'] = response_data['message']

    if response.status_code == 200:
        flash("Order submitted successfully! Your OrderId is {}".format(
            response_data['orderid']))
        logger.info("successful order submission for user %s\n\n orderid: %s" %
                    (session['user'].username, response_data['orderid']))
        rdest = redirect('/ordering/order-status/{}/'.format(
            response_data['orderid']))
    else:
        flash(format_errors(response_data["msg"]), 'error')
        logger.info(
            "problem with order submission for user %s\n\n message: %s\n\n" %
            (session['user'].username, response_data['msg']))
        _dest = url_for('new_external_order') if _external else url_for(
            'new_order')
        rdest = redirect(_dest)

    return rdest


@espaweb.route('/ordering/status/')
@espaweb.route('/ordering/status/<email>/')
@login_required
def list_orders(email=None):
    url = "/list-orders-ext"
Esempio n. 4
0
    logger.info('Order out to API: {}'.format(out_dict))
    response = api_up("/order", out_dict)
    response_data = response.json()
    logger.info('Response from API: {}'.format(response_data))

    # hack till we settle on msg or message
    if 'message' in response_data:
        response_data['msg'] = response_data['message']

    if response.status_code == 200:
        flash("Order submitted successfully! Your OrderId is {}".format(response_data['orderid']))
        logger.info("successful order submission for user %s\n\n orderid: %s" % (session['user'].username,
                                                                                 response_data['orderid']))
        rdest = redirect('/ordering/order-status/{}/'.format(response_data['orderid']))
    else:
        flash(format_errors(response_data["msg"]), 'error')
        logger.info("problem with order submission for user %s\n\n message: %s\n\n" % (session['user'].username,
                                                                                       response_data['msg']))
        _dest = url_for('new_external_order') if _external else url_for('new_order')
        rdest = redirect(_dest)

    return rdest


@espaweb.route('/ordering/status/')
@espaweb.route('/ordering/status/<email>/')
@login_required
def list_orders(email=None):
    url = "/list-orders-ext"
    for_user = session['user'].email
    if email: