Ticket #2926: 2926.patch

File 2926.patch, 3.7 KB (added by TimothyClemans, 13 years ago)
  • sage/server/notebook/notebook.py

    # HG changeset patch
    # User Timothy Clemans <timothy.clemans@gmail.com>
    # Date 1208283304 25200
    # Node ID 0bcaa94be437e884f0d598b396331757f797083c
    # Parent  631bb7b11fe9e45f70f43be6da034543d5f790e0
    Add change password functionality
    
    diff -r 631bb7b11fe9 -r 0bcaa94be437 sage/server/notebook/notebook.py
    a b class Notebook(SageObject): 
    10071007        if not pub:
    10081008            entries.insert(2, ('history_window()', 'Log', 'View a log of recent computations'))
    10091009        if not self.user_is_guest(user):
     1010            entries.append(('/passwd', 'Change password', 'Change account password'))
    10101011            entries.append(('/logout', 'Sign out', 'Log out of the Sage notebook'))
    10111012
    10121013        s += self.html_banner_and_control(user, entries)           
  • sage/server/notebook/twist.py

    diff -r 631bb7b11fe9 -r 0bcaa94be437 sage/server/notebook/twist.py
    a b class NotebookSettings(resource.Resource 
    844844            s = notebook.html_notebook_settings()
    845845        return http.Response(stream = s)
    846846
     847class ChangePasswordPage(resource.PostableResource):
     848    def __init__(self, username):
     849        self.username = username
     850       
     851    def render(self, request):
     852        error = None
     853        if 'Oldpass' in request.args or 'Newpass' in request.args or 'RetypePass' in request.args:
     854            if not 'Oldpass' in request.args:
     855                error = 'Old password not given'
     856            elif not notebook.user(self.username).password_is(request.args['Oldpass'][0]):
     857                error = 'Incorrect password given'
     858            elif not 'Newpass' in request.args:
     859                error = 'New password not given'
     860            elif not 'RetypePass' in request.args:
     861                error = 'Please type in new password again.'
     862            elif request.args['Newpass'][0] != request.args['RetypePass'][0]:
     863                error = 'The passwords you entered do not match.'
     864           
     865            if error:
     866                return http.Response(stream=message(error, '/passwd'))
     867               
     868            notebook.change_password(self.username, request.args['Newpass'][0])
     869            return http.RedirectResponse('/logout')
     870        else:
     871            s = """<html><h1 align=center>Change Password.</h1>
     872            <br>
     873            <hr>
     874            <br>
     875            <form method="POST" action="/passwd">
     876            <br><br>
     877            <table align=center><tr>
     878            <td align=right>Old password:</td><td><input type="password" name="Oldpass" size="15" /></td></tr>
     879            <tr><td align=right>New password:</td><td>
     880                <input type="password" name="Newpass" size="15" />
     881                </td></tr>
     882            <tr><td align=right>Retype new password:</td><td>
     883                <input type="password" name="RetypePass" size="15" />
     884                </td></tr>
     885          <tr><td></td><td></td></tr>
     886            <tr><td></td><td align=left><input type="submit" value="Change password" /></td></tr>
     887            </table> </form>
     888            <br><br>
     889            <div align=center><a href="../">Cancel</a></div>
     890            <br>
     891           
     892            </html>"""
     893        return http.Response(stream=s)
    847894
    848895########################################################
    849896# Set output type of a cell
    class UserToplevel(Toplevel): 
    18181865    userchild_live_history = LiveHistory
    18191866    userchild_new_worksheet = NewWorksheet
    18201867    userchild_notebook_settings = NotebookSettings
     1868    userchild_passwd = ChangePasswordPage
    18211869    userchild_pub = PublicWorksheets
    18221870
    18231871    userchild_send_to_trash = SendWorksheetToTrash