4 usage: %(progname)s [args] 8 import os, sys, string, time, getopt
15 from pyclearsilver
import odb, hdfhelp, odb_sqlite3
16 from pyclearsilver
import CSPage
24 gDBTablePrefix =
"auth" 28 odb.Database.__init__(self, db, debug=debug)
30 self.addTable(
"users", gDBTablePrefix +
"_users", UserTable,
32 self.addTable(
"login", gDBTablePrefix +
"_login", UserLoginTable)
33 self.addTable(
"vcode", gDBTablePrefix +
"_vcode", VCodeTable)
34 self.addTable(
"browserid", gDBTablePrefix +
"_browserid", BrowserTable)
39 return hdfhelp.HdfItemList
43 rows = self.users.fetchAllRows()
45 users.append(row.username)
54 self.d_addColumn(
"uid",kInteger,
None,primarykey = 1,
57 self.d_addColumn(
"username",kVarString, indexed=1, unique=1)
58 self.d_addColumn(
"role", kVarString, default=
"")
59 self.d_addColumn(
"pw_hash",kVarString)
60 self.d_addColumn(
"status",kInteger, default=0)
62 self.d_addColumn(
"creationDate", kInteger, default=0)
63 self.d_addColumn(
"dismissed_notices", kVarString, default=
"")
64 self.d_addColumn(
"favorite_apps", kVarString, default=
"")
65 self.d_addColumn(
"changePassword",kInteger, default=0)
66 self.d_addColumn(
"skype_id", kVarString, default=
"")
70 row = self.fetchRow((
'username', username))
71 except odb.eNoMatchingRows, reason:
75 def new(self, username, password):
76 row = self.
lookup(username)
77 if row
is not None:
return row
80 row.username = username
81 row.creationDate = int(time.time())
82 row.setPassword(password)
89 if len(self.
pw_hash) < 2:
return 0
90 if passwordHash == self.
pw_hash:
return 1
95 if len(self.
pw_hash) < 2:
return 0
97 return pwauth.checkPassword(password, self.
pw_hash)
100 self.
pw_hash = pwauth.cryptPassword(new_password)
105 return self.favorite_apps.split(
',')
if len(self.
favorite_apps) > 0
else []
108 return self.favorite_apps.find(app_taskid) != -1
112 if not app_taskid
in apps:
113 apps.append(app_taskid)
120 if app_taskid
in apps:
121 apps.remove(app_taskid)
127 return self.dismissed_notices.split(
',')
if len(self.
dismissed_notices) > 0
else []
130 return self.dismissed_notices.find(notice) != -1
134 if not notice
in notices:
135 notices.append(notice)
147 if not config.gLobby:
return 150 url = config.gLobby +
"/lobby/lobby/userrec.py" 152 postdata[
'username'] = self.username
154 postdata[
'skype_id'] = self.
skype_id 158 fp = urllib.urlopen(url, urllib.urlencode(postdata.items()))
165 self.d_addColumn(
"uid",kInteger, primarykey=1)
166 self.d_addColumn(
"username",kVarString, indexed=1, primarykey=1)
167 self.d_addColumn(
"time", kCreatedStampMS, primarykey=1)
169 self.d_addColumn(
"loginType", kInteger)
173 self.d_addColumn(
"browserid",kVarString)
174 self.d_addColumn(
"ipaddr",kVarString)
179 self.d_addColumn(
"username",kVarString, primarykey=1)
180 self.d_addColumn(
"vcode",kInteger, default=0)
181 self.d_addColumn(
"browserid",kInteger, default=0)
182 self.d_addColumn(
"creationDate", kInteger, default=0)
187 self.d_addColumn(
"browserid",kInteger, primarykey=1, autoincrement=1)
188 self.d_addColumn(
"ipaddr", kVarString)
189 self.d_addColumn(
"creationDate", kInteger, default=0)
194 return os.path.join(path_to_store, gDBFilename +
".db3")
197 if timeout
is None: timeout = 600
199 path = config.getSiteDBPath(gDBSubPath)
202 config.createDBPath(path)
204 conn = odb_sqlite3.Connection(
fullDBPath(path),
207 db =
AuthDB(conn,debug=debug)
211 db.synchronizeSchema()
215 if config.gWebUserID
is not None and config.gWebGroupID
is not None:
221 path = config.getSiteDBPath(gDBSubPath)
223 if os.path.exists(fn):
236 rows = db.users.fetchAllRows()
238 print row.username, row.pw_hash
243 print __doc__ % vars()
245 def main(argv, stdout, environ):
247 optlist, args = getopt.getopt(argv[1:],
"", [
"help",
"test",
"debug"])
250 for (field, val)
in optlist:
251 if field ==
"--help":
254 elif field ==
"--debug":
256 elif field ==
"--test":
267 if __name__ ==
"__main__":
268 main(sys.argv, sys.stdout, os.environ)
def dismiss_notice(self, notice)
def main(argv, stdout, environ)
def setPassword(self, new_password)
def sync_with_lobby(self)
def dismissed_notice_list(self)
def favorite_apps_list(self)
def checkPasswordHash(self, passwordHash)
def fullDBPath(path_to_store)
def add_favorite_app(self, app_taskid)
def remove_favorite_app(self, app_taskid)
def defaultRowListClass(self)
def set_skype_id(self, id)
def notice_dismissed(self, notice)
def new(self, username, password)
def checkPassword(self, password)
def lookup(self, username)
def initSchema(create=0, timeout=None)
def __init__(self, db, debug=0)
def is_favorite_app(self, app_taskid)
def defaultRowClass(self)