Browse Source

Add basic account deletion

Make URLs more hierarchical
Closes #18
master
Chris Smith 14 years ago
parent
commit
acd5968027
2 changed files with 34 additions and 5 deletions
  1. 23
    2
      src/helloworld.py
  2. 11
    3
      src/index.html

+ 23
- 2
src/helloworld.py View File

1
+import logging
1
 import os
2
 import os
2
 from Scraper import Scraper
3
 from Scraper import Scraper
3
 from google.appengine.ext.webapp import template
4
 from google.appengine.ext.webapp import template
78
 
79
 
79
         self.redirect('/')
80
         self.redirect('/')
80
 
81
 
82
+class DeleteAccountPage(webapp.RequestHandler):
83
+    def post(self):
84
+
85
+        if not users.get_current_user():
86
+            self.error(403)
87
+            return
88
+
89
+        account = db.get(db.Key(self.request.get('key')))
90
+
91
+        if account.user != users.get_current_user() and not users.is_current_user_admin():
92
+            logging.warning("Account deletion attempted by :u1 for account owned by :u2",
93
+                            u1 = users.get_current_user(), u2 = account.user)
94
+            self.error(403)
95
+            return
96
+
97
+        account.delete()
98
+
99
+        self.redirect('/')
100
+
81
 
101
 
82
 class UpdatePage(webapp.RequestHandler):
102
 class UpdatePage(webapp.RequestHandler):
83
 
103
 
157
         return res
177
         return res
158
 
178
 
159
 application = webapp.WSGIApplication([('/', MainPage),
179
 application = webapp.WSGIApplication([('/', MainPage),
160
-                                      ('/admin/addsource', AddSourcePage),
180
+                                      ('/admin/source/add', AddSourcePage),
161
                                       ('/worker/update', UpdatePage),
181
                                       ('/worker/update', UpdatePage),
162
-                                      ('/addaccount', AddAccountPage)],
182
+                                      ('/account/add', AddAccountPage),
183
+                                      ('/account/delete', DeleteAccountPage)],
163
                                      debug=True)
184
                                      debug=True)
164
 
185
 
165
 def main():
186
 def main():

+ 11
- 3
src/index.html View File

50
                 right: 2px;
50
                 right: 2px;
51
                 font-size: small;
51
                 font-size: small;
52
             }
52
             }
53
+
54
+            td.actions form {
55
+                display: inline;
56
+            }
53
         </style>
57
         </style>
54
     </head>
58
     </head>
55
     <body>
59
     <body>
58
             <div class="admin">
62
             <div class="admin">
59
                 <h1>Admin</h1>
63
                 <h1>Admin</h1>
60
                 <h2>Add Source</h2>
64
                 <h2>Add Source</h2>
61
-                <form action="/admin/addsource" method="post">
65
+                <form action="/admin/source/add" method="post">
62
                     <label>Name: <input type="text" name="name"/></label>
66
                     <label>Name: <input type="text" name="name"/></label>
63
                     <label>URL: <input type="text" name="url"/></label>
67
                     <label>URL: <input type="text" name="url"/></label>
64
                     <input type="submit" value="Add"/>
68
                     <input type="submit" value="Add"/>
76
                 <tr>
80
                 <tr>
77
                     <td>{{ account.source.name|escape }}</td>
81
                     <td>{{ account.source.name|escape }}</td>
78
                     <td>{{ account.credentials|escape }}</td>
82
                     <td>{{ account.credentials|escape }}</td>
79
-                    <td>
83
+                    <td class="actions">
80
                         <form action="/worker/update" method="post">
84
                         <form action="/worker/update" method="post">
81
                             <input type="hidden" name="key" value="{{ account.key|escape }}"/>
85
                             <input type="hidden" name="key" value="{{ account.key|escape }}"/>
82
                             <input type="submit" value="Update now"/>
86
                             <input type="submit" value="Update now"/>
83
                         </form>
87
                         </form>
88
+                        <form action="/account/delete" method="post">
89
+                            <input type="hidden" name="key" value="{{ account.key|escape }}"/>
90
+                            <input type="submit" value="Delete"/>
91
+                        </form>
84
                     </td>
92
                     </td>
85
                 </tr>
93
                 </tr>
86
                 {% endfor %}
94
                 {% endfor %}
87
             </table>
95
             </table>
88
 
96
 
89
             <h2>Add account</h2>
97
             <h2>Add account</h2>
90
-            <form action="/addaccount" method="post">
98
+            <form action="/account/add" method="post">
91
                 <label>Type:
99
                 <label>Type:
92
                    <select name="type">
100
                    <select name="type">
93
                         {% for source in sources %}
101
                         {% for source in sources %}

Loading…
Cancel
Save