Пример #1
0
def oauth_return(request, *args, **kwargs):
    if 'payment_paypal_oauth_event' not in request.session:
        messages.error(request, _('An error occurred during connecting with PayPal, please try again.'))
        return redirect(reverse('control:index'))

    event = get_object_or_404(Event, pk=request.session['payment_paypal_oauth_event'])

    prov = Paypal(event)
    prov.init_api()

    try:
        tokeninfo = Tokeninfo.create(request.GET.get('code'))
        userinfo = Tokeninfo.create_with_refresh_token(tokeninfo['refresh_token']).userinfo()
    except:
        logger.exception('Failed to obtain OAuth token')
        messages.error(request, _('An error occurred during connecting with PayPal, please try again.'))
    else:
        messages.success(request,
                         _('Your PayPal account is now connected to pretix. You can change the settings in '
                           'detail below.'))

        event.settings.payment_paypal_connect_refresh_token = tokeninfo['refresh_token']
        event.settings.payment_paypal_connect_user_id = userinfo.email

    return redirect(reverse('control:event.settings.payment.provider', kwargs={
        'organizer': event.organizer.slug,
        'event': event.slug,
        'provider': 'paypal'
    }))
Пример #2
0
def login_return(request):

    authCode = request.GET.get('code', '')

    if not authCode:
        return HttpResponseRedirect('/')

    # Create tokeninfo with Authorize code
    tokeninfo = Tokeninfo.create(authCode)

    #     request.session['id_token'] = tokeninfo.id_token
    request.session['access_token'] = tokeninfo.access_token
    request.session['refresh_token'] = tokeninfo.refresh_token
    request.session['logout_url'] = tokeninfo.logout_url()
    #     request.session.set_expiry(float(tokeninfo.expires_in))

    # Get userinfo
    userinfo = tokeninfo.userinfo()
    request.session['email'] = userinfo.email
    request.session['name'] = userinfo.name
    checkUser(userinfo.email, True)

    return afterLogin(request)
Пример #3
0
import paypalrestsdk
from paypalrestsdk.openid_connect import Tokeninfo

paypalrestsdk.configure({ 'openid_client_id': 'CLIENT_ID',
  'openid_client_secret': 'CLIENT_SECRET',
  'openid_redirect_uri': 'http://example.com' })

login_url = Tokeninfo.authorize_url({ 'scope': 'openid profile'})

print(login_url)

code = raw_input('Authorize code: ')

tokeninfo = Tokeninfo.create(code)

print(tokeninfo)

userinfo  = tokeninfo.userinfo()

print(userinfo)

tokeninfo = tokeninfo.refresh()

print(tokeninfo)

logout_url = tokeninfo.logout_url()

print(logout_url)
Пример #4
0
#   if payment.execute({"payer_id": "DUFRQ8GWYMJXC"}):  # return True or False
#     print("Payment[%s] execute successfully" % (payment.id))
#   else:
#     print(payment.error)

# else:
#   print(payment.error)

from paypalrestsdk.openid_connect import Tokeninfo, Userinfo


# Generate login url
login_url = Tokeninfo.authorize_url({ "scope": "openid profile"})

# Create tokeninfo with Authorize code
tokeninfo = Tokeninfo.create("Replace with Authorize code")

# Refresh tokeninfo
tokeninfo = tokeninfo.refresh()

# Create tokeninfo with refresh_token
tokeninfo = Tokeninfo.create_with_refresh_token("Replace with refresh_token")

# Get userinfo
userinfo  = tokeninfo.userinfo()

# Get userinfo with access_token
userinfo  = Userinfo.get("Replace with access_token")

# Generate logout url
logout_url = tokeninfo.logout_url()
Пример #5
0
def create_session():
    data = request.args
    user = None
    registered = False

    if 'code' in data:
        code = data.get('code')

        try:
            options = configure_openid_request(code=code)

            tokeninfo = Tokeninfo.create(options=options)
            userinfo = tokeninfo.userinfo(options=options)

            userinfo_dict = userinfo.to_dict()

            if 'email' in userinfo_dict:
                email = userinfo_dict.get('email')

                user = User.query\
                    .filter_by(email=email)\
                    .first()

                if user is None:
                    user = create_user_from_userinfo(userinfo_dict)
                    registered = True
                    app.logger.debug("Paypal User %s created using userinfo" %
                                     email)
                else:
                    app.logger.debug("User %s found using email" % email)
            else:
                app.logger.debug("No email found using email")

            if user is not None:
                if not user.is_active:
                    app.logger.debug("User provided is inactive.")

                    flash("Your e-mail is not verified. Please check your "
                          "inbox to verify & activate your account.")

                    try:
                        response = send_verification_notification(user)
                        app.logger.info(response)

                        app.logger.debug(
                            'Sent verification notification to %s' %
                            user.email)
                    except Exception as e:
                        app.logger.exception(e)

                    app.logger.debug('Redirecting to %s' %
                                     url_for("account_verification"))
                    return redirect(url_for("account_verification"))
                else:
                    app.logger.debug("User provided is active.")

                    if login_user(user, remember=True):
                        app.logger.debug("logged in user: %s" % user.email)
                        app.logger.debug('session == %s' % session)

                        if not registered and clean_phone_no(user.phone):
                            return render_template("authenticated_popup.html",
                                                   token=session['token'],
                                                   user=user,
                                                   redirect_to=url_for('home'))
                        elif registered:
                            if not clean_phone_no(user.phone):
                                return redirect(
                                    url_for('mpesa_mobile_phone_no'))
                            else:
                                flash(
                                    "You have been registered successfully "
                                    "check your e-mail and phone for verification codes."
                                )

                                send_registration_notification(user)
                                return redirect(
                                    url_for("account_verification"))
                    else:
                        app.logger.debug("Could not login user")
                        return jsonify(
                            success=False,
                            message="Forbidden: error logging you in."), 403
            else:
                return jsonify(
                    success=False,
                    message="could not authenticate via paypal"), 403
        except Exception as e:
            app.logger.exception(e)
            return internal_server_error(e)

    elif 'error_uri' in data:
        error_uri = data.get('error_uri')
        error_description = data.get('error_description')
        error = data.get('error')

        return internal_server_error(error)

    return page_not_found()