forked from japsu/phpbb-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
67 lines (56 loc) · 1.89 KB
/
sql.py
File metadata and controls
67 lines (56 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# encoding: utf-8
# vim: shiftwidth=4 expandtab
#
# phpbb-python © Copyright 2010 Santtu Pajukanta
# http://pajukanta.fi
#
# phpBB3 © Copyright 2000, 2002, 2005, 2007 phpBB Group
# http://www.phpbb.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
#
DEFAULT_PARAM_STYLE = '%s'
DEFAULT_USERS_TABLE = 'phpbb_users'
USER_ROW_FIELDS = [
'user_id',
'username',
'user_password',
'user_passchg',
'user_pass_convert',
'user_email',
'user_type',
'user_login_attempts'
]
GET_USER_ROW_SQL = 'SELECT %s FROM %s WHERE username_clean = %s'
class GetUserRow(object):
def __init__(self, *args, **kwargs):
self.conn = None
self.sql = None
if args or kwargs:
self.setup(*args, **kwargs)
def setup(self, conn, param_style=DEFAULT_PARAM_STYLE, users_table=DEFAULT_USERS_TABLE):
self.conn = conn
self.sql = GET_USER_ROW_SQL % (", ".join(USER_ROW_FIELDS), users_table, param_style)
def is_setup(self):
return self.conn is not None
def __call__(self, username_clean):
c = self.conn.cursor()
c.execute(self.sql, [username_clean,])
user_row = c.fetchone()
if user_row:
return dict(zip(USER_ROW_FIELDS, user_row))
else:
return None
get_user_row = GetUserRow()
setup = get_user_row.setup
is_setup = get_user_row.is_setup