예제 #1
0
파일: views.py 프로젝트: hifans/CNPROG
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)  # create janrain OpenID object
    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 = clean_next(request.GET.get("next"))
    return HttpResponseRedirect(next)
예제 #2
0
파일: views.py 프로젝트: hifans/CNPROG
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 is now associated with your account." % identity_url)
    redirect = "%s?msg=%s" % (reverse("user_account_settings"), urlquote_plus(msg))
    return HttpResponseRedirect(redirect)
예제 #3
0
def changeopenid_success(request, identity_url, openid_response):
    logging.error('never tested this worflow')
    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 is now associated with your account." % identity_url) 
    redirect = "%s?msg=%s" % (
            reverse('user_account_settings'), 
            urlquote_plus(msg))
    return HttpResponseRedirect(redirect)
예제 #4
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.
    """

    logging.debug('')
    openid_ = from_openid_response(openid_response) #create janrain OpenID object
    request.session['openid'] = openid_
    try:
        logging.debug('trying to get user associated with this openid...')
        rel = UserAssociation.objects.get(openid_url__exact = str(openid_))
        logging.debug('success')
    except:
        logging.debug('failed --> try to register brand new user')
        # try to register this new user
        return register(request)
    user_ = rel.user
    if user_.is_active:
        user_.backend = "django.contrib.auth.backends.ModelBackend"
        logging.debug('user is active --> attached django auth ModelBackend --> calling login')
        login(request, user_)
        logging.debug('success')
    else:
        logging.debug('user is inactive, do not log them in')
    logging.debug('redirecting to %s' % get_next_url(request))
    return HttpResponseRedirect(get_next_url(request))
예제 #5
0
def emailopenid_success(request, identity_url, openid_response):
    logging.debug('')
    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 %s found 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 user logged in" % 
                    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)
예제 #6
0
파일: views.py 프로젝트: SuLab/biogps_core
def openid_login_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 redirected to /.

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

    goto_url = clean_next(request.GET.get('next'))
    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_openid(request)
    user = rel.user

    if user and user.is_active:
        user.backend = "django.contrib.auth.backends.ModelBackend"
        auth.login(request, user)

        #logging
        log.info('username=%s clientip=%s action=user_login openid=1', getattr(request.user, 'username', ''), request.META.get('REMOTE_ADDR', ''))

        return HttpResponseRedirect(goto_url)
    else:
        return render_login_form(request,
                                 goto_url,
                                 message='User does not exist or inactive.')
예제 #7
0
파일: views.py 프로젝트: yyms/CNPROG
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)  #create janrain OpenID object
    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 = clean_next(request.GET.get('next'))
    return HttpResponseRedirect(next)
예제 #8
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)
예제 #9
0
파일: views.py 프로젝트: hifans/CNPROG
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 %s found 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 user logged in" % identity_url)
        )

    msg = _("Account deleted.")
    redirect = "/?msg=%s" % (urlquote_plus(msg))
    return HttpResponseRedirect(redirect)
예제 #10
0
파일: views.py 프로젝트: yyms/CNPROG
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 %s found 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 user logged in" %
              identity_url))

    msg = _("Account deleted.")
    redirect = "/?msg=%s" % (urlquote_plus(msg))
    return HttpResponseRedirect(redirect)
예제 #11
0
파일: views.py 프로젝트: hifans/CNPROG
def default_on_success(request, identity_url, openid_response):
    """ default action on openid signin success """
    request.session["openid"] = from_openid_response(openid_response)
    return HttpResponseRedirect(clean_next(request.GET.get("next")))
예제 #12
0
def default_on_success(request, identity_url, openid_response):
    """ default action on openid signin success """
    logging.debug('')
    request.session['openid'] = from_openid_response(openid_response)
    logging.debug('performing default action on openid success %s' % get_next_url(request))
    return HttpResponseRedirect(get_next_url(request))
예제 #13
0
파일: views.py 프로젝트: hrcerqueira/osqa
def default_on_success(request, identity_url, openid_response):
    """ default action on openid signin success """
    request.session['openid'] = from_openid_response(openid_response)
    return HttpResponseRedirect(get_next_url(request))
예제 #14
0
파일: views.py 프로젝트: yyms/CNPROG
def default_on_success(request, identity_url, openid_response):
    """ default action on openid signin success """
    request.session['openid'] = from_openid_response(openid_response)
    return HttpResponseRedirect(clean_next(request.GET.get('next')))