def evesso_authorized():
    resp = evesso.authorized_response()
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    if isinstance(resp, Exception):
        return 'Access denied: error=%s' % str(resp)

    session['evesso_token'] = (resp['access_token'], '')

    me = evesso.get("verify")
    user_data = me.data

    provider_id = "%r%r" % (user_data['CharacterID'], user_data['CharacterOwnerHash'])
    user = db.session.query(User).filter_by(provider_id=provider_id).filter_by(
        provider_name='eve').first()
    if not user:
        # noinspection PyArgumentList
        user = User.create(commit=False, provider_id=provider_id, provider_name='eve')
    user.character_id = user_data["CharacterID"]
    user.character_name = user_data["CharacterName"]
    user.save()
    user.login()
    return redirect(url_for("index"))
Exemple #2
0
def debug_login():
    if not current_app.debug:
        abort(404)
    form = DebugLoginForm(request.form)
    if form.validate():
        provider_id = str(form.character_id)
        user = db.session.query(User).filter_by(provider_id=provider_id).filter_by(
            provider_name='debug').first()
        if not user:
            # noinspection PyArgumentList
            user = User.create(commit=False, provider_id=provider_id, provider_name='debug', admin=True)
        user.character_id = form.character_id
        user.character_name = form.character_name
        user.save()
        user.login()
        return redirect(url_for("index"))

    return render_template("login.html", form=form)
def authorized():
    resp = twobad.authorized_response()
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error'],
            request.args['error_description']
        )
    if isinstance(resp, OAuthException):
        return 'Access denied: %r' % resp
    session['twobad_token'] = (resp['access_token'], '')
    me = twobad.get('me')
    if me.data["success"]:
        user_data = me.data["user"]
        user = db.session.query(User).filter_by(provider_id=user_data['user_id']).filter_by(
            provider_name='2bad').first()
        if not user:
            # noinspection PyArgumentList
            user = User.create(commit=False, provider_id=user_data['user_id'], provider_name='2bad')
        user.character_id = user_data["character_id"]
        user.character_name = user_data["username"]
        user.save()
        user.login()
        return redirect(url_for("index"))
    return jsonify(me.data)