Commits

KS Chan committed ea0c319

Introduced GET/POST for user registration

Comments (0)

Files changed (1)

src/pythonhk/controllers.py

 from pythonhk import api
 
 
+class UserController(object):
+
+    def get_register(self):
+        template = pythonhk.template_loader .get_template("register.html")
+        return template.render()
+
+    def post_register(self, display_name=None, email=None, password=None,
+                      password_again=None):
+        if not display_name:
+            raise cherrypy.HTTPError(400, "Field: Display name is required.")
+
+        if not email:
+            raise cherrypy.HTTPError(400, "Field: Email is required.")
+
+        if not password:
+            raise cherrypy.HTTPError(400, "Field: Password is required.")
+
+        if not password_again:
+            raise cherrypy.HTTPError(400, "Field: Password again is required.")
+
+
+user_routes = cherrypy.dispatch.RoutesDispatcher()
+user_routes.mapper.explicit = False
+
+user_routes.connect("register", "/register", UserController,
+                    action="get_register", conditions={"method":["GET"]})
+user_routes.connect("register", "/register", UserController,
+                    action="post_register", conditions={"method":["POST"]})
+
+
 class Root(object):
 
     @cherrypy.expose
     def index(self):
         template = pythonhk.template_loader.get_template("index.html")
         return template.render()
+
+    user = UserController()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.