def _register(self, username, email, password): user = User(username=username, email=email, password=password) self.request.db.add(user) # Create a new activation for the user activation = Activation() self.request.db.add(activation) user.activation = activation # Flush the session to ensure that the user can be created and the # activation is successfully wired up self.request.db.flush() # Send the activation email message = activation_email(self.request, user) mailer = get_mailer(self.request) mailer.send(message) self.request.session.flash( jinja2.Markup( _('Thank you for creating an account! ' "We've sent you an email with an activation link, " 'before you can sign in <strong>please check your email and open ' 'the link to activate your account</strong>.')), 'success') self.request.registry.notify(RegistrationEvent(self.request, user))
def _register(self, username, email, password): user = User(username=username, email=email, password=password) self.request.db.add(user) # Create a new activation for the user activation = Activation() self.request.db.add(activation) user.activation = activation # Flush the session to ensure that the user can be created and the # activation is successfully wired up self.request.db.flush() # Send the activation email message = activation_email(self.request, user) mailer = get_mailer(self.request) mailer.send(message) self.request.session.flash( jinja2.Markup( _( "Thank you for creating an account! " "We've sent you an email with an activation link, " "before you can sign in <strong>please check your email and open " "the link to activate your account</strong>." ) ), "success", ) self.request.registry.notify(RegistrationEvent(self.request, user))
def register(self): """ Handle submission of the new user registration form. Validates the form data, creates a new activation for the user, sends the activation mail, and then redirects the user to the index. """ err, appstruct = validate_form(self.form, self.request.POST.items()) if err is not None: return err # Create the new user from selected form fields props = {k: appstruct[k] for k in ["username", "email", "password"]} user = User(**props) self.request.db.add(user) # Create a new activation for the user activation = Activation() self.request.db.add(activation) user.activation = activation # Flush the session to ensure that the user can be created and the # activation is successfully wired up self.request.db.flush() # Send the activation email message = activation_email(self.request, user) mailer = get_mailer(self.request) mailer.send(message) self.request.session.flash( _( "Thank you for registering! Please check " "your e-mail now. You can continue by " "clicking the activation link we have " "sent you." ), "success", ) self.request.registry.notify(RegistrationEvent(self.request, user)) return httpexceptions.HTTPFound(location=self.request.route_url("index"))
def register(self): """ Handle submission of the new user registration form. Validates the form data, creates a new activation for the user, sends the activation mail, and then redirects the user to the index. """ err, appstruct = validate_form(self.form, self.request.POST.items()) if err is not None: return err # Create the new user from selected form fields props = {k: appstruct[k] for k in ['username', 'email', 'password']} user = User(**props) self.request.db.add(user) # Create a new activation for the user activation = Activation() self.request.db.add(activation) user.activation = activation # Flush the session to ensure that the user can be created and the # activation is successfully wired up self.request.db.flush() # Send the activation email message = activation_email(self.request, user) mailer = get_mailer(self.request) mailer.send(message) self.request.session.flash( _("Thank you for registering! Please check " "your e-mail now. You can continue by " "clicking the activation link we have " "sent you."), 'success') self.request.registry.notify(RegistrationEvent(self.request, user)) return httpexceptions.HTTPFound( location=self.request.route_url('index'))