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