def POST(self): # Reads the email in the HTTP request parameters email = web.input(email=None).email # Check if the user exists and is active user = User.get_user(email) if user is None or not user.active: raise http.Forbidden("Utilisateur inconnu") # Checks if there is already an active password token matching this email current_password_token = PasswordToken.get_password_token(email) if current_password_token is not None: formatted_creation_dt = formatting.format_date(dates.change_timezone(current_password_token.creation_dt), "%d/%m/%y %H:%M") raise http.Forbidden(u"Demande similaire déjà effectuée le %s" % formatted_creation_dt) # Creates a new password token valid for 2 days password_token = PasswordToken(validity=2, user=user, token=PasswordToken.generate_random_token(16)) config.orm.add(password_token) # Registers an email notification http.register_hook(lambda: notify_via_email(password_token, Events.NEW)) return u"Instructions en cours d'envoi à %s" % email
def POST(self): # Reads the email in the HTTP request parameters email = web.input(email=None).email # Check if the user exists and is active user = User.get_user(email) if user is None or not user.active: raise http.Forbidden("Utilisateur inconnu") # Checks if there is already an active password token matching this email current_password_token = PasswordToken.get_password_token(email) if current_password_token is not None: formatted_creation_dt = formatting.format_date( dates.change_timezone(current_password_token.creation_dt), "%d/%m/%y %H:%M") raise http.Forbidden(u"Demande similaire déjà effectuée le %s" % formatted_creation_dt) # Creates a new password token valid for 2 days password_token = PasswordToken( validity=2, user=user, token=PasswordToken.generate_random_token(16)) config.orm.add(password_token) # Registers an email notification http.register_hook( lambda: notify_via_email(password_token, Events.NEW)) return u"Instructions en cours d'envoi à %s" % email
def POST(self, key): if not key in ADMIN_COMPONENTS: raise web.notfound() http_input = web.input() # Scenario 1 : edit an existing element if http_input.event == Events.MODIFIED: # The grid should be bound to the form data component_to_sync = grid = ADMIN_COMPONENTS.get(key).grid_component() grid.rebind(data=http_input) fieldset = ADMIN_COMPONENTS.get(key).fieldset_component() # Scenario 2 : create a new element elif http_input.event == Events.NEW: # The fieldset should be bound to the form data & the session grid = ADMIN_COMPONENTS.get(key).grid_component() component_to_sync = fieldset = ADMIN_COMPONENTS.get(key).fieldset_component().bind(data=http_input, session=config.orm) # Scenario 3 : invalid action else: raise web.notfound() # Synchronizes the grid or the fieldset (depending on the action) & registers an email notification if component_to_sync.validate(): component_to_sync.sync() http.register_hook(lambda: notify_via_email(component_to_sync.model, http_input.event)) raise web.seeother("/") else: return config.views.layout(config.views.administration(grid, fieldset))
def POST(self): # Reads the HTTP request parameters http_input = web.input(poll_id=None, poll_user_choices=[]) poll_id = http_input.poll_id poll_user_choices = http_input.poll_user_choices # Loads the poll if poll_id is None: raise web.notfound() poll = Poll.get(int(poll_id), joined_attrs=["choices", "votes_by_user"]) if poll is None: raise web.notfound() # Passes the user's choices to the model try: # Parses the choice numbers & makes sure they're valid poll_user_choices = map(int, poll_user_choices) if any(i not in range(len(poll.choices)) for i in poll_user_choices): raise ValueError( u"Un des entiers passes a la methode /poll/vote n'est pas compris dans l'intervalle %s" % range(len(poll.choices))) # Determines if it's the first vote ever in the poll someone_already_voted = poll.has_votes # Determines if it's the first vote for the user user_already_voted = config.session_manager.user in poll.choices_by_user # Actual vote action for the user poll_vote = poll.vote(config.session_manager.user, [poll.choices[i] for i in poll_user_choices]) # Registers an email notification http.register_hook(lambda: notify_via_email( poll_vote, Events.MODIFIED if user_already_voted else Events.NEW)) return dict(data=config.views.poll_votes( poll, highlight_user=config.session_manager.user if someone_already_voted else None), partial=someone_already_voted) except ValueError as exception: raise http.Forbidden(exception)
def POST(self): # Reads the HTTP request parameters tournament_id = web.input().tournament_id comment = web.input().comment # Appends the comment # TODO: variables are ambiguous tournament = Tournament.get(int(tournament_id), joined_attrs=["comments"]) added_comment = tournament.add_comment(config.session_manager.user, comment) # Registers an email notification http.register_hook(lambda: notify_via_email(added_comment, Events.NEW)) # Returns the dictionary return config.views.comment(added_comment)
def POST(self): # Reads the HTTP request parameters http_input = web.input(poll_id=None, poll_user_choices=[]) poll_id = http_input.poll_id poll_user_choices = http_input.poll_user_choices # Loads the poll if poll_id is None: raise web.notfound() poll = Poll.get(int(poll_id), joined_attrs=["choices", "votes_by_user"]) if poll is None: raise web.notfound() # Passes the user's choices to the model try: # Parses the choice numbers & makes sure they're valid poll_user_choices = map(int, poll_user_choices) if any(i not in range(len(poll.choices)) for i in poll_user_choices): raise ValueError(u"Un des entiers passes a la methode /poll/vote n'est pas compris dans l'intervalle %s" % range(len(poll.choices))) # Determines if it's the first vote ever in the poll someone_already_voted = poll.has_votes # Determines if it's the first vote for the user user_already_voted = config.session_manager.user in poll.choices_by_user # Actual vote action for the user poll_vote = poll.vote(config.session_manager.user, [poll.choices[i] for i in poll_user_choices]) # Registers an email notification http.register_hook(lambda: notify_via_email(poll_vote, Events.MODIFIED if user_already_voted else Events.NEW)) return dict( data=config.views.poll_votes(poll, highlight_user=config.session_manager.user if someone_already_voted else None), partial=someone_already_voted ) except ValueError as exception: raise http.Forbidden(exception)
def POST(self, key): if not key in ADMIN_COMPONENTS: raise web.notfound() http_input = web.input() # Scenario 1 : edit an existing element if http_input.event == Events.MODIFIED: # The grid should be bound to the form data component_to_sync = grid = ADMIN_COMPONENTS.get( key).grid_component() grid.rebind(data=http_input) fieldset = ADMIN_COMPONENTS.get(key).fieldset_component() # Scenario 2 : create a new element elif http_input.event == Events.NEW: # The fieldset should be bound to the form data & the session grid = ADMIN_COMPONENTS.get(key).grid_component() component_to_sync = fieldset = ADMIN_COMPONENTS.get( key).fieldset_component().bind(data=http_input, session=config.orm) # Scenario 3 : invalid action else: raise web.notfound() # Synchronizes the grid or the fieldset (depending on the action) & registers an email notification if component_to_sync.validate(): component_to_sync.sync() http.register_hook(lambda: notify_via_email( component_to_sync.model, http_input.event)) raise web.seeother("/") else: return config.views.layout( config.views.administration(grid, fieldset))
def POST(self): # Reads the HTTP request parameters http_input = web.input() poll_id = http_input.poll_id comment = http_input.comment # Loads the poll if poll_id is None: raise web.notfound() poll = Poll.get(int(poll_id), joined_attrs=["comments"]) if poll is None: raise web.notfound() # Appends the comment poll_comment = poll.add_comment(config.session_manager.user, comment) # Registers an email notification http.register_hook(lambda: notify_via_email(poll_comment, Events.NEW)) # Returns the dictionary return config.views.comment(poll_comment)