[wiki/auth] Deux modules, un pour la zone crans, un pour la catégorie page publique
This commit is contained in:
parent
9a78c10805
commit
023239ac4e
2 changed files with 92 additions and 0 deletions
41
wiki/auth/categorie_public.py
Normal file
41
wiki/auth/categorie_public.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# -*- 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
|
||||||
|
|
51
wiki/auth/ip_range.py
Normal file
51
wiki/auth/ip_range.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
# -*- 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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue