# HG changeset patch
# User Timothy Clemans <timothy.clemans@gmail.com>
# Date 1218575416 25200
# Node ID 3c0bd2f627942c2ff20ed4f0c3570e68566d579a
# Parent a070453197e497471745f4cae0ca64fb9e681707
#3619 View login times
diff -r a070453197e4 -r 3c0bd2f62794 sage/server/notebook/avatars.py
|
a
|
b
|
|
| 61 | 61 | return defer.succeed(FailedLogin(username, failure_type = 'user')) |
| 62 | 62 | |
| 63 | 63 | if U.password_is(password): |
| | 64 | if twist.notebook.conf()['record_logins']: |
| | 65 | U.record_login() |
| 64 | 66 | return defer.succeed(username) |
| 65 | 67 | else: |
| 66 | 68 | return defer.succeed(FailedLogin(username,failure_type='password')) |
diff -r a070453197e4 -r 3c0bd2f62794 sage/server/notebook/server_conf.py
|
a
|
b
|
|
| 15 | 15 | 'save_interval':360, # seconds |
| 16 | 16 | |
| 17 | 17 | 'doc_pool_size':128, |
| 18 | | 'email':False |
| | 18 | 'email':False, |
| | 19 | 'record_logins':False |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | 22 | class ServerConfiguration(conf.Configuration): |
diff -r a070453197e4 -r 3c0bd2f62794 sage/server/notebook/twist.py
|
a
|
b
|
|
| 2065 | 2065 | self.username = username |
| 2066 | 2066 | |
| 2067 | 2067 | def render(self, ctx): |
| 2068 | | if user_type(self.username) != 'admin': |
| 2069 | | s = message('You must an admin to manage other users.') |
| | 2068 | if 'logins' in ctx.args: |
| | 2069 | s = '<br/>'.join(map(str, notebook.user(ctx.args['logins'][0]).login_times())) |
| 2070 | 2070 | else: |
| 2071 | | s = """ |
| 2072 | | <html><head><title>Users | Sage Notebook</title></head> |
| 2073 | | <body> |
| 2074 | | %s |
| 2075 | | </body></html> |
| 2076 | | """ % '<br/>'.join(['<a href="/home/%s/">%s</a>' % (i, i) for i in notebook.valid_login_names()]) |
| | 2071 | if user_type(self.username) != 'admin': |
| | 2072 | s = message('You must an admin to manage other users.') |
| | 2073 | else: |
| | 2074 | logins_th = '<th>Login times</th>' if notebook.conf()['record_logins'] else '' |
| | 2075 | if notebook.conf()['record_logins']: |
| | 2076 | rows = '<br/>'.join(['<tr><td>%s</td><td><a href="/home/%s/">Access</a></td><td><a href="?logins=%s">Access</a></td></tr>' % (i, i, i) for i in notebook.valid_login_names()]) |
| | 2077 | else: |
| | 2078 | rows = '<br/>'.join(['<tr><td>%s</td><td><a href="/home/%s/">Access</a></td></tr>' % (i, i) for i in notebook.valid_login_names()]) |
| | 2079 | s = """ |
| | 2080 | <html><head><title>User Management | Sage Notebook</title> |
| | 2081 | <style> |
| | 2082 | table {border-collapse:collapse} |
| | 2083 | th, td {border:1px solid #000; padding:5px} |
| | 2084 | </style> |
| | 2085 | </head> |
| | 2086 | <body> |
| | 2087 | <table> |
| | 2088 | <tr><th>Users</th><th>Worksheets</th>%s</tr> |
| | 2089 | %s |
| | 2090 | </table> |
| | 2091 | </body></html> |
| | 2092 | """ % (logins_th, rows) |
| 2077 | 2093 | return http.Response(stream = s) |
| 2078 | 2094 | |
| 2079 | 2095 | class InvalidPage(resource.Resource): |
diff -r a070453197e4 -r 3c0bd2f62794 sage/server/notebook/user.py
|
a
|
b
|
|
| 21 | 21 | raise ValueError, "account type must be one of admin, user, or guest" |
| 22 | 22 | self.__account_type = account_type |
| 23 | 23 | self.__conf = user_conf.UserConfiguration() |
| | 24 | self.__login_times = None |
| 24 | 25 | |
| 25 | 26 | def __getstate__(self): |
| 26 | 27 | d = copy.copy(self.__dict__) |
| … |
… |
|
| 242 | 243 | False |
| 243 | 244 | """ |
| 244 | 245 | return self.__account_type == 'guest' |
| | 246 | |
| | 247 | def record_login(self): |
| | 248 | """ |
| | 249 | """ |
| | 250 | import datetime |
| | 251 | try: |
| | 252 | self.__login_times.append(datetime.today()) |
| | 253 | except AttributeError: |
| | 254 | self.__login_times = [datetime.datetime.today()] |
| | 255 | |
| | 256 | def login_times(self): |
| | 257 | """ |
| | 258 | """ |
| | 259 | try: |
| | 260 | return self.__login_times |
| | 261 | except AttributeError: |
| | 262 | self.__login_times = [] |
| | 263 | return [] |