annotate MoinMoin/user.py @ 6103:500f68d3e2fd

remove our own usage of python_compatibility module
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 06 Sep 2016 01:00:25 +0200
parents 1306560f158e
children 561b7a9c2bd9
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - User Accounts
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
4
1909
be140a589f11 improved some module docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
5 This module contains functions to access user accounts (list all users, get
be140a589f11 improved some module docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
6 some specific user). User instances are used to access the user profile of
be140a589f11 improved some module docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
7 some specific user (name, password, email, bookmark, trail, settings, ...).
be140a589f11 improved some module docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
8
3333
928a45b60bb3 remove remaining mentions of "UserPreferences", add to CHANGES
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3175
diff changeset
9 Some related code is in the userform and userprefs modules.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
10
1963
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
11 TODO:
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
12 * code is a mixture of highlevel user stuff and lowlevel storage functions,
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
13 this has to get separated into:
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
14 * user object highlevel stuff
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
15 * storage code
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
16
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1909
diff changeset
17 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
5915
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
18 2003-2013 MoinMoin:ThomasWaldmann,
5720
69668ad0cae7 add support for other password hashes (thanks to Michael Foetsch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5613
diff changeset
19 2010 Michael Foetsch <foetsch@yahoo.com>
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
21 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
22
4363
817d99d715fe remove direct usage of deprecated sha module - use hashlib, if possible
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4107
diff changeset
23 import os, time, codecs, base64
6103
500f68d3e2fd remove our own usage of python_compatibility module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6043
diff changeset
24 import hashlib
500f68d3e2fd remove our own usage of python_compatibility module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6043
diff changeset
25 import hmac
6031
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
26 from copy import deepcopy
5720
69668ad0cae7 add support for other password hashes (thanks to Michael Foetsch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5613
diff changeset
27 import md5crypt
69668ad0cae7 add support for other password hashes (thanks to Michael Foetsch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5613
diff changeset
28
69668ad0cae7 add support for other password hashes (thanks to Michael Foetsch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5613
diff changeset
29 try:
69668ad0cae7 add support for other password hashes (thanks to Michael Foetsch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5613
diff changeset
30 import crypt
69668ad0cae7 add support for other password hashes (thanks to Michael Foetsch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5613
diff changeset
31 except ImportError:
69668ad0cae7 add support for other password hashes (thanks to Michael Foetsch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5613
diff changeset
32 crypt = None
4363
817d99d715fe remove direct usage of deprecated sha module - use hashlib, if possible
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4107
diff changeset
33
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
34 from MoinMoin import log
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
35 logging = log.getLogger(__name__)
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
36
2493
f3e3ffa68a7f Send UserCreatedEvent from user.save(), not the newaccount action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2429
diff changeset
37 from MoinMoin import config, caching, wikiutil, i18n, events
5904
3a1b92276377 reorder imports, so that MoinMoin.support is already in sys.path
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5902
diff changeset
38 from werkzeug.security import safe_str_cmp as safe_str_equal
5612
cc15366f7b74 remove all calls to filesys.dc* (dclistdir, dcdisable), remove unused imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5532
diff changeset
39 from MoinMoin.util import timefuncs, random_string
3564
474f6ad01900 recoverpass: email password reset token rather than sha1
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3333
diff changeset
40 from MoinMoin.wikiutil import url_quote_plus
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
41
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
42 # for efficient lookup <attr> -> userid, we keep an index of this in the cache.
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
43 # the attribute names in here should be uniquely identifying a user.
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
44 CACHED_USER_ATTRS = ['name', 'email', 'jid', 'openids', ]
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
45
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
46
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
47 def getUserList(request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
48 """ Get a list of all (numerical) user IDs.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
49
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
50 @param request: current request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51 @rtype: list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
52 @return: all user IDs
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 """
1801
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
54 import re
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
55 user_re = re.compile(r'^\d+\.\d+(\.\d+)?$')
5612
cc15366f7b74 remove all calls to filesys.dc* (dclistdir, dcdisable), remove unused imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5532
diff changeset
56 files = os.listdir(request.cfg.user_dir)
232
31c1fbb101a3 remove string/Cookie import, rewrite filter/map
Thomas Waldmann <tw@waldmann-edv.de>
parents: 138
diff changeset
57 userlist = [f for f in files if user_re.match(f)]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 return userlist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59
2092
937da10cb5b3 s/filter/filter_func/ to avoid conflict with builtin name
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
60 def get_by_filter(request, filter_func):
6031
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
61 """ Searches for a user with a given filter function
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
62
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
63 Be careful: SLOW for big wikis, rather use _getUserIdByKey & related.
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
64 """
2091
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2090
diff changeset
65 for uid in getUserList(request):
2090
9fec7760489e Add a get_by_jabber_id function to search for users given their jabber id.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2065
diff changeset
66 theuser = User(request, uid)
2092
937da10cb5b3 s/filter/filter_func/ to avoid conflict with builtin name
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
67 if filter_func(theuser):
2090
9fec7760489e Add a get_by_jabber_id function to search for users given their jabber id.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2065
diff changeset
68 return theuser
9fec7760489e Add a get_by_jabber_id function to search for users given their jabber id.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2065
diff changeset
69
690
e8ccec07515b Refactored user search by mail address.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 626
diff changeset
70 def get_by_email_address(request, email_address):
2090
9fec7760489e Add a get_by_jabber_id function to search for users given their jabber id.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2065
diff changeset
71 """ Searches for an user with a particular e-mail address and returns it. """
6033
f70b9ab3dedc fix return type of get_by_... lookup functions (must be User obj or None)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6031
diff changeset
72 uid = _getUserIdByKey(request, 'email', email_address, case=False)
f70b9ab3dedc fix return type of get_by_... lookup functions (must be User obj or None)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6031
diff changeset
73 if uid is not None:
f70b9ab3dedc fix return type of get_by_... lookup functions (must be User obj or None)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6031
diff changeset
74 return User(request, uid)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
75
2090
9fec7760489e Add a get_by_jabber_id function to search for users given their jabber id.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2065
diff changeset
76 def get_by_jabber_id(request, jabber_id):
9fec7760489e Add a get_by_jabber_id function to search for users given their jabber id.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2065
diff changeset
77 """ Searches for an user with a perticular jabber id and returns it. """
6033
f70b9ab3dedc fix return type of get_by_... lookup functions (must be User obj or None)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6031
diff changeset
78 uid = _getUserIdByKey(request, 'jid', jabber_id, case=False)
f70b9ab3dedc fix return type of get_by_... lookup functions (must be User obj or None)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6031
diff changeset
79 if uid is not None:
f70b9ab3dedc fix return type of get_by_... lookup functions (must be User obj or None)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6031
diff changeset
80 return User(request, uid)
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
81
6031
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
82 def _getUserIdByKey(request, key, search, case=True):
2011
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
83 """ Get the user ID for a specified key/value pair.
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
84
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
85 This method must only be called for keys that are
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
86 guaranteed to be unique.
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
87
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
88 @param key: the key to look in
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
89 @param search: the value to look for
6031
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
90 @param case: do a case-sensitive lookup?
2011
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
91 @return the corresponding user ID or None
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
92 """
6029
e2da1c1183d8 _getUserIdByKey: make sure we are only called for cached/supported userprofile attributes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6028
diff changeset
93 if key not in CACHED_USER_ATTRS:
e2da1c1183d8 _getUserIdByKey: make sure we are only called for cached/supported userprofile attributes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6028
diff changeset
94 raise ValueError("unsupported key, must be in CACHED_USER_ATTRS")
e2da1c1183d8 _getUserIdByKey: make sure we are only called for cached/supported userprofile attributes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6028
diff changeset
95 if not search:
2011
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
96 return None
6031
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
97 cfg_cache_attr = key + "2id"
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
98 if not case:
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
99 cfg_cache_attr += "_lower"
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
100 search = search.lower()
2011
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
101 cfg = request.cfg
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
102 try:
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
103 attr2id = getattr(cfg.cache, cfg_cache_attr)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
104 from_disk = False
2011
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
105 except AttributeError:
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
106 # no in-memory cache there - initialize it / load it from disk
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
107 loadLookupCaches(request)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
108 attr2id = getattr(cfg.cache, cfg_cache_attr)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
109 from_disk = True # we just loaded the stuff from disk
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
110 uid = attr2id.get(search, None)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
111 if uid is None and not from_disk:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
112 # we do not have the entry we searched for.
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
113 # we didn't find it in some in-memory cache, try refreshing these from disk
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
114 loadLookupCaches(request)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
115 attr2id = getattr(cfg.cache, cfg_cache_attr)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
116 from_disk = True # we just loaded the stuff from disk
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
117 uid = attr2id.get(search, None)
2011
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
118 if uid is None:
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
119 # we do not have the entry we searched for.
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
120 # we don't have it in the on-disk cache, cache MISS.
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
121 # could be because:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
122 # a) ok: we have no such search value in the profiles
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
123 # b) fault: the cache is incoherent with the profiles
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
124 # c) fault: reading the cache from disk failed, due to an error
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
125 # d) ok: same as c), but just because no ondisk cache has been built yet
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
126 rebuildLookupCaches(request) # XXX expensive
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
127 attr2id = getattr(cfg.cache, cfg_cache_attr)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
128 uid = attr2id.get(search, None)
2011
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
129 return uid
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
130
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
131
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
132 def setMemoryLookupCaches(request, cache):
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
133 """set the in-memory cache from the given cache contents
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
134
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
135 @param request: the request object
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
136 @param cache: either a dict of attrname -> attrcache to set the in-memory cache,
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
137 or None to delete the in-memory cache.
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
138 """
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
139 for attrname in CACHED_USER_ATTRS:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
140 if cache is None:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
141 try:
6031
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
142 delattr(request.cfg.cache, attrname + "2id")
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
143 except:
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
144 pass
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
145 try:
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
146 delattr(request.cfg.cache, attrname + "2id_lower")
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
147 except:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
148 pass
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
149 else:
6031
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
150 setattr(request.cfg.cache, attrname + "2id", cache[attrname])
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
151 setattr(request.cfg.cache, attrname + "2id_lower", cache[attrname + "_lower"])
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
152
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
153
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
154 def loadLookupCaches(request):
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
155 """load lookup cache contents into memory: cfg.cache.XXX2id"""
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
156 scope, arena, cachekey = 'userdir', 'users', 'lookup'
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
157 diskcache = caching.CacheEntry(request, arena, cachekey, scope=scope, use_pickle=True)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
158 try:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
159 cache = diskcache.content()
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
160 except caching.CacheError:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
161 cache = {}
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
162 for attrname in CACHED_USER_ATTRS:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
163 cache[attrname] = {}
6031
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
164 cache_with_lowercase = addLowerCaseKeys(cache)
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
165 setMemoryLookupCaches(request, cache_with_lowercase)
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
166
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
167
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
168 def rebuildLookupCaches(request):
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
169 """complete attrs -> userid lookup cache rebuild"""
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
170 # as there may be thousands of users and reading all profiles is
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
171 # expensive, we just have 1 lookup cache for all interesting user attrs,
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
172 # so we only need to read all profiles ONCE to build the cache.
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
173 scope, arena, key = 'userdir', 'users', 'lookup'
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
174 diskcache = caching.CacheEntry(request, arena, key, scope=scope, use_pickle=True, do_locking=False)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
175 diskcache.lock('w')
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
176
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
177 cache = {}
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
178 for attrname in CACHED_USER_ATTRS:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
179 cache[attrname] = {}
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
180 for userid in getUserList(request):
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
181 u = User(request, id=userid)
6030
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
182 if u.valid:
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
183 for attrname in CACHED_USER_ATTRS:
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
184 if hasattr(u, attrname):
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
185 attr2id = cache[attrname]
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
186 value = getattr(u, attrname)
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
187 if isinstance(value, list):
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
188 for val in value:
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
189 attr2id[val] = userid
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
190 else:
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
191 attr2id[value] = userid
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
192
6031
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
193 cache_with_lowercase = addLowerCaseKeys(cache)
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
194 setMemoryLookupCaches(request, cache_with_lowercase)
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
195 diskcache.update(cache)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
196 diskcache.unlock()
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
197 return cache
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
198
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
199
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
200 def clearLookupCaches(request):
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
201 """kill the userid lookup cache"""
6026
28a3951fc9f6 add comments about userid lookup cache killing/rebuilding
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6025
diff changeset
202 # this triggers a rebuild of the cache.
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
203 setMemoryLookupCaches(request, None)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
204 scope, arena, key = 'userdir', 'users', 'lookup'
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
205 caching.CacheEntry(request, arena, key, scope=scope).remove()
6025
05a6897ee496 "userdir" caching scope: use it for userid lookup caches, reduce code duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6024
diff changeset
206
05a6897ee496 "userdir" caching scope: use it for userid lookup caches, reduce code duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6024
diff changeset
207
6031
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
208 def addLowerCaseKeys(cache):
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
209 """add lowercased lookup keys, so we can support case-insensitive lookup"""
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
210 c = deepcopy(cache) # we do not want to modify cache itself
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
211 for attrname in CACHED_USER_ATTRS:
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
212 attr2id = c[attrname]
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
213 attr2id_lower = c[attrname + "_lower"] = {}
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
214 for key, value in attr2id.iteritems():
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
215 attr2id_lower[key.lower()] = value
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
216 return c
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
217
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
218
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
219 def getUserId(request, searchName):
1963
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
220 """ Get the user ID for a specific user NAME.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
221
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
222 @param searchName: the user name to look up
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
223 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
224 @return: the corresponding user ID or None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
225 """
2011
6cd0e4cc8e18 refactor user.getUserId
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2010
diff changeset
226 return _getUserIdByKey(request, 'name', searchName)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
227
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
228
2299
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
229 def getUserIdByOpenId(request, openid):
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
230 """ Get the user ID for a specific OpenID.
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
231
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
232 @param openid: the openid to look up
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
233 @rtype: string
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
234 @return: the corresponding user ID or None
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
235 """
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
236 return _getUserIdByKey(request, 'openids', openid)
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
237
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
238
6027
8618232296b5 optimized notification of superusers on user account creation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6026
diff changeset
239 def superusers(request):
8618232296b5 optimized notification of superusers on user account creation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6026
diff changeset
240 """
8618232296b5 optimized notification of superusers on user account creation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6026
diff changeset
241 yields superuser User objects
8618232296b5 optimized notification of superusers on user account creation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6026
diff changeset
242 """
8618232296b5 optimized notification of superusers on user account creation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6026
diff changeset
243 for name in request.cfg.superuser:
8618232296b5 optimized notification of superusers on user account creation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6026
diff changeset
244 u = User(request, auth_username=name)
8618232296b5 optimized notification of superusers on user account creation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6026
diff changeset
245 if u.isSuperUser(): # this checks for addtl. criteria
8618232296b5 optimized notification of superusers on user account creation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6026
diff changeset
246 yield u
8618232296b5 optimized notification of superusers on user account creation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6026
diff changeset
247
8618232296b5 optimized notification of superusers on user account creation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6026
diff changeset
248
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
249 def getUserIdentification(request, username=None):
1963
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
250 """ Return user name or IP or '<unknown>' indicator.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
251
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
252 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
253 @param username: (optional) user name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
254 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
255 @return: user name or IP or unknown indicator
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
256 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
257 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
258
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
259 if username is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
260 username = request.user.name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
261
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
262 return username or (request.cfg.show_hosts and request.remote_addr) or _("<unknown>")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
263
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
264
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
265 def encodePassword(cfg, pwd, salt=None, scheme=None):
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
266 """ Encode a cleartext password using the default algorithm.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
267
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
268 @param cfg: the wiki config
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
269 @param pwd: the cleartext password, (unicode)
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
270 @param salt: the salt for the password (string) or None to generate a
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
271 random salt.
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
272 @param scheme: scheme to use (by default will use cfg.password_scheme)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
273 @rtype: string
5918
5126fadbf24f password related code and tests - clean up and refactor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5917
diff changeset
274 @return: the password hash in apache htpasswd compatible encoding,
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
275 """
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
276 if scheme is None:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
277 scheme = cfg.password_scheme
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
278 configured_scheme = True
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
279 else:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
280 configured_scheme = False
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
281 if scheme == '{PASSLIB}':
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
282 return '{PASSLIB}' + cfg.cache.pwd_context.encrypt(pwd, salt=salt)
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
283 elif scheme == '{SSHA}':
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
284 pwd = pwd.encode('utf-8')
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
285 if salt is None:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
286 salt = random_string(20)
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
287 assert isinstance(salt, str)
6103
500f68d3e2fd remove our own usage of python_compatibility module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6043
diff changeset
288 hash = hashlib.new('sha1', pwd)
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
289 hash.update(salt)
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
290 return '{SSHA}' + base64.encodestring(hash.digest() + salt).rstrip()
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
291 else:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
292 # should never happen as we check the value of cfg.password_scheme
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
293 raise NotImplementedError
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
294
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
295
5915
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
296 class Fault(Exception):
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
297 """something went wrong"""
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
298
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
299 class NoSuchUser(Fault):
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
300 """raised if no such user exists"""
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
301
5940
1960726cd356 set_password: warn if user has no e-mail address in the profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5939
diff changeset
302 class UserHasNoEMail(Fault):
1960726cd356 set_password: warn if user has no e-mail address in the profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5939
diff changeset
303 """raised if user has no e-mail address in his profile"""
1960726cd356 set_password: warn if user has no e-mail address in the profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5939
diff changeset
304
5915
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
305 class MailFailed(Fault):
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
306 """raised if e-mail sending failed"""
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
307
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
308
5936
2d3352c547bc moin account resetpw - misc. improvements
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5930
diff changeset
309 def set_password(request, newpass, u=None, uid=None, uname=None,
5959
63412f39e2b4 moin account resetpw: add option --skip-invalid to skip users with already invalidated pw hashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5953
diff changeset
310 notify=False, skip_invalid=False, subject=None,
5936
2d3352c547bc moin account resetpw - misc. improvements
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5930
diff changeset
311 text_intro=None, text_msg=None, text_data=None):
5915
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
312 if uid:
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
313 u = User(request, uid)
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
314 elif uname:
5930
aac944a51a54 fix bug in set_password (it did not load the user profile, but safe an empty one)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5929
diff changeset
315 u = User(request, auth_username=uname)
5915
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
316 if u and u.exists():
5959
63412f39e2b4 moin account resetpw: add option --skip-invalid to skip users with already invalidated pw hashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5953
diff changeset
317 if skip_invalid and u.enc_password == '':
63412f39e2b4 moin account resetpw: add option --skip-invalid to skip users with already invalidated pw hashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5953
diff changeset
318 return
5917
c99f570e274a moin account resetpw: make password optional, to be able to set a invalid password
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5915
diff changeset
319 if not newpass:
c99f570e274a moin account resetpw: make password optional, to be able to set a invalid password
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5915
diff changeset
320 # set a invalid password hash
c99f570e274a moin account resetpw: make password optional, to be able to set a invalid password
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5915
diff changeset
321 u.enc_password = ''
c99f570e274a moin account resetpw: make password optional, to be able to set a invalid password
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5915
diff changeset
322 else:
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
323 u.enc_password = encodePassword(request.cfg, newpass)
5915
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
324 u.save()
5940
1960726cd356 set_password: warn if user has no e-mail address in the profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5939
diff changeset
325 if not u.email:
1960726cd356 set_password: warn if user has no e-mail address in the profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5939
diff changeset
326 raise UserHasNoEMail('User profile does not have an E-Mail address (name: %r id: %r)!' % (u.name, u.id))
5929
8d03f3ec97a7 don't try to send email to user if email address in profile is empty
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5922
diff changeset
327 if notify and not u.disabled:
5936
2d3352c547bc moin account resetpw - misc. improvements
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5930
diff changeset
328 mailok, msg = u.mailAccountData(subject=subject,
2d3352c547bc moin account resetpw - misc. improvements
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5930
diff changeset
329 text_intro=text_intro, text_msg=text_msg, text_data=text_data)
5915
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
330 if not mailok:
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
331 raise MailFailed(msg)
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
332 else:
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
333 raise NoSuchUser('User does not exist (name: %r id: %r)!' % (u.name, u.id))
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
334
19e8a1c50bda moin account resetpw - added options --all-users and --notify
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5904
diff changeset
335
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
336 def normalizeName(name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
337 """ Make normalized user name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
338
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
339 Prevent impersonating another user with names containing leading,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
340 trailing or multiple whitespace, or using invisible unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
341 characters.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
342
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
343 Prevent creating user page as sub page, because '/' is not allowed
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
344 in user names.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
345
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
346 Prevent using ':' and ',' which are reserved by acl.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
347
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
348 @param name: user name, unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
349 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
350 @return: user name that can be used in acl lines
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
351 """
826
8e880418d736 remove all underscore <-> blank magic
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
352 username_allowedchars = "'@.-_" # ' for names like O'Brian or email addresses.
8e880418d736 remove all underscore <-> blank magic
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
353 # "," and ":" must not be allowed (ACL delimiters).
8e880418d736 remove all underscore <-> blank magic
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
354 # We also allow _ in usernames for nicer URLs.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
355 # Strip non alpha numeric characters (except username_allowedchars), keep white space
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
356 name = ''.join([c for c in name if c.isalnum() or c.isspace() or c in username_allowedchars])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
357
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
358 # Normalize white space. Each name can contain multiple
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
359 # words separated with only one space.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
360 name = ' '.join(name.split())
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
361
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
362 return name
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
363
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
364
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
365 def isValidName(request, name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
366 """ Validate user name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
367
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
368 @param name: user name, unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
369 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
370 normalized = normalizeName(name)
4146
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3631
diff changeset
371 return (name == normalized) and not wikiutil.isGroupPage(name, request.cfg)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
372
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
373
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
374 def encodeList(items):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
375 """ Encode list of items in user data file
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
376
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
377 Items are separated by '\t' characters.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
378
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
379 @param items: list unicode strings
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
380 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
381 @return: list encoded as unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
382 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
383 line = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
384 for item in items:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
385 item = item.strip()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
386 if not item:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
387 continue
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
388 line.append(item)
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
389
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
390 line = '\t'.join(line)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
391 return line
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
392
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
393 def decodeList(line):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
394 """ Decode list of items from user data file
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
395
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
396 @param line: line containing list of items, encoded with encodeList
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
397 @rtype: list of unicode strings
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
398 @return: list of items in encoded in line
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
399 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
400 items = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
401 for item in line.split('\t'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
402 item = item.strip()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
403 if not item:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
404 continue
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
405 items.append(item)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
406 return items
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
407
1940
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
408 def encodeDict(items):
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
409 """ Encode dict of items in user data file
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
410
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
411 Items are separated by '\t' characters.
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
412 Each item is key:value.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
413
1940
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
414 @param items: dict of unicode:unicode
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
415 @rtype: unicode
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
416 @return: dict encoded as unicode
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
417 """
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
418 line = []
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
419 for key, value in items.items():
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
420 item = u'%s:%s' % (key, value)
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
421 line.append(item)
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
422 line = '\t'.join(line)
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
423 return line
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
424
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
425 def decodeDict(line):
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
426 """ Decode dict of key:value pairs from user data file
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
427
1940
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
428 @param line: line containing a dict, encoded with encodeDict
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
429 @rtype: dict
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
430 @return: dict unicode:unicode items
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
431 """
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
432 items = {}
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
433 for item in line.split('\t'):
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
434 item = item.strip()
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
435 if not item:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
436 continue
1940
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
437 key, value = item.split(':', 1)
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
438 items[key] = value
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
439 return items
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
440
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
441
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
442 class User:
1963
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
443 """ A MoinMoin User """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
444
265
2cbc7dc436d7 auth changes: added u.auth_method, u.auth_attribs and some debug code. Support for switching off some form fields.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 244
diff changeset
445 def __init__(self, request, id=None, name="", password=None, auth_username="", **kw):
244
42f749b0d8bb fix empty username when using auth_username for autocreation
Thomas Waldmann <tw@waldmann-edv.de>
parents: 238
diff changeset
446 """ Initialize User object
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
447
1986
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1963
diff changeset
448 TODO: when this gets refactored, use "uid" not builtin "id"
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1963
diff changeset
449
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
450 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
451 @param id: (optional) user ID
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
452 @param name: (optional) user name
1606
ae56d79ae076 http auth / ssl clientcert auth: correctly decode name/password/email to unicode (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1597
diff changeset
453 @param password: (optional) user password (unicode)
265
2cbc7dc436d7 auth changes: added u.auth_method, u.auth_attribs and some debug code. Support for switching off some form fields.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 244
diff changeset
454 @param auth_username: (optional) already authenticated user name
1606
ae56d79ae076 http auth / ssl clientcert auth: correctly decode name/password/email to unicode (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1597
diff changeset
455 (e.g. when using http basic auth) (unicode)
265
2cbc7dc436d7 auth changes: added u.auth_method, u.auth_attribs and some debug code. Support for switching off some form fields.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 244
diff changeset
456 @keyword auth_method: method that was used for authentication,
2cbc7dc436d7 auth changes: added u.auth_method, u.auth_attribs and some debug code. Support for switching off some form fields.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 244
diff changeset
457 default: 'internal'
2cbc7dc436d7 auth changes: added u.auth_method, u.auth_attribs and some debug code. Support for switching off some form fields.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 244
diff changeset
458 @keyword auth_attribs: tuple of user object attribute names that are
2cbc7dc436d7 auth changes: added u.auth_method, u.auth_attribs and some debug code. Support for switching off some form fields.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 244
diff changeset
459 determined by auth method and should not be
3333
928a45b60bb3 remove remaining mentions of "UserPreferences", add to CHANGES
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3175
diff changeset
460 changeable by preferences, default: ().
265
2cbc7dc436d7 auth changes: added u.auth_method, u.auth_attribs and some debug code. Support for switching off some form fields.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 244
diff changeset
461 First tuple element was used for authentication.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
462 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
463 self._cfg = request.cfg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
464 self.valid = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
465 self.id = id
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
466 self.auth_username = auth_username
265
2cbc7dc436d7 auth changes: added u.auth_method, u.auth_attribs and some debug code. Support for switching off some form fields.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 244
diff changeset
467 self.auth_method = kw.get('auth_method', 'internal')
2cbc7dc436d7 auth changes: added u.auth_method, u.auth_attribs and some debug code. Support for switching off some form fields.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 244
diff changeset
468 self.auth_attribs = kw.get('auth_attribs', ())
1940
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
469 self.bookmarks = {} # interwikiname: bookmark
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
470
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
471 # create some vars automatically
737
87cf4c0aac44 hopefully fixes the css_url backtrace for new users when admin removed css_url form field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 733
diff changeset
472 self.__dict__.update(self._cfg.user_form_defaults)
87cf4c0aac44 hopefully fixes the css_url backtrace for new users when admin removed css_url form field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 733
diff changeset
473
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
474 if name:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
475 self.name = name
4041
4a994a297ba3 replace cfg.user_autocreate setting by autocreate=<boolean> parameter of auth objects
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3845
diff changeset
476 elif auth_username: # this is needed for user autocreate
244
42f749b0d8bb fix empty username when using auth_username for autocreation
Thomas Waldmann <tw@waldmann-edv.de>
parents: 238
diff changeset
477 self.name = auth_username
266
1fb19804a4b9 removed some debug code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 265
diff changeset
478
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
479 # create checkbox fields (with default 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
480 for key, label in self._cfg.user_checkbox_fields:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
481 setattr(self, key, self._cfg.user_checkbox_defaults.get(key, 0))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
482
3567
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
483 self.recoverpass_key = ""
3564
474f6ad01900 recoverpass: email password reset token rather than sha1
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3333
diff changeset
484
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
485 if password:
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
486 self.enc_password = encodePassword(self._cfg, password)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
487
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
488 #self.edit_cols = 80
8
da9701a3facb more cleanup
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
489 self.tz_offset = int(float(self._cfg.tz_offset) * 3600)
da9701a3facb more cleanup
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
490 self.language = ""
3032
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2726
diff changeset
491 self.real_language = "" # In case user uses "Browser setting". For language-statistics
3842
f40bd4c68aa2 MoinMoin.user: fix MoinMoinBugs/DuplicateNewUserNotification
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
492 self._stored = False
8
da9701a3facb more cleanup
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
493 self.date_fmt = ""
da9701a3facb more cleanup
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
494 self.datetime_fmt = ""
1689
7b80735ede14 quicklinks_default and subscribed_pages_default to preload the lists in the user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1638
diff changeset
495 self.quicklinks = self._cfg.quicklinks_default
7b80735ede14 quicklinks_default and subscribed_pages_default to preload the lists in the user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1638
diff changeset
496 self.subscribed_pages = self._cfg.subscribed_pages_default
2429
0cd1152b8da5 default to email notification of all events to ease migration from old scheme
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2426
diff changeset
497 self.email_subscribed_events = self._cfg.email_subscribed_events_default
0cd1152b8da5 default to email notification of all events to ease migration from old scheme
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2426
diff changeset
498 self.jabber_subscribed_events = self._cfg.jabber_subscribed_events_default
8
da9701a3facb more cleanup
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
499 self.theme_name = self._cfg.theme_default
da9701a3facb more cleanup
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
500 self.editor_default = self._cfg.editor_default
da9701a3facb more cleanup
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
501 self.editor_ui = self._cfg.editor_ui
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
502 self.last_saved = str(time.time())
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
503
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
504 # attrs not saved to profile
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
505 self._request = request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
506
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
507 # we got an already authenticated username:
3808
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
508 check_password = None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
509 if not self.id and self.auth_username:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
510 self.id = getUserId(request, self.auth_username)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
511 if not password is None:
3808
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
512 check_password = password
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
513 if self.id:
3808
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
514 self.load_from_id(check_password)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
515 elif self.name:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
516 self.id = getUserId(self._request, self.name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
517 if self.id:
3808
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
518 # no password given should fail
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
519 self.load_from_id(password or u'')
3819
b3b04ffbecd8 user: fix password validation
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3818
diff changeset
520 # Still no ID - make new user
b3b04ffbecd8 user: fix password validation
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3818
diff changeset
521 if not self.id:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
522 self.id = self.make_id()
3819
b3b04ffbecd8 user: fix password validation
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3818
diff changeset
523 if password is not None:
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
524 self.enc_password = encodePassword(self._cfg, password)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
525
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
526 # "may" so we can say "if user.may.read(pagename):"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
527 if self._cfg.SecurityPolicy:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
528 self.may = self._cfg.SecurityPolicy(self)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
529 else:
1535
6a7dd84b091f Fixed evil relative import.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1430
diff changeset
530 from MoinMoin.security import Default
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
531 self.may = Default(self)
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
532
689
ff56d9861a71 yet another i18n fix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 688
diff changeset
533 if self.language and not self.language in i18n.wikiLanguages():
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
534 self.language = 'en'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
535
339
083c2d82a173 add User.__repr__
Thomas Waldmann <tw@waldmann-edv.de>
parents: 266
diff changeset
536 def __repr__(self):
1075
2ecd1e6c084d Fixed security issues in MoinMoin.user (do not reveal the ID), added variable hiding to cgitb.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1005
diff changeset
537 return "<%s.%s at 0x%x name:%r valid:%r>" % (
339
083c2d82a173 add User.__repr__
Thomas Waldmann <tw@waldmann-edv.de>
parents: 266
diff changeset
538 self.__class__.__module__, self.__class__.__name__,
1075
2ecd1e6c084d Fixed security issues in MoinMoin.user (do not reveal the ID), added variable hiding to cgitb.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1005
diff changeset
539 id(self), self.name, self.valid)
339
083c2d82a173 add User.__repr__
Thomas Waldmann <tw@waldmann-edv.de>
parents: 266
diff changeset
540
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
541 def make_id(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
542 """ make a new unique user id """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
543 #!!! this should probably be a hash of REMOTE_ADDR, HTTP_USER_AGENT
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
544 # and some other things identifying remote users, then we could also
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
545 # use it reliably in edit locking
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
546 from random import randint
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
547 return "%s.%d" % (str(time.time()), randint(0, 65535))
238
b80624429934 added cfg.user_autocreate, for now for auth.http and auth.ssl_clientcert
Thomas Waldmann <tw@waldmann-edv.de>
parents: 232
diff changeset
548
b80624429934 added cfg.user_autocreate, for now for auth.http and auth.ssl_clientcert
Thomas Waldmann <tw@waldmann-edv.de>
parents: 232
diff changeset
549 def create_or_update(self, changed=False):
b80624429934 added cfg.user_autocreate, for now for auth.http and auth.ssl_clientcert
Thomas Waldmann <tw@waldmann-edv.de>
parents: 232
diff changeset
550 """ Create or update a user profile
b80624429934 added cfg.user_autocreate, for now for auth.http and auth.ssl_clientcert
Thomas Waldmann <tw@waldmann-edv.de>
parents: 232
diff changeset
551
b80624429934 added cfg.user_autocreate, for now for auth.http and auth.ssl_clientcert
Thomas Waldmann <tw@waldmann-edv.de>
parents: 232
diff changeset
552 @param changed: bool, set this to True if you updated the user profile values
b80624429934 added cfg.user_autocreate, for now for auth.http and auth.ssl_clientcert
Thomas Waldmann <tw@waldmann-edv.de>
parents: 232
diff changeset
553 """
4041
4a994a297ba3 replace cfg.user_autocreate setting by autocreate=<boolean> parameter of auth objects
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3845
diff changeset
554 if not self.valid and not self.disabled or changed: # do we need to save/update?
4a994a297ba3 replace cfg.user_autocreate setting by autocreate=<boolean> parameter of auth objects
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3845
diff changeset
555 self.save() # yes, create/update user profile
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
556
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
557 def __filename(self):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
558 """ Get filename of the user's file on disk
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
559
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
560 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
561 @return: full path and filename of user account file
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
562 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
563 return os.path.join(self._cfg.user_dir, self.id or "...NONE...")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
564
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
565 def exists(self):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
566 """ Do we have a user account for this user?
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
567
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
568 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
569 @return: true, if we have a user account
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
570 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
571 return os.path.exists(self.__filename())
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
572
5939
24054d620fc1 moin account inactive - find, show, disable, remove inactive users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5936
diff changeset
573 def remove(self):
24054d620fc1 moin account inactive - find, show, disable, remove inactive users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5936
diff changeset
574 """ Remove user profile from disk """
24054d620fc1 moin account inactive - find, show, disable, remove inactive users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5936
diff changeset
575 os.remove(self.__filename())
24054d620fc1 moin account inactive - find, show, disable, remove inactive users
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5936
diff changeset
576
3808
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
577 def load_from_id(self, password=None):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
578 """ Load user account data from disk.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
579
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
580 Can only load user data if the id number is already known.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
581
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
582 This loads all member variables, except "id" and "valid" and
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
583 those starting with an underscore.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
584
3808
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
585 @param password: If not None, then the given password must match the
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
586 password in the user account file.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
587 """
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
588 if not self.exists():
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
589 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
590
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
591 data = codecs.open(self.__filename(), "r", config.charset).readlines()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
592 user_data = {'enc_password': ''}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
593 for line in data:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
594 if line[0] == '#':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
595 continue
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
596
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
597 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
598 key, val = line.strip().split('=', 1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
599 if key not in self._cfg.user_transient_fields and key[0] != '_':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
600 # Decode list values
1923
eefebea247a0 user profiles: store lists with key[]=val1\tval2... (thanks to Johannes Berg)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
601 if key.endswith('[]'):
eefebea247a0 user profiles: store lists with key[]=val1\tval2... (thanks to Johannes Berg)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
602 key = key[:-2]
eefebea247a0 user profiles: store lists with key[]=val1\tval2... (thanks to Johannes Berg)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
603 val = decodeList(val)
1940
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
604 # Decode dict values
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
605 elif key.endswith('{}'):
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
606 key = key[:-2]
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
607 val = decodeDict(val)
1923
eefebea247a0 user profiles: store lists with key[]=val1\tval2... (thanks to Johannes Berg)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
608 # for compatibility reading old files, keep these explicit
eefebea247a0 user profiles: store lists with key[]=val1\tval2... (thanks to Johannes Berg)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
609 # we will store them with [] appended
2152
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2092
diff changeset
610 elif key in ['quicklinks', 'subscribed_pages', 'subscribed_events']:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
611 val = decodeList(val)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
612 user_data[key] = val
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
613 except ValueError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
614 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
615
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
616 # Validate data from user file. In case we need to change some
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
617 # values, we set 'changed' flag, and later save the user data.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
618 changed = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
619
3808
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
620 if password is not None:
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
621 # Check for a valid password, possibly changing storage
3819
b3b04ffbecd8 user: fix password validation
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3818
diff changeset
622 valid, changed = self._validatePassword(user_data, password)
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
623 if not valid:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
624 return
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
625
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
626 # Remove ignored checkbox values from user data
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
627 for key, label in self._cfg.user_checkbox_fields:
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1832
diff changeset
628 if key in user_data and key in self._cfg.user_checkbox_disable:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
629 del user_data[key]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
630
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
631 # Copy user data into user object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
632 for key, val in user_data.items():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
633 vars(self)[key] = val
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
634
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
635 self.tz_offset = int(self.tz_offset)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
636
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
637 # Remove old unsupported attributes from user data file.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
638 remove_attributes = ['passwd', 'show_emoticons']
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
639 for attr in remove_attributes:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
640 if hasattr(self, attr):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
641 delattr(self, attr)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
642 changed = 1
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
643
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
644 # make sure checkboxes are boolean
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
645 for key, label in self._cfg.user_checkbox_fields:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
646 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
647 setattr(self, key, int(getattr(self, key)))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
648 except ValueError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
649 setattr(self, key, 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
650
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
651 # convert (old) hourly format to seconds
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
652 if -24 <= self.tz_offset and self.tz_offset <= 24:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
653 self.tz_offset = self.tz_offset * 3600
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
654
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
655 if not self.disabled:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
656 self.valid = 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
657
3842
f40bd4c68aa2 MoinMoin.user: fix MoinMoinBugs/DuplicateNewUserNotification
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
658 # Mark this user as stored so saves don't send
f40bd4c68aa2 MoinMoin.user: fix MoinMoinBugs/DuplicateNewUserNotification
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
659 # the "user created" event
f40bd4c68aa2 MoinMoin.user: fix MoinMoinBugs/DuplicateNewUserNotification
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
660 self._stored = True
2493
f3e3ffa68a7f Send UserCreatedEvent from user.save(), not the newaccount action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2429
diff changeset
661
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
662 # If user data has been changed, save fixed user data.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
663 if changed:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
664 self.save()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
665
3819
b3b04ffbecd8 user: fix password validation
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3818
diff changeset
666 def _validatePassword(self, data, password):
3808
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
667 """
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
668 Check user password.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
669
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
670 This is a private method and should not be used by clients.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
671
3808
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
672 @param data: dict with user data (from storage)
5239
90fae67c4cda Fix SHA -> SSHA password hash upgrade for old user profiles (more details below).
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4491
diff changeset
673 @param password: password to verify [unicode]
3808
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
674 @rtype: 2 tuple (bool, bool)
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
675 @return: password is valid, enc_password changed
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
676 """
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
677 epwd = data['enc_password']
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
678
3808
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
679 # If we have no password set, we don't accept login with username
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
680 if not epwd:
8c5fbc62dd1d user storage: hash stored passwords, upgrade on use, remove charset magic
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
681 return False, False
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
682
3819
b3b04ffbecd8 user: fix password validation
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3818
diff changeset
683 # require non empty password
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
684 if not password:
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
685 return False, False
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
686
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
687 password_correct = recompute_hash = False
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
688 wanted_scheme = self._cfg.password_scheme
5918
5126fadbf24f password related code and tests - clean up and refactor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5917
diff changeset
689
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
690 # Check password and upgrade weak hashes to strong default algorithm:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
691 for scheme in config.password_schemes_supported:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
692 if epwd.startswith(scheme):
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
693 is_passlib = False
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
694 d = epwd[len(scheme):]
5720
69668ad0cae7 add support for other password hashes (thanks to Michael Foetsch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5613
diff changeset
695
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
696 if scheme == '{PASSLIB}':
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
697 # a password hash to be checked by passlib library code
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
698 if not self._cfg.passlib_support:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
699 logging.error('in user profile %r, password hash with {PASSLIB} scheme encountered, but passlib_support is False' % (self.id, ))
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
700 else:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
701 pwd_context = self._cfg.cache.pwd_context
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
702 try:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
703 password_correct = pwd_context.verify(password, d)
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
704 except ValueError, err:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
705 # can happen for unknown scheme
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
706 logging.error('in user profile %r, verifying the passlib pw hash crashed [%s]' % (self.id, str(err)))
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
707 if password_correct:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
708 # check if we need to recompute the hash. this is needed if either the
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
709 # passlib hash scheme / hash params changed or if we shall change to a
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
710 # builtin hash scheme (not recommended):
5971
96ef8a8ecc80 improve some passlib related code using the 1.6.1-post-release doc updates
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5959
diff changeset
711 recompute_hash = pwd_context.hash_needs_update(d) or wanted_scheme != '{PASSLIB}'
5918
5126fadbf24f password related code and tests - clean up and refactor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5917
diff changeset
712
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
713 else:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
714 # a password hash to be checked by legacy, builtin code
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
715 if scheme == '{SSHA}':
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
716 d = base64.decodestring(d)
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
717 salt = d[20:]
6103
500f68d3e2fd remove our own usage of python_compatibility module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6043
diff changeset
718 hash = hashlib.new('sha1', password.encode('utf-8'))
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
719 hash.update(salt)
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
720 enc = base64.encodestring(hash.digest() + salt).rstrip()
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
721
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
722 elif scheme == '{SHA}':
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
723 enc = base64.encodestring(
6103
500f68d3e2fd remove our own usage of python_compatibility module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6043
diff changeset
724 hashlib.new('sha1', password.encode('utf-8')).digest()).rstrip()
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
725
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
726 elif scheme == '{APR1}':
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
727 # d is of the form "$apr1$<salt>$<hash>"
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
728 salt = d.split('$')[2]
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
729 enc = md5crypt.apache_md5_crypt(password.encode('utf-8'),
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
730 salt.encode('ascii'))
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
731 elif scheme == '{MD5}':
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
732 # d is of the form "$1$<salt>$<hash>"
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
733 salt = d.split('$')[2]
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
734 enc = md5crypt.unix_md5_crypt(password.encode('utf-8'),
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
735 salt.encode('ascii'))
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
736 elif scheme == '{DES}':
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
737 if crypt is None:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
738 return False, False
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
739 # d is 2 characters salt + 11 characters hash
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
740 salt = d[:2]
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
741 enc = crypt.crypt(password.encode('utf-8'), salt.encode('ascii'))
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
742
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
743 else:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
744 logging.error('in user profile %r, password hash with unknown scheme encountered: %r' % (self.id, scheme))
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
745 raise NotImplementedError
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
746
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
747 if safe_str_equal(epwd, scheme + enc):
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
748 password_correct = True
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
749 recompute_hash = scheme != wanted_scheme
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
750
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
751 if recompute_hash:
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
752 data['enc_password'] = encodePassword(self._cfg, password)
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
753 return password_correct, recompute_hash
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
754
5918
5126fadbf24f password related code and tests - clean up and refactor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5917
diff changeset
755 # unsupported algorithm
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
756 return False, False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
757
1951
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
758 def persistent_items(self):
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
759 """ items we want to store into the user profile """
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
760 return [(key, value) for key, value in vars(self).items()
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
761 if key not in self._cfg.user_transient_fields and key[0] != '_']
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
762
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
763 def save(self):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
764 """ Save user account data to user account file on disk.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
765
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
766 This saves all member variables, except "id" and "valid" and
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
767 those starting with an underscore.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
768 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
769 if not self.id:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
770 return
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
771
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
772 user_dir = self._cfg.user_dir
1430
fd7166892bd3 check for non-existing dir before calling os.makedirs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1428
diff changeset
773 if not os.path.exists(user_dir):
fd7166892bd3 check for non-existing dir before calling os.makedirs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1428
diff changeset
774 os.makedirs(user_dir)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
775
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
776 self.last_saved = str(time.time())
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
777
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
778 # !!! should write to a temp file here to avoid race conditions,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
779 # or even better, use locking
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
780
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
781 data = codecs.open(self.__filename(), "w", config.charset)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
782 data.write("# Data saved '%s' for id '%s'\n" % (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
783 time.strftime(self._cfg.datetime_fmt, time.localtime(time.time())),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
784 self.id))
1951
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
785 attrs = self.persistent_items()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
786 attrs.sort()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
787 for key, value in attrs:
1951
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
788 # Encode list values
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
789 if isinstance(value, list):
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
790 key += '[]'
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
791 value = encodeList(value)
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
792 # Encode dict values
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
793 elif isinstance(value, dict):
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
794 key += '{}'
a05a3b447db5 interwiki auth fixed, added getUserData xmlrpc method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
795 value = encodeDict(value)
5530
970d94ea19f2 user profile saving, eliminate lineseps in keys/values
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4480
diff changeset
796 line = u"%s=%s" % (key, unicode(value))
970d94ea19f2 user profile saving, eliminate lineseps in keys/values
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4480
diff changeset
797 line = line.replace('\n', ' ').replace('\r', ' ') # no lineseps
970d94ea19f2 user profile saving, eliminate lineseps in keys/values
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4480
diff changeset
798 data.write(line + '\n')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
799 data.close()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
800
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
801 if not self.disabled:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
802 self.valid = 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
803
6030
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
804 self.updateLookupCaches()
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
805
3842
f40bd4c68aa2 MoinMoin.user: fix MoinMoinBugs/DuplicateNewUserNotification
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
806 if not self._stored:
f40bd4c68aa2 MoinMoin.user: fix MoinMoinBugs/DuplicateNewUserNotification
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3707
diff changeset
807 self._stored = True
2493
f3e3ffa68a7f Send UserCreatedEvent from user.save(), not the newaccount action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2429
diff changeset
808 event = events.UserCreatedEvent(self._request, self)
f3e3ffa68a7f Send UserCreatedEvent from user.save(), not the newaccount action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2429
diff changeset
809 events.send_event(event)
f3e3ffa68a7f Send UserCreatedEvent from user.save(), not the newaccount action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2429
diff changeset
810
6021
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
811 # update page subscriber's cache after saving user preferences
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
812 self.updatePageSubCache()
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
813
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
814 # -----------------------------------------------------------------
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
815 # Time and date formatting
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
816
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
817 def getTime(self, tm):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
818 """ Get time in user's timezone.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
819
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
820 @param tm: time (UTC UNIX timestamp)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
821 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
822 @return: tm tuple adjusted for user's timezone
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
823 """
476
4be11eec9c4f MoinMoin.util.datetime -> timefuncs to avoid conflict/confusion with stdlib datetime, also moved util.W3CDate there
Thomas Waldmann <tw@waldmann-edv.de>
parents: 449
diff changeset
824 return timefuncs.tmtuple(tm + self.tz_offset)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
825
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
826
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
827 def getFormattedDate(self, tm):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
828 """ Get formatted date adjusted for user's timezone.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
829
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
830 @param tm: time (UTC UNIX timestamp)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
831 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
832 @return: formatted date, see cfg.date_fmt
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
833 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
834 date_fmt = self.date_fmt or self._cfg.date_fmt
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
835 return time.strftime(date_fmt, self.getTime(tm))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
836
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
837
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
838 def getFormattedDateTime(self, tm):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
839 """ Get formatted date and time adjusted for user's timezone.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
840
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
841 @param tm: time (UTC UNIX timestamp)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
842 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
843 @return: formatted date and time, see cfg.datetime_fmt
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
844 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
845 datetime_fmt = self.datetime_fmt or self._cfg.datetime_fmt
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
846 return time.strftime(datetime_fmt, self.getTime(tm))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
847
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
848 # -----------------------------------------------------------------
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
849 # Bookmark
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
850
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
851 def setBookmark(self, tm):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
852 """ Set bookmark timestamp.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
853
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
854 @param tm: timestamp
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
855 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
856 if self.valid:
4480
af8cea9bfcda made cfg.interwikiname a unicode object (str only worked for ascii)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3842
diff changeset
857 interwikiname = self._cfg.interwikiname or u''
1940
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
858 bookmark = unicode(tm)
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
859 self.bookmarks[interwikiname] = bookmark
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
860 self.save()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
861
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
862 def getBookmark(self):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
863 """ Get bookmark timestamp.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
864
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
865 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
866 @return: bookmark timestamp or None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
867 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
868 bm = None
4480
af8cea9bfcda made cfg.interwikiname a unicode object (str only worked for ascii)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3842
diff changeset
869 interwikiname = self._cfg.interwikiname or u''
1940
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
870 if self.valid:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
871 try:
1940
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
872 bm = int(self.bookmarks[interwikiname])
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
873 except (ValueError, KeyError):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
874 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
875 return bm
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
876
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
877 def delBookmark(self):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
878 """ Removes bookmark timestamp.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
879
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
880 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
881 @return: 0 on success, 1 on failure
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
882 """
4480
af8cea9bfcda made cfg.interwikiname a unicode object (str only worked for ascii)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3842
diff changeset
883 interwikiname = self._cfg.interwikiname or u''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
884 if self.valid:
1940
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
885 try:
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
886 del self.bookmarks[interwikiname]
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
887 except KeyError:
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
888 return 1
d7296d36e6f0 enable user storage code to save simple dicts to user profile, use that to save RC bookmarks into user profile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
889 self.save()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
890 return 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
891 return 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
892
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
893 # -----------------------------------------------------------------
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
894 # Subscribe
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
895
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
896 def getSubscriptionList(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
897 """ Get list of pages this user has subscribed to
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
898
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
899 @rtype: list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
900 @return: pages this user has subscribed to
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
901 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
902 return self.subscribed_pages
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
903
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
904 def isSubscribedTo(self, pagelist):
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
905 """ Check if user subscription matches any page in pagelist.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
906
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
907 The subscription list may contain page names or interwiki page
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
908 names. e.g 'Page Name' or 'WikiName:Page_Name'
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
909
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
910 @param pagelist: list of pages to check for subscription
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
911 @rtype: bool
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
912 @return: if user is subscribed any page in pagelist
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
913 """
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
914 if not self.valid:
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
915 return False
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
916
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
917 import re
94
7f531b511f2e fix isSubscribedTo when calling multiple times, for example from page.getSubscribersList()
Nir Soffer <nirs@freeshell.org>
parents: 90
diff changeset
918 # Create a new list with both names and interwiki names.
7f531b511f2e fix isSubscribedTo when calling multiple times, for example from page.getSubscribersList()
Nir Soffer <nirs@freeshell.org>
parents: 90
diff changeset
919 pages = pagelist[:]
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
920 if self._cfg.interwikiname:
94
7f531b511f2e fix isSubscribedTo when calling multiple times, for example from page.getSubscribersList()
Nir Soffer <nirs@freeshell.org>
parents: 90
diff changeset
921 pages += [self._interWikiName(pagename) for pagename in pagelist]
7f531b511f2e fix isSubscribedTo when calling multiple times, for example from page.getSubscribersList()
Nir Soffer <nirs@freeshell.org>
parents: 90
diff changeset
922 # Create text for regular expression search
7f531b511f2e fix isSubscribedTo when calling multiple times, for example from page.getSubscribersList()
Nir Soffer <nirs@freeshell.org>
parents: 90
diff changeset
923 text = '\n'.join(pages)
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
924
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
925 for pattern in self.getSubscriptionList():
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
926 # Try simple match first
94
7f531b511f2e fix isSubscribedTo when calling multiple times, for example from page.getSubscribersList()
Nir Soffer <nirs@freeshell.org>
parents: 90
diff changeset
927 if pattern in pages:
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
928 return True
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
929 # Try regular expression search, skipping bad patterns
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
930 try:
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
931 pattern = re.compile(r'^%s$' % pattern, re.M)
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
932 except re.error:
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
933 continue
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
934 if pattern.search(text):
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
935 return True
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
936
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
937 return False
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
938
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
939 def subscribe(self, pagename):
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
940 """ Subscribe to a wiki page.
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
941
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
942 To enable shared farm users, if the wiki has an interwiki name,
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
943 page names are saved as interwiki names.
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
944
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
945 @param pagename: name of the page to subscribe
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
946 @type pagename: unicode
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
947 @rtype: bool
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
948 @return: if page was subscribed
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
949 """
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
950 if self._cfg.interwikiname:
121
e61a09408702 fix name error in user.subscribe
Nir Soffer <nirs@freeshell.org>
parents: 94
diff changeset
951 pagename = self._interWikiName(pagename)
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
952
121
e61a09408702 fix name error in user.subscribe
Nir Soffer <nirs@freeshell.org>
parents: 94
diff changeset
953 if pagename not in self.subscribed_pages:
e61a09408702 fix name error in user.subscribe
Nir Soffer <nirs@freeshell.org>
parents: 94
diff changeset
954 self.subscribed_pages.append(pagename)
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
955 self.save()
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
956
2065
23d90aae61b5 Send events when an user subscribes to a page and when page gets reverted.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2035
diff changeset
957 # Send a notification
23d90aae61b5 Send events when an user subscribes to a page and when page gets reverted.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2035
diff changeset
958 from MoinMoin.events import SubscribedToPageEvent, send_event
23d90aae61b5 Send events when an user subscribes to a page and when page gets reverted.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2035
diff changeset
959 e = SubscribedToPageEvent(self._request, pagename, self.name)
23d90aae61b5 Send events when an user subscribes to a page and when page gets reverted.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2035
diff changeset
960 send_event(e)
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
961 return True
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
962
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
963 return False
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
964
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
965 def unsubscribe(self, pagename):
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
966 """ Unsubscribe a wiki page.
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
967
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
968 Try to unsubscribe by removing non-interwiki name (leftover
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
969 from old use files) and interwiki name from the subscription
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
970 list.
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
971
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
972 Its possible that the user will be subscribed to a page by more
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
973 then one pattern. It can be both pagename and interwiki name,
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
974 or few patterns that all of them match the page. Therefore, we
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
975 must check if the user is still subscribed to the page after we
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
976 try to remove names from the list.
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
977
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
978 @param pagename: name of the page to subscribe
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
979 @type pagename: unicode
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
980 @rtype: bool
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
981 @return: if unsubscrieb was successful. If the user has a
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
982 regular expression that match, it will always fail.
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
983 """
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
984 changed = False
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
985 if pagename in self.subscribed_pages:
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
986 self.subscribed_pages.remove(pagename)
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
987 changed = True
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
988
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
989 interWikiName = self._interWikiName(pagename)
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
990 if interWikiName and interWikiName in self.subscribed_pages:
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
991 self.subscribed_pages.remove(interWikiName)
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
992 changed = True
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
993
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
994 if changed:
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
995 self.save()
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
996 return not self.isSubscribedTo([pagename])
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
997
6021
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
998 def updatePageSubCache(self):
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
999 """ When a user profile is saved, we update the page subscriber's cache """
6021
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1000
6024
ad461ba29a17 getSubscribers: fix: move the cache to "userdir" scope, update cleancache script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6022
diff changeset
1001 scope, arena, key = 'userdir', 'users', 'pagesubscriptions'
6021
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1002
6024
ad461ba29a17 getSubscribers: fix: move the cache to "userdir" scope, update cleancache script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6022
diff changeset
1003 cache = caching.CacheEntry(self._request, arena=arena, key=key, scope=scope, use_pickle=True, do_locking=False)
6021
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1004 if not cache.exists():
6022
fa5f81a0dfa9 getSubscribers: cleanups, optimizations, locking fix, .valid fix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6021
diff changeset
1005 return # if no cache file exists, just don't do anything
6021
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1006
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1007 cache.lock('w')
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1008 page_sub = cache.content()
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1009
6030
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1010 # we only store entries for valid users with some page subscriptions
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1011 if self.valid and self.subscribed_pages:
6021
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1012 page_sub[self.id] = {
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1013 'name': self.name,
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1014 'email': self.email,
6022
fa5f81a0dfa9 getSubscribers: cleanups, optimizations, locking fix, .valid fix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6021
diff changeset
1015 'subscribed_pages': self.subscribed_pages,
6021
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1016 }
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1017 elif page_sub.get(self.id):
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1018 del page_sub[self.id]
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1019
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1020 cache.update(page_sub)
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1021 cache.unlock()
54dc774ff49b apply original patches from MoinMoinBugs/GetSubscribersSlow (as is)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5985
diff changeset
1022
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1023 def updateLookupCaches(self):
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1024 """ When a user profile is saved, we update the userid lookup caches """
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1025
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1026 scope, arena, key = 'userdir', 'users', 'lookup'
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1027
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1028 diskcache = caching.CacheEntry(self._request, arena=arena, key=key, scope=scope, use_pickle=True, do_locking=False)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1029 if not diskcache.exists():
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1030 return # if no cache file exists, just don't do anything
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1031
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1032 diskcache.lock('w')
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1033 cache = diskcache.content()
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1034 userid = self.id
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1035
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1036 # first remove all old entries mapping to this userid:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1037 for attrname in CACHED_USER_ATTRS:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1038 attr2id = cache[attrname]
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1039 for key, value in attr2id.items():
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1040 if value == userid:
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1041 del attr2id[key]
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1042
6030
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1043 # then, if user is valid, update with the current attr values:
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1044 if self.valid:
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1045 for attrname in CACHED_USER_ATTRS:
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1046 if hasattr(self, attrname):
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1047 value = getattr(self, attrname)
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1048 if value:
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1049 # we do not store empty values, likely not unique
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1050 attr2id = cache[attrname]
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1051 if isinstance(value, list):
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1052 for val in value:
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1053 attr2id[val] = userid
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1054 else:
5ab38cec99f7 only cache valid user's attributes (we don't care for invalid/disabled user profiles)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6029
diff changeset
1055 attr2id[value] = userid
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1056
6031
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
1057 cache_with_lowercase = addLowerCaseKeys(cache)
1b2e1497f5ed replace slow get_by_filter() calls by faster _getUserIdByKey calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6030
diff changeset
1058 setMemoryLookupCaches(self._request, cache_with_lowercase)
6028
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1059 diskcache.update(cache)
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1060 diskcache.unlock()
1893da1d5213 userid lookup caches: use 1 on-disk cache file, update cache rather than rebuild
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6027
diff changeset
1061
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1062 # -----------------------------------------------------------------
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1063 # Quicklinks
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1064
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1065 def getQuickLinks(self):
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1066 """ Get list of pages this user wants in the navibar
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1067
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1068 @rtype: list
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1069 @return: quicklinks from user account
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1070 """
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1071 return self.quicklinks
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1072
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1073 def isQuickLinkedTo(self, pagelist):
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1074 """ Check if user quicklink matches any page in pagelist.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
1075
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1076 @param pagelist: list of pages to check for quicklinks
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1077 @rtype: bool
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1078 @return: if user has quicklinked any page in pagelist
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1079 """
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1080 if not self.valid:
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1081 return False
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
1082
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1083 for pagename in pagelist:
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1084 if pagename in self.quicklinks:
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1085 return True
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1086 interWikiName = self._interWikiName(pagename)
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1087 if interWikiName and interWikiName in self.quicklinks:
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1088 return True
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
1089
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1090 return False
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1091
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1092 def addQuicklink(self, pagename):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
1093 """ Adds a page to the user quicklinks
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
1094
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1095 If the wiki has an interwiki name, all links are saved as
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1096 interwiki names. If not, as simple page name.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1097
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1098 @param pagename: page name
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1099 @type pagename: unicode
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1100 @rtype: bool
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1101 @return: if pagename was added
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1102 """
22
a47550d21d2d quicklinks: avoid dupes, dont render as interwiki if wiki == self
Thomas Waldmann <tw@waldmann-edv.de>
parents: 8
diff changeset
1103 changed = False
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1104 interWikiName = self._interWikiName(pagename)
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1105 if interWikiName:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1106 if pagename in self.quicklinks:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1107 self.quicklinks.remove(pagename)
22
a47550d21d2d quicklinks: avoid dupes, dont render as interwiki if wiki == self
Thomas Waldmann <tw@waldmann-edv.de>
parents: 8
diff changeset
1108 changed = True
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1109 if interWikiName not in self.quicklinks:
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1110 self.quicklinks.append(interWikiName)
22
a47550d21d2d quicklinks: avoid dupes, dont render as interwiki if wiki == self
Thomas Waldmann <tw@waldmann-edv.de>
parents: 8
diff changeset
1111 changed = True
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1112 else:
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1113 if pagename not in self.quicklinks:
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1114 self.quicklinks.append(pagename)
22
a47550d21d2d quicklinks: avoid dupes, dont render as interwiki if wiki == self
Thomas Waldmann <tw@waldmann-edv.de>
parents: 8
diff changeset
1115 changed = True
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1116
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1117 if changed:
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1118 self.save()
22
a47550d21d2d quicklinks: avoid dupes, dont render as interwiki if wiki == self
Thomas Waldmann <tw@waldmann-edv.de>
parents: 8
diff changeset
1119 return changed
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1120
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1121 def removeQuicklink(self, pagename):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
1122 """ Remove a page from user quicklinks
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
1123
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1124 Remove both interwiki and simple name from quicklinks.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
1125
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1126 @param pagename: page name
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1127 @type pagename: unicode
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1128 @rtype: bool
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1129 @return: if pagename was removed
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1130 """
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1131 changed = False
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1132 interWikiName = self._interWikiName(pagename)
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1133 if interWikiName and interWikiName in self.quicklinks:
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1134 self.quicklinks.remove(interWikiName)
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1135 changed = True
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1136 if pagename in self.quicklinks:
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1137 self.quicklinks.remove(pagename)
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
1138 changed = True
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
1139
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1140 if changed:
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1141 self.save()
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1142 return changed
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1143
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1144 def _interWikiName(self, pagename):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
1145 """ Return the inter wiki name of a page name
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1146
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1147 @param pagename: page name
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1148 @type pagename: unicode
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1149 """
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1150 if not self._cfg.interwikiname:
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1151 return None
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
1152
88
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1153 return "%s:%s" % (self._cfg.interwikiname, pagename)
9f037347955c fixed quicklink bug when interwiki is None, create simpler addQuicklink and removeQuicklink methods, simplify isQuicklinkedTo method
Nir Soffer <nirs@freeshell.org>
parents: 34
diff changeset
1154
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1155 # -----------------------------------------------------------------
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1156 # Trail
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1157
3101
65322abb0a33 Fix trail for anon users without a session, do not show a single page. (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3069
diff changeset
1158 def _wantTrail(self):
4629
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1159 return (not self.valid and self._request.cfg.cookie_lifetime[0] # anon sessions enabled
3101
65322abb0a33 Fix trail for anon users without a session, do not show a single page. (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3069
diff changeset
1160 or self.valid and (self.show_page_trail or self.remember_last_visit)) # logged-in session
65322abb0a33 Fix trail for anon users without a session, do not show a single page. (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3069
diff changeset
1161
1956
477760dd8487 speedup addTrail by passing existing page object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
1162 def addTrail(self, page):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1163 """ Add page to trail.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
1164
1956
477760dd8487 speedup addTrail by passing existing page object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
1165 @param page: the page (object) to add to the trail
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1166 """
3101
65322abb0a33 Fix trail for anon users without a session, do not show a single page. (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3069
diff changeset
1167 if self._wantTrail():
1956
477760dd8487 speedup addTrail by passing existing page object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1951
diff changeset
1168 pagename = page.page_name
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1169 # Add only existing pages that the user may read
3101
65322abb0a33 Fix trail for anon users without a session, do not show a single page. (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3069
diff changeset
1170 if not (page.exists() and self._request.user.may.read(pagename)):
65322abb0a33 Fix trail for anon users without a session, do not show a single page. (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3069
diff changeset
1171 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1172
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1173 # Save interwiki links internally
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1174 if self._cfg.interwikiname:
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1175 pagename = self._interWikiName(pagename)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1176
4629
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1177 trail = self._request.session.get('trail', [])
5576
6b94d284ad11 avoid writing key/value to session dict if value doesn't change
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5538
diff changeset
1178 trail_current = trail[:]
4629
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1179
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1180 # Don't append tail to trail ;)
4629
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1181 if trail and trail[-1] == pagename:
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1182 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1183
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1184 # Append new page, limiting the length
4629
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1185 trail = [p for p in trail if p != pagename]
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1186 pagename_stripped = pagename.strip()
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1187 if pagename_stripped:
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1188 trail.append(pagename_stripped)
5576
6b94d284ad11 avoid writing key/value to session dict if value doesn't change
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5538
diff changeset
1189 trail = trail[-self._cfg.trail_size:]
6b94d284ad11 avoid writing key/value to session dict if value doesn't change
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5538
diff changeset
1190 if trail != trail_current:
6b94d284ad11 avoid writing key/value to session dict if value doesn't change
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5538
diff changeset
1191 # we only modify the session if we have something different:
6b94d284ad11 avoid writing key/value to session dict if value doesn't change
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5538
diff changeset
1192 self._request.session['trail'] = trail
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1193
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1194 def getTrail(self):
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1195 """ Return list of recently visited pages.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
1196
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1197 @rtype: list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1198 @return: pages in trail
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1199 """
4629
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1200 if self._wantTrail():
1935
740d9939ffe9 use session object to store page trail (even for anon users, if anon sessions are enabled)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1923
diff changeset
1201 trail = self._request.session.get('trail', [])
4629
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1202 else:
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1203 trail = []
554e1d780e3b fixed anon session detection, optimized trail code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4604
diff changeset
1204 return trail
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1205
89
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1206 # -----------------------------------------------------------------
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1207 # Other
4e44f6dfdfc2 user: formatting, move related methods together
Nir Soffer <nirs@freeshell.org>
parents: 88
diff changeset
1208
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1209 def isCurrentUser(self):
1963
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
1210 """ Check if this user object is the user doing the current request """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1211 return self._request.user.name == self.name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1212
448
45924beef130 user.isSuperUser() check, require cfg.superuser being a list or tuple
Thomas Waldmann <tw@waldmann-edv.de>
parents: 416
diff changeset
1213 def isSuperUser(self):
1963
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
1214 """ Check if this user is superuser """
4761
83390406fc5c Fix isSuperUser(). See below for details.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4629
diff changeset
1215 if not self.valid:
83390406fc5c Fix isSuperUser(). See below for details.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4629
diff changeset
1216 return False
1597
bbe187af4fc0 integrated MMDE (build scripts need more work)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
1217 request = self._request
4761
83390406fc5c Fix isSuperUser(). See below for details.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4629
diff changeset
1218 if request.cfg.DesktopEdition and request.remote_addr == '127.0.0.1':
1597
bbe187af4fc0 integrated MMDE (build scripts need more work)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
1219 # the DesktopEdition gives any local user superuser powers
bbe187af4fc0 integrated MMDE (build scripts need more work)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
1220 return True
bbe187af4fc0 integrated MMDE (build scripts need more work)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
1221 superusers = request.cfg.superuser
449
8ec16f62e989 Moved type check of the superuser setting.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 448
diff changeset
1222 assert isinstance(superusers, (list, tuple))
4761
83390406fc5c Fix isSuperUser(). See below for details.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4629
diff changeset
1223 return self.name and self.name in superusers
448
45924beef130 user.isSuperUser() check, require cfg.superuser being a list or tuple
Thomas Waldmann <tw@waldmann-edv.de>
parents: 416
diff changeset
1224
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1225 def host(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1226 """ Return user host """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1227 _ = self._request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1228 host = self.isCurrentUser() and self._cfg.show_hosts and self._request.remote_addr
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1229 return host or _("<unknown>")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1230
1154
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1231 def wikiHomeLink(self):
1963
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
1232 """ Return wiki markup usable as a link to the user homepage,
1154
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1233 it doesn't matter whether it already exists or not.
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1234 """
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1235 wikiname, pagename = wikiutil.getInterwikiHomePage(self._request, self.name)
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1236 if wikiname == 'Self':
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1237 if wikiutil.isStrictWikiname(self.name):
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1238 markup = pagename
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1239 else:
2726
6cb75379c073 change ["free link"] to [[free link]] in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2493
diff changeset
1240 markup = '[[%s]]' % pagename
1154
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1241 else:
2726
6cb75379c073 change ["free link"] to [[free link]] in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2493
diff changeset
1242 markup = '[[%s:%s]]' % (wikiname, pagename)
1154
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1243 return markup
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1244
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1245 def signature(self):
1154
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1246 """ Return user signature using wiki markup
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
1247
1154
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1248 Users sign with a link to their homepage.
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1249 Visitors return their host address.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
1250
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1251 TODO: The signature use wiki format only, for example, it will
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1252 not create a link when using rst format. It will also break if
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 89
diff changeset
1253 we change wiki syntax.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1254 """
1154
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1255 if self.name:
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1256 return self.wikiHomeLink()
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1075
diff changeset
1257 else:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1258 return self.host()
1005
e1e1885deec1 whitespace-only cleanup, fix regex by using raw string
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 826
diff changeset
1259
3567
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1260 def generate_recovery_token(self):
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1261 key = random_string(64, "abcdefghijklmnopqrstuvwxyz0123456789")
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1262 msg = str(int(time.time()))
6103
500f68d3e2fd remove our own usage of python_compatibility module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6043
diff changeset
1263 h = hmac.new(key, msg).hexdigest()
3567
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1264 self.recoverpass_key = key
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1265 self.save()
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1266 return msg + '-' + h
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1267
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1268 def apply_recovery_token(self, tok, newpass):
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1269 parts = tok.split('-')
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1270 if len(parts) != 2:
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1271 return False
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1272 try:
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1273 stamp = int(parts[0])
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1274 except ValueError:
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1275 return False
5985
0063e98b14aa cfg.recovery_token_lifetime to determine how long the recovery token will be valid
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5971
diff changeset
1276 lifetime = self._request.cfg.recovery_token_lifetime * 3600
0063e98b14aa cfg.recovery_token_lifetime to determine how long the recovery token will be valid
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5971
diff changeset
1277 if time.time() > stamp + lifetime:
3567
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1278 return False
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1279 # check hmac
4491
eb377776ca34 user.apply_recovery_token: key must be of type string
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4481
diff changeset
1280 # key must be of type string
6103
500f68d3e2fd remove our own usage of python_compatibility module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6043
diff changeset
1281 h = hmac.new(str(self.recoverpass_key), str(stamp)).hexdigest()
5902
840ebd16ddd9 use a constant time str comparison function to prevent timing attacks
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5772
diff changeset
1282 if not safe_str_equal(h, parts[1]):
3567
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1283 return False
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1284 self.recoverpass_key = ""
5922
25900eaeb864 passlib integration - enhanced password hash security
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5918
diff changeset
1285 self.enc_password = encodePassword(self._cfg, newpass)
3567
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1286 self.save()
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1287 return True
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1288
5936
2d3352c547bc moin account resetpw - misc. improvements
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5930
diff changeset
1289 def mailAccountData(self, cleartext_passwd=None,
2d3352c547bc moin account resetpw - misc. improvements
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5930
diff changeset
1290 subject=None,
2d3352c547bc moin account resetpw - misc. improvements
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5930
diff changeset
1291 text_intro=None, text_msg=None, text_data=None):
1963
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
1292 """ Mail a user who forgot his password a message enabling
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
1293 him to login again.
de42f84ddb3c user: add some docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1957
diff changeset
1294 """
750
f158c4e8fea2 moved mail related functions to MoinMoin.mail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 737
diff changeset
1295 from MoinMoin.mail import sendmail
138
81654a482b3a Added createonly parameter to UserPreferences macro and userform action; moved mailAccountData to the user object; extended SystemAdmin to offer 'send acount data' links; fixed minor quoting problem in Page.link_to()
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 121
diff changeset
1296 _ = self._request.getText
81654a482b3a Added createonly parameter to UserPreferences macro and userform action; moved mailAccountData to the user object; extended SystemAdmin to offer 'send acount data' links; fixed minor quoting problem in Page.link_to()
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 121
diff changeset
1297
5929
8d03f3ec97a7 don't try to send email to user if email address in profile is empty
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5922
diff changeset
1298 if not self.email:
8d03f3ec97a7 don't try to send email to user if email address in profile is empty
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5922
diff changeset
1299 return False, "user has no E-Mail address in his profile."
8d03f3ec97a7 don't try to send email to user if email address in profile is empty
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5922
diff changeset
1300
3567
ddf31f2ae8e3 use hmac and make recoverpass token only valid for 12 hours
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3564
diff changeset
1301 tok = self.generate_recovery_token()
416
fb5e1ecdbc33 generate rnd password when there is none yet
Thomas Waldmann <tw@waldmann-edv.de>
parents: 339
diff changeset
1302
5936
2d3352c547bc moin account resetpw - misc. improvements
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5930
diff changeset
1303 if subject is None:
2d3352c547bc moin account resetpw - misc. improvements
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: