/[theodore]/bunnyblog/modules/logintools/loginutils.py


UCC Code Repository

Contents of /bunnyblog/modules/logintools/loginutils.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Tue Jan 29 14:32:01 2008 UTC (12 years ago) by svn-admin
File MIME type: text/x-python
File size: 2932 byte(s)
Re-import of repository after repository database corruption.

1 # loginutils.py
2 # part of logintools
3 # A CGI Authentication and user account system
4 # Copyright (C) 2004/2005 Michael Foord
5 # E-mail: fuzzyman AT voidspace DOT org DOT uk
6
7 # Released subject to the BSD License
8 # Please see http://www.voidspace.org.uk/documents/BSD-LICENSE.txt
9
10 # Scripts maintained at http://www.voidspace.org.uk/python/index.shtml
11 # Comments, suggestions and bug reports welcome.
12
13 # For information about bugfixes, updates and support, please join the Pythonutils mailing list.
14 # http://voidspace.org.uk/mailman/listinfo/pythonutils_voidspace.org.uk
15 # Comments, suggestions and bug reports welcome.
16
17 import sys
18 import os
19 sys.path.append('../modules')
20 from cgiutils import *
21
22 actionline = '<input type="hidden" name="action" value="%s" />'
23 # a list of reserved names for users
24 RESERVEDNAMES = ['config', 'default', 'temp', 'emails', 'pending']
25
26 # Helper functions for the login scripts and tools
27
28 def makecookie(userconfig, password, cookiepath):
29 """
30 Return the current valid cookie heaader for the values supplied in the
31 userconfig, the straight password and the cookiepath.
32 """
33 from login import encodestring
34 from Cookie import SimpleCookie
35 thecookie = SimpleCookie()
36 cookiestring = encodestring(userconfig['username'],password)
37 maxage = userconfig['max-age']
38 thecookie['userid'] = cookiestring
39 if maxage and int(maxage): # possible cause of error here if the maxage value in a users file isn't an integer !!
40 thecookie['userid']['max-age'] = int(maxage)
41 if cookiepath:
42 thecookie['userid']['path'] = cookiepath
43 return thecookie.output() # XXXX may need to be able to return the cookie object
44
45 def emptycookie(cookiepath=None):
46 """Return an empty cookie with max-age 0.
47 Used for logout features.
48 """
49 from Cookie import SimpleCookie
50 thecookie = SimpleCookie()
51 thecookie['userid'] = ''
52 thecookie['userid']['max-age'] = 0
53 if cookiepath:
54 thecookie['userid']['path'] = cookiepath
55 return thecookie.output() # XXXX may need to be able to return the cookie object
56
57 def sortaction(action):
58 return action or 'EMPTY_VAL_MJF'
59
60 def createuser(userdir, realname, username, email, password, adminlev):
61 """Create a new user."""
62 from time import time
63 from dataenc import pass_enc
64 from configobj import ConfigObj
65
66 user = ConfigObj(userdir+'default.ini')
67 user.filename = userdir + username + '.ini' # XXXX this does no checkign htat the name is valid and doesn't already exist !!
68 user['username'] = username
69 user['realname'] = realname
70 user['email'] = email
71 user['admin'] = adminlev
72 user['password'] = pass_enc(password, timestamp=True, daynumber=True)
73 user['created'] = str(time())
74 user.write()
75
76 """
77 CHANGELOG
78 =========
79
80 2005/09/09
81 ----------
82
83 Changes to work with pythonutils 0.2.1
84
85 """

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26