Commit 9a78c108 authored by Valentin Samir's avatar Valentin Samir
Browse files

[wiki/auth/anonymous_user] Une classe d'auth générale pour authentifier en tant

qu'un utilisateur les utilisateur anonymes.
parent 7ed60359
# -*- coding: iso-8859-1 -*-
MoinMoin - CAS authentication
Jasig CAS (see authentication module.
@copyright: 2012 MoinMoin:RichardLiao
@license: GNU GPL, see COPYING for details.
import sys
import os
import time, re
import urlparse
import urllib, urllib2
from MoinMoin import log
logging = log.getLogger(__name__)
from MoinMoin.auth import BaseAuth
from MoinMoin import user, wikiutil
from MoinMoin.Page import Page
from werkzeug import get_host
class AnonymousAuth(BaseAuth):
name = 'AnonymousAuth'
login_inputs = []
logout_possible = False
def __init__(self, auth_username="Connexion"):
self.auth_username = auth_username
def can_view(self, request):
raise NotImplementedError
def request(self, request, user_obj, **kw):
# authenticated user
if user_obj and user_obj.valid:
return user_obj, True
# anonymous
if self.can_view(request):
if user_obj and user_obj.valid:
return user_obj, True
u = user.User(request, auth_username=self.auth_username,
u.valid = True = self.auth_username
elif user_obj and user_obj.valid:
u = user.User(request,
u.valid = False
u = user_obj
action = request.args.get("action", "")
p = urlparse.urlparse(request.url)
# Impossible to edit preferences
if u and u.valid and action == "userprefs":
url = urlparse.urlunparse(('https', p.netloc, p.path, "", "", ""))
# If reach anonymous user personnal page, redirect to referer with action=login
if p.path == "/%s" % self.auth_username and action != "login":
referer_p = urlparse.urlparse(request.http_referer)
if get_host(request.environ) == referer_p.netloc:
referer_url = urlparse.urlunparse(('https', p.netloc, referer_p.path, "", "", ""))
request.http_redirect(referer_url + "?action=login")
request.http_redirect("https://"+ p.netloc + "/?action=login")
return u, True
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment