Commit 023239ac authored by Valentin Samir's avatar Valentin Samir

[wiki/auth] Deux modules, un pour la zone crans, un pour la catégorie page publique

parent 9a78c108
# -*- coding: iso-8859-1 -*-
"""
MoinMoin - CAS authentication
Jasig CAS (see http://www.jasig.org/cas) 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 netaddr import IPNetwork, IPAddress
from MoinMoin import log
logging = log.getLogger(__name__)
from MoinMoin.auth import BaseAuth
from MoinMoin import user, wikiutil
from MoinMoin.Page import Page
from anonymous_user import AnonymousAuth
class PublicCategories(AnonymousAuth):
name = 'PublicCategories'
def __init__(self, pub_cats=[], auth_username="Connexion"):
AnonymousAuth.__init__(self, auth_username=auth_username)
self.pub_cats=pub_cats
def can_view(self, request):
p = urlparse.urlparse(request.url)
categories = Page(request, p.path[1:]).getCategories(request)
for cat in self.pub_cats:
if cat in categories:
return True
return False
# -*- coding: iso-8859-1 -*-
"""
MoinMoin - CAS authentication
Jasig CAS (see http://www.jasig.org/cas) authentication module.
@copyright: 2012 MoinMoin:RichardLiao
@license: GNU GPL, see COPYING for details.
"""
import urlparse
from netaddr import IPNetwork, IPAddress
from MoinMoin.auth import BaseAuth
from MoinMoin import user
from anonymous_user import AnonymousAuth
class IpRange(AnonymousAuth):
name = 'IpRange'
def __init__(self, auth_username="Connexion", local_nets=[], actions=[], actions_msg={}):
AnonymousAuth.__init__(self, auth_username=auth_username)
self.local_nets = local_nets;
self.actions = actions
self.actions_msg=actions_msg
def can_view(self, request):
try:
for net in self.local_nets:
if IPAddress(request.remote_addr) in IPNetwork(net):
return True
except:
pass
return False
def request(self, request, user_obj, **kw):
user_obj, cont = AnonymousAuth.request(self, request, user_obj, **kw)
if user_obj and not user_obj.valid:
# Are we trying to do a protected action (eg newaccount)
action = request.args.get("action", "")
if action in self.actions:
if action in self.actions_msg.keys():
request.theme.add_msg(self.actions_msg[action])
p = urlparse.urlparse(request.url)
url = urlparse.urlunparse(('https', p.netloc, p.path, "", "", ""))
request.http_redirect(url)
return user_obj, True
return user_obj, False
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