def GET(self): # Reads the token in the HTTP request parameters token = web.input(token=None).token # Checks if the token is valid user_token = UserToken.get_token(token) if user_token is None or user_token.expired: raise http.Forbidden() # The fieldset is not bound to any specific instance : the token is passed because it contains the email user_fieldset = user_forms.NewUserFieldSet(user_token) return config.views.layout(config.views.creation_form(user_fieldset))
def test_get_token(self): # These tests work because a UserTokenData has a similar structure to a UserToken # When Tournament.__eq__ is called, it compares the fields without caring of the parameters' actual types self.assertIsNone(UserToken.get_token(None)) self.assertIsNone(UserToken.get_token("")) self.assertIsNone(UserToken.get_token("invalid_token")) self.assertIsNone(UserToken.get_token("goB9Z7fhsUrjXHDi")) self.assertIsNone(UserToken.get_token("xYCPayfPCPEPCPaL")) self.assertEquals(UserToken.get_token("znc9TNqpajeN2nEH"), UserTokenData.user_token_expired) self.assertEquals(UserToken.get_token("xjRp67wh3HdjEI6I"), UserTokenData.user_token_active)
def POST(self): # Reads the token in the HTTP request parameters token = web.input(token=None).token # Checks if the token is valid user_token = UserToken.get_token(token) if user_token is None or user_token.expired: raise http.Forbidden() # The fieldset is bound to the form data & the session : the token is passed because it contains the level user_fieldset = user_forms.NewUserFieldSet(user_token).bind(data=web.input(), session=config.orm) # Synchronizes the fieldset & registers a delayed login of the user (because the user id is not available yet) if user_fieldset.validate(): user_fieldset.sync() http.register_hook(lambda: session.login_workflow(user_fieldset.model)) raise web.seeother("/") else: return config.views.layout(config.views.creation_form(user_fieldset))
def POST(self): # Reads the token in the HTTP request parameters token = web.input(token=None).token # Checks if the token is valid user_token = UserToken.get_token(token) if user_token is None or user_token.expired: raise http.Forbidden() # The fieldset is bound to the form data & the session : the token is passed because it contains the level user_fieldset = user_forms.NewUserFieldSet(user_token).bind( data=web.input(), session=config.orm) # Synchronizes the fieldset & registers a delayed login of the user (because the user id is not available yet) if user_fieldset.validate(): user_fieldset.sync() http.register_hook( lambda: session.login_workflow(user_fieldset.model)) raise web.seeother("/") else: return config.views.layout( config.views.creation_form(user_fieldset))