Exemple #1
0
def oauth_new_user(request, name):
    from film20.utils.utils import direct_to_template

    logger.info("registering new %s user", name)
    
    reg_data = request.session.get('oauth_reg_data')
    access_token = reg_data['access_token']
    user_info = reg_data['user_info']
    next = reg_data['next'] or '/'
    service = OAuthService.get_by_name(name)
    
    if request.POST:
        form = SSORegistrationForm(request.POST, request=request)
        if form.is_valid():
            user = form.save()
            service.set_access_token(user, access_token, user_info['user_id'])
            try:
                Avatar.create_from_url(user, user_info['avatar_url'])
            except Exception, e:
                logger.warning(e)
            user = authenticate(service=service, user_id=user_info['user_id'])
            if user:
                auth_login_and_stats(request, user)
                logger.info("%s user (%s) authenticated and logged in, redirecting to %r", name, user, next)
                return new_user_registered_redirect(request, next)
            logger.error("Can't login to new created user %s" % user)
            assert False, "Can't login to new created user %s" % user
        else:
            logger.warning("invalid sso form: %s", form.errors)
Exemple #2
0
 def wrapper(request, name, *args, **kw):
     try:
         return view(request, name, *args, **kw)
     except Exception, e:
         service = OAuthService.get_by_name(name)
         logger.error("%(name)s error: %(descr)s" % {'name':service.name, 'descr':unicode(e)})
         logger.exception(e)
         return direct_to_template(request, 'account/oauth_error.html', {
             'error_description': _("%(name)s error: %(descr)s") % {'name':service.name, 'descr':unicode(e)},
         })
Exemple #3
0
def oauth_assoc_callback(request, name):
    service = OAuthService.get_by_name(name)
    token = service.fetch_access_token(request).to_string()
    ctx = {}

    info = service.get_user_info(token)
    user_id = info['user_id']
    try:
        user = service.get_user(user_id)
        ctx['error'] = (_("This %(service)s service account is already associated with user %(user)s") % dict(service=service.name, user=user))
    except User.DoesNotExist, e:
        service.set_access_token(request.user, token, user_id)
Exemple #4
0
def oauth_login_callback(request, name):
    service = OAuthService.get_by_name(name)
    next = get_next(request)
    oauth = request.GET.get('oauth')
    error = request.GET.get('denied') and _("Access denied") or request.GET.get('error')
    if error:
        raise service.Error(error)
    try:
        access_token = service.fetch_access_token(request).to_string()
        user_info = service.get_user_info(access_token)
    except IOError, e:
        if hasattr(e, 'reason'):
            error = _("We failed to reach server (%s)") % e.reason
        else:
            error = _("The server couldn't fulfill the request (code: %s)") % e.code
        raise service.Error(error)
Exemple #5
0
def oauth_login(request, name):
    next = get_next(request)
    # TODO - some kind of next parameter validation
    ip = request.META.get('REMOTE_ADDR')
    logger.info("[%s] (%s) starting %s oauth login", ip, request.META.get('HTTP_USER_AGENT', ''), name)
    return OAuthService.get_by_name(name).login(request, next)
Exemple #6
0
def oauth_cancel(request, name):
    OAuthService.get_by_name(name).set_access_token(request.user, None, None)
    return HttpResponseRedirect(reverse('associations'))
Exemple #7
0
def oauth_associate(request, name):
    return OAuthService.get_by_name(name).associate(request)