示例#1
0
文件: webapp.py 项目: hdemers/passwrd
def webapp():
    try:
        if not is_authorized():
            return to("auth")
        else:
            config = {'userId': session['id'], 'email': session['email'],}
            return render_template("webapp.html", email=session['email'],
                                   config=json.dumps(config))
    except Exception, exception:
        logger.critical(exception)
        logger.debug(traceback.format_exc())
        return error_page(exception)
示例#2
0
文件: auth.py 项目: hdemers/passwrd
def auth():
    try:
        if not is_identified():
            return to("id")
        # We are here because the user has been identified but NOT authorized.
        user = get_user()
        if not user:
            user = create_user()
        # If our user is already authorized to use the service, skip the
        # authorization and let's go.
        if is_authorized():
            logger.debug("User %s is authorized." % user.id)
            return next_on()
        else:
            logger.debug("User %s is NOT authorized." % user.id)
            # Render the payment page. 
            return payment(user)
    except Exception, exception:
        logger.critical("Exception: %s" % exception)
        logger.debug(traceback.format_exc())
        return error_page(exception)
示例#3
0
文件: auth.py 项目: hdemers/passwrd
        logger.debug(traceback.format_exc())
        return error_page(exception)

# If we have an authorization state, this mean we're coming from our payment
# processor.
@app.route("/auth/<state>/")
def recurly_callback(state):
    try:
        user_id = request.args.get('id', None)
        plan = request.args.get('plan', None)
        if state in ['success', 'cancel'] and user_id and plan:
            return process_subscription_result(state, user, user_id, plan)
    except Exception, exception:
        logger.critical("Exception: %s" % exception)
        logger.debug(traceback.format_exc())
    return error_page()

def create_user():
    # Create a new user.
    user = User.create(session.get('identity'), session.get('email'))
    # The user has been created, update the session.
    user.sync(session)
    first_time_user()
    return user

def get_user():
    user = User.get(session.get('identity'))
    if user:
        user.sync(session)
    return user