Ticket #3619: sage-3619.patch

File sage-3619.patch, 4.5 KB (added by TimothyClemans, 19 months ago)

Depends on #3776

  • sage/server/notebook/avatars.py

    # 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  
    6161            return defer.succeed(FailedLogin(username, failure_type = 'user')) 
    6262 
    6363        if U.password_is(password): 
     64            if twist.notebook.conf()['record_logins']: 
     65                U.record_login()  
    6466            return defer.succeed(username) 
    6567        else: 
    6668            return defer.succeed(FailedLogin(username,failure_type='password')) 
  • sage/server/notebook/server_conf.py

    diff -r a070453197e4 -r 3c0bd2f62794 sage/server/notebook/server_conf.py
    a b  
    1515            'save_interval':360,        # seconds 
    1616 
    1717            'doc_pool_size':128, 
    18             'email':False  
     18            'email':False, 
     19            'record_logins':False 
    1920           } 
    2021 
    2122class ServerConfiguration(conf.Configuration): 
  • sage/server/notebook/twist.py

    diff -r a070453197e4 -r 3c0bd2f62794 sage/server/notebook/twist.py
    a b  
    20652065            self.username = username 
    20662066             
    20672067        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())) 
    20702070            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) 
    20772093            return http.Response(stream = s) 
    20782094 
    20792095class InvalidPage(resource.Resource): 
  • sage/server/notebook/user.py

    diff -r a070453197e4 -r 3c0bd2f62794 sage/server/notebook/user.py
    a b  
    2121            raise ValueError, "account type must be one of admin, user, or guest" 
    2222        self.__account_type = account_type 
    2323        self.__conf = user_conf.UserConfiguration() 
     24        self.__login_times = None  
    2425 
    2526    def __getstate__(self): 
    2627        d = copy.copy(self.__dict__) 
     
    242243            False 
    243244        """ 
    244245        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 []