| 847 | class 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) |