Ejemplo n.º 1
0
def changeopenid_success(request, identity_url, openid_response):
    openid_ = from_openid_response(openid_response)
    is_exist = True
    try:
        uassoc = UserAssociation.objects.get(openid_url__exact=identity_url)
    except:
        is_exist = False
        
    if not is_exist:
        try:
            uassoc = UserAssociation.objects.get(
                    user__username__exact=request.user.username
            )
            uassoc.openid_url = identity_url
            uassoc.save()
        except:
            uassoc = UserAssociation(user=request.user, 
                    openid_url=identity_url)
            uassoc.save()
    elif uassoc.user.username != request.user.username:
        return changeopenid_failure(request, 
                _('This openid is already associated with another account.'))

    request.session['openids'] = []
    request.session['openids'].append(openid_)

    msg = _("Openid %s associated with your account." % identity_url) 
    redirect = "%s?msg=%s" % (
            reverse('user_account_settings'), 
            urlquote_plus(msg))
    return HttpResponseRedirect(redirect)
Ejemplo n.º 2
0
def default_on_success(request,
                       identity_url,
                       openid_response,
                       confirmed=True,
                       email=""):
    if 'openids' not in request.session.keys():
        request.session['openids'] = []

    # Eliminate any duplicates
    request.session['openids'] = [
        o for o in request.session['openids'] if o.openid != identity_url
    ]
    request.session['openids'].append(from_openid_response(openid_response))

    # Set up request.openids and request.openid, reusing middleware logic
    OpenIDMiddleware().process_request(request)

    next = request.GET.get('next', '').strip()

    if confirmed:
        redirect_next = 'OPENID_REDIRECT_NEXT'
    else:
        redirect_next = 'OPENID_REDIRECT_CONFIRM_NEXT'
    if not next or not is_valid_next_url(next):
        next = getattr(settings, redirect_next, '/')
        if email:
            next += ("?email=%s" % (email))
    else:
        next = "%s?next=%s&email=%s" % (getattr(settings, redirect_next,
                                                '/'), next, email)
    return HttpResponseRedirect(next)
Ejemplo n.º 3
0
def signin_success(request, identity_url, openid_response):
    """
    openid signin success.

    If the openid is already registered, the user is redirected to 
    url set par next or in settings with OPENID_REDIRECT_NEXT variable.
    If none of these urls are set user is redirectd to /.

    if openid isn't registered user is redirected to register page.
    """

    openid_ = from_openid_response(openid_response)
    request.session['openid'] = openid_

    try:
        rel = UserAssociation.objects.get(openid_url__exact = str(openid_))
    except:
        # try to register this new user
        return register(request)
    user_ = rel.user
    if user_.is_active:
        user_.backend = "django.contrib.auth.backends.ModelBackend"
        login(request, user_)

    next = request.GET.get('next', '').strip()
    if not next or not is_valid_next_url(next):
        next = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')
    
    return HttpResponseRedirect(next)
Ejemplo n.º 4
0
def emailopenid_success(request, identity_url, openid_response):
    openid_ = from_openid_response(openid_response)

    user_ = request.user
    try:
        uassoc = UserAssociation.objects.get(
                openid_url__exact=identity_url
        )
    except:
        return emailopenid_failure(request, 
                _("No openid % associated in our database" % identity_url))

    if uassoc.user.username != request.user.username:
        return emailopenid_failure(request, 
                _("The openid %s isn't associated to current logged user" % 
                    identity_url))
    
    new_email = request.session.get('new_email', '')
    if new_email:
        user_.email = new_email
        user_.save()
        del request.session['new_email']
    msg = _("Email Changed.")

    redirect = "%s?msg=%s" % (reverse('user_account_settings'),
            urlquote_plus(msg))
    return HttpResponseRedirect(redirect)
Ejemplo n.º 5
0
def default_on_success(request, identity_url, openid_response):
    username = str(request.GET['openid.claimed_id'][36:])
    user, new = User.objects.get_or_create(username=username)
    if new:
        user.set_password('!')
        user.save()
    user = authenticate(username=user.username, password='******')
    if user is not None:
        if user.is_active:
            login(request, user)
    
    if 'openids' not in request.session.keys():
        request.session['openids'] = []
    
    # Eliminate any duplicates
    request.session['openids'] = [
        o for o in request.session['openids'] if o.openid != identity_url
    ]
    request.session['openids'].append(from_openid_response(openid_response))
    
    # Set up request.openids and request.openid, reusing middleware logic
    OpenIDMiddleware().process_request(request)
    
    next = request.GET.get('next', '').strip()
    if not next or not is_valid_next_url(request, next):
        next = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')
    
    return HttpResponseRedirect(next)
Ejemplo n.º 6
0
def default_on_success(request, identity_url, openid_response):
    username = str(request.GET['openid.claimed_id'][36:])
    user, new = User.objects.get_or_create(username=username)
    if new:
        user.set_password('!')
        user.save()
    user = authenticate(username=user.username, password='******')
    if user is not None:
        if user.is_active:
            login(request, user)

    if 'openids' not in request.session.keys():
        request.session['openids'] = []

    # Eliminate any duplicates
    request.session['openids'] = [
        o for o in request.session['openids'] if o.openid != identity_url
    ]
    request.session['openids'].append(from_openid_response(openid_response))

    # Set up request.openids and request.openid, reusing middleware logic
    OpenIDMiddleware().process_request(request)

    next = request.GET.get('next', '').strip()
    if not next or not is_valid_next_url(request, next):
        next = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')

    return HttpResponseRedirect(next)
Ejemplo n.º 7
0
def default_on_success(request, identity_url, openid_response):
    """ default action on openid signin success """
    request.session['openid'] = from_openid_response(openid_response)
    
    next = request.GET.get('next', '').strip()
    if not next or not is_valid_next_url(next):
        next = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')
    
    return HttpResponseRedirect(next)
Ejemplo n.º 8
0
def default_on_success(request, identity_url, openid_response):
    if "openids" not in request.session.keys():
        request.session["openids"] = []

    # Eliminate any duplicates
    request.session["openids"] = [o for o in request.session["openids"] if o.openid != identity_url]
    request.session["openids"].append(from_openid_response(openid_response))

    next = request.GET.get("next", "").strip()
    if not next or not is_valid_next_url(next):
        next = getattr(settings, "OPENID_REDIRECT_NEXT", "/")

    return HttpResponseRedirect(next)
Ejemplo n.º 9
0
def default_on_success(request, identity_url, openid_response):
    if 'openids' not in request.session.keys():
        request.session['openids'] = []

    # Eliminate any duplicates
    request.session['openids'] = [
        o for o in request.session['openids'] if o.openid != identity_url
    ]
    request.session['openids'].append(from_openid_response(openid_response))

    next = request.GET.get('next', '').strip()
    if not next or not is_valid_next_url(next):
        next = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')

    return HttpResponseRedirect(next)
Ejemplo n.º 10
0
def default_on_success(request, identity_url, openid_response):
    if 'openids' not in request.session.keys():
        request.session['openids'] = []
    
    # Eliminate any duplicates
    request.session['openids'] = [
        o for o in request.session['openids'] if o.openid != identity_url
    ]
    request.session['openids'].append(from_openid_response(openid_response))
    
    # Set up request.openids and request.openid, reusing middleware logic
    OpenIDMiddleware().process_request(request)
    
    next = request.GET.get('next', '').strip()
    if not next or not is_valid_next_url(next):
        next = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')
    
    return HttpResponseRedirect(next)
Ejemplo n.º 11
0
def on_success(request, identity_url, openid_response):
	request.session['openid'] = from_openid_response(openid_response)

	# Set up request.openids and request.openid, reusing middleware logic
	OpenIDMiddleware().process_request(request)

	if request.openid:
		#check for already existing associations
		openid_key = str(request.openid)
		#authenticate and login
		user = authenticate(openid_key=openid_key, request=request)
		if user:
			login(request, user)
			messages.success(request, "Hello!")
			next = request.GET.get('next', '').strip()
			if not next or not is_valid_next_url(next):
				next = reverse('index')
			return HttpResponseRedirect(next)
	return HttpResponseRedirect(reverse('index'))
Ejemplo n.º 12
0
def default_on_success(request, identity_url, openid_response):
    if 'openids' not in request.session.keys():
        request.session['openids'] = []

    # Eliminate any duplicates
    request.session['openids'] = [
        o for o in request.session['openids'] if o.openid != identity_url
    ]
    request.session['openids'].append(from_openid_response(openid_response))

    # Set up request.openids and request.openid, reusing middleware logic
    OpenIDMiddleware().process_request(request)

    next = request.GET.get('next', '').strip()
    if not next or not is_valid_next_url(request, next):
        next = getattr(settings, 'OPENID_REDIRECT_NEXT',
                       '/user/login/openid/auth/')

    return HttpResponseRedirect(next)
Ejemplo n.º 13
0
def default_on_success(request, identity_url, openid_response):
    if 'openids' not in request.session.keys():
        request.session['openids'] = []
    
    # Eliminate any duplicates
    request.session['openids'] = [
        o for o in request.session['openids'] if o.openid != identity_url
    ]
    request.session['openids'].append(from_openid_response(openid_response))
    
    next = request.GET.get('next', '').strip()
    if not next or not is_valid_next_url(next):
        next = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')
    
    user = User.objects.filter(oid_url=identity_url)[0]
    email = openid_response.extensionResponse('sreg').get('email')
    if email and email != user.email:
        user.email = email
        user.save()
    
    return HttpResponseRedirect(next)
Ejemplo n.º 14
0
def deleteopenid_success(request, identity_url, openid_response):
    openid_ = from_openid_response(openid_response)

    user_ = request.user
    try:
        uassoc = UserAssociation.objects.get(
                openid_url__exact=identity_url
        )
    except:
        return deleteopenid_failure(request,
                _("No openid % associated in our database" % identity_url))

    if uassoc.user.username == user_.username:
        user_.delete()
        return signout(request)
    else:
        return deleteopenid_failure(request,
                _("The openid %s isn't associated to current logged user" % 
                    identity_url))
    
    msg = _("Account deleted.") 
    redirect = "/?msg=%s" % (urlquote_plus(msg))
    return HttpResponseRedirect(redirect)
Ejemplo n.º 15
0
def deleteopenid_success(request, identity_url, openid_response):
    logging.info('openid response: %s' % openid_response)
    openid_ = from_openid_response(openid_response)
    
    user_ = request.user
    try:
        uassoc = UserAssociation.objects.get(
                openid_url__exact=identity_url
        )
    except:
        return deleteopenid_failure(request,
                _("This OpenID isn't associated in the system."))

    if uassoc.user.username == user_.username:
        user_.delete()
        return signout(request, msg='Your account has been deleted.')
    else:
        return deleteopenid_failure(request,
                _("This OpenID isn't associated with the current logged-in user"))
    
    msg = _("Account deleted.") 
    redirect = "/?msg=%s" % (urlquote_plus(msg))
    return HttpResponseRedirect(redirect)
Ejemplo n.º 16
0
def default_on_success(request, identity_url, openid_response):
    username = str(request.GET["openid.claimed_id"][36:])
    user, new = User.objects.get_or_create(username=username)
    if new:
        user.set_password("!")
        user.save()
    user = authenticate(username=user.username, password="******")
    if user is not None:
        if user.is_active:
            login(request, user)

    if "openids" not in request.session.keys():
        request.session["openids"] = []

    # Eliminate any duplicates
    request.session["openids"] = [o for o in request.session["openids"] if o.openid != identity_url]
    request.session["openids"].append(from_openid_response(openid_response))

    # Set up request.openids and request.openid, reusing middleware logic
    OpenIDMiddleware().process_request(request)

    next = "/tf2recruiter/"

    return HttpResponseRedirect(next)