Exemplo n.º 1
0
    def get(self, slug = None):
        """show the complete registration form with registration data, user registration and more"""

        
        regform = self.registration_form
        userform = self.user_registration_form

        # a list of all ticket class objects
        ticketlist = self.barcamp.ticketlist
                
        if self.request.method == "POST":
            try:
                self.process_post_data()
            except ProcessingError, e:
                self.log.exception()
                self.flash(self._("Unfortunately an error occurred when trying to register you. Please try again or contact the barcamptools administrator."), category="danger")
            else:
                if self.logged_in:
                    if self.barcamp.paid_tickets:
                        self.flash(self._("Your ticket reservations have been processed. Please check your email for information on how to pay for your ticket."), category="success")
                    else:
                        self.flash(self._("Your ticket reservation was successful."), category="success")
                    return redirect(self.url_for(".mytickets", slug = self.barcamp.slug))
                else:
                    self.flash(self._("In order to finish your registration you have to activate your account. Please check your email."), category="success")
                    return redirect(self.url_for(".index", slug = self.barcamp.slug))
Exemplo n.º 2
0
    def get(self, slug=None):
        """show the complete registration form with registration data, user registration and more"""

        # show tickets instead if ticketmode is enabled
        if self.barcamp.ticketmode_enabled:
            return redirect(self.url_for(".tickets", slug=slug))

        regform = self.registration_form
        userform = self.user_registration_form

        if self.request.method == "POST":
            try:
                self.process_post_data()
            except ProcessingError, e:
                self.flash(self._(
                    "Unfortunately an error occurred when trying to register you. Please try again or contact the barcamptools administrator."
                ),
                           category="danger")
                print "error on processing post data", e
            else:
                if self.logged_in:
                    self.flash(self._(
                        "You have been successfully registered. Please check your email."
                    ),
                               category="success")
                    return redirect(
                        self.url_for(".user_events", slug=self.barcamp.slug))
                else:
                    self.flash(self._(
                        "In order to finish your registration you have to activate your account. Please check your email."
                    ),
                               category="success")
                    return redirect(
                        self.url_for(".index", slug=self.barcamp.slug))
Exemplo n.º 3
0
    def get(self, slug = None):
        """handle the barcamp registration for multiple events with optional registration form"""

        if self.barcamp.workflow != "registration":
            return "registration is not open yet"

        # check if the user has filled out all the required information on the form already
        uid = unicode(self.user._id)

        if not self.barcamp.registration_data.has_key(uid) and self.barcamp.registration_form:
            # user is not in list and we have a form
            return redirect(self.url_for(".registration_form", slug = self.barcamp.slug))

        # now check the fields
        if self.barcamp.registration_form:
            ok = True
            data = self.barcamp.registration_data[uid]
            for field in self.barcamp.registration_form:
                if field['required'] and field['name'] not in data:
                    ok = False
                    return redirect(self.url_for(".registration_form", slug = self.barcamp.slug))

        # user can register, show the list of events

        return self.render(
            view = self.barcamp_view,
            barcamp = self.barcamp,
            title = self.barcamp.name,
            has_form_data = self.barcamp.registration_data.has_key(uid),
            form_data = self.barcamp.registration_data.get(uid,{}),
            **self.barcamp)
Exemplo n.º 4
0
    def post(self, slug = None):
        """only a post without parameters is done to remove."""
        event = self.barcamp.event
        view = self.barcamp_view

        # get the username from the form
        username = self.request.form.get("u", None)
        if username is not None:
            user = self.app.module_map.userbase.get_user_by_username(username)
        else:
            user = self.user
        uid = unicode(user._id)

        # now check if we are allowed to to any changes to the user. We are if a) we are that user or b) we are an admin
        if not view.is_admin and not user==self.user:
            self.flash(self._("You are not allowed to change this."), category="danger")
            return redirect(self.url_for("barcamp_userlist", slug = self.barcamp.slug))

        if uid in event.participants:
            event.participants.remove(uid)
        if len(event.participants) < self.barcamp.size and len(event.waiting_list)>0:
            # somebody from the waiting list can move up 
            nuid = event.waiting_list[0]
            event.waiting_list = event.waiting_list[1:]
            event.participants.append(nuid)

        # you are now still a subscriber 
        self.barcamp.subscribe(user)

        self.barcamp.put()
        if user == self.user:
            self.flash(self._("You have been removed from the list of participants."), category="danger")
        else:
            self.flash(self._("%(fullname)s has been removed from the list of participants.") %user, category="danger")
        return redirect(self.url_for("barcamp_userlist", slug = self.barcamp.slug))
Exemplo n.º 5
0
    def get(self):
        """show the registration form"""
        cfg = self.module.config
        mod = self.module
        form = ActivationEMailForm(self.request.form)

        if self.request.method == 'POST':
            if form.validate():
                f = form.data
                user = mod.get_user_by_email(f['email'])
                if user is not None:
                    # send out new activation code and redirect to code sent success screen
                    if user.active:
                        self.flash(
                            self._(
                                "The user is already active. Please log in.") %
                            user)
                        url_for_params = cfg.urls.activation_success
                        url = self.url_for(**url_for_params)
                        return redirect(url)
                    mod.send_activation_code(user)
                    self.flash(
                        self.
                        _("A new activation code has been sent out, please check your email"
                          ) % user)
                    url_for_params = cfg.urls.activation_code_sent
                    url = self.url_for(**url_for_params)
                    return redirect(url)
                else:
                    self.flash(self._(
                        "This email address cannot not be found in our user database"
                    ),
                               category="danger")
        return self.render(form=form)
Exemplo n.º 6
0
    def get(self):
        """show the registration form"""
        cfg = self.module.config
        mod = self.module
        form = cfg.registration_form
        obj_class = cfg.user_class

        form = form(self.request.form, module = self.module)
        if self.request.method == 'POST':
            if form.validate():
                f = form.data
                user = mod.register(f, create_pw=False)
                if cfg.login_after_registration and not cfg.use_double_opt_in:
                    user = mod.login(self, force=True, **f)
                    self.flash(self._("Welcome, %(fullname)s") %user)
                    url_for_params = cfg.urls.login_success
                    url = self.url_for(**url_for_params)
                    return redirect(url)
                if cfg.use_double_opt_in:
                    self.flash(self._(u'To finish the registration process please check your email with instructions on how to activate your account.') %user)
                    url_for_params = cfg.urls.double_opt_in_pending
                else:
                    self.flash(self._(u'Your user registration has been successful') %user)
                    url_for_params = cfg.urls.registration_success
                url = self.url_for(**url_for_params)
                return redirect(url)
        return self.render(form = form, use_double_opt_in = cfg.use_double_opt_in)
Exemplo n.º 7
0
    def get(self):
        """show the registration form"""
        cfg = self.module.config
        mod = self.module
        form = cfg.registration_form
        obj_class = cfg.user_class

        form = form(self.request.form, module=self.module)
        if self.request.method == 'POST':
            if form.validate():
                f = form.data
                user = mod.register(f, create_pw=False)
                if cfg.login_after_registration and not cfg.use_double_opt_in:
                    user = mod.login(self, force=True, **f)
                    self.flash(self._("Welcome, %(fullname)s") % user)
                    url_for_params = cfg.urls.login_success
                    url = self.url_for(**url_for_params)
                    return redirect(url)
                if cfg.use_double_opt_in:
                    self.flash(
                        self.
                        _(u'To finish the registration process please check your email with instructions on how to activate your account.'
                          ) % user)
                    url_for_params = cfg.urls.double_opt_in_pending
                else:
                    self.flash(
                        self._(u'Your user registration has been successful') %
                        user)
                    url_for_params = cfg.urls.registration_success
                url = self.url_for(**url_for_params)
                return redirect(url)
        return self.render(form=form, use_double_opt_in=cfg.use_double_opt_in)
Exemplo n.º 8
0
    def get(self, slug=None):
        """handle the barcamp registration for multiple events with optional registration form"""

        if self.barcamp.workflow != "registration":
            return "registration is not open yet"

        # check if the user has filled out all the required information on the form already
        uid = unicode(self.user._id)

        if not self.barcamp.registration_data.has_key(
                uid) and self.barcamp.registration_form:
            # user is not in list and we have a form
            return redirect(
                self.url_for(".registration_form", slug=self.barcamp.slug))

        # now check the fields
        if self.barcamp.registration_form:
            ok = True
            data = self.barcamp.registration_data[uid]
            for field in self.barcamp.registration_form:
                if field['required'] and field['name'] not in data:
                    ok = False
                    return redirect(
                        self.url_for(".registration_form",
                                     slug=self.barcamp.slug))

        # user can register, show the list of events

        return self.render(
            view=self.barcamp_view,
            barcamp=self.barcamp,
            title=self.barcamp.name,
            has_form_data=self.barcamp.registration_data.has_key(uid),
            form_data=self.barcamp.registration_data.get(uid, {}),
            **self.barcamp)
Exemplo n.º 9
0
    def post(self, slug=None):
        """only a post without parameters is done to add. Post again to unsubscribe"""
        view = self.barcamp_view
        username = self.request.form.get("u", None)
        if username is not None:
            user = self.app.module_map.userbase.get_user_by_username(username)
        else:
            user = self.user

        # now check if we are allowed to to any changes to the user. We are if a) we are that user or b) we are an admin
        if not view.is_admin and not user == self.user:
            self.flash(self._("You are not allowed to change this."), category="danger")
            return redirect(self.url_for(".userlist", slug=self.barcamp.slug))
        if unicode(user._id) not in self.barcamp.subscribers:
            self.barcamp.subscribe(self.user)  # we can only subscribe our own user, thus self.user and not user
            self.flash(self._("You are now on the list of people interested in the barcamp"), category="success")
        else:
            self.barcamp.unsubscribe(user)  # we can remove any user if we have the permission (see above for the check)
            if user == self.user:
                self.flash(
                    self._("You have been removed from the list of people interested in this barcamp"),
                    category="danger",
                )
            else:
                self.flash(
                    self._("%(fullname)s has been removed from the list of people interested in this barcamp") % user,
                    category="danger",
                )
        return redirect(self.url_for(".userlist", slug=self.barcamp.slug))
Exemplo n.º 10
0
    def get(self):
        """show the registration form"""
        cfg = self.module.config
        mod = self.module
        form = ActivationEMailForm(self.request.form)

        if self.request.method == 'POST':
            if form.validate():
                f = form.data
                user = mod.get_user_by_email(f['email'])
                if user is not None:
                    # send out new activation code and redirect to code sent success screen 
                    if user.active:
                        self.flash(self._("The user is already active. Please log in.") %user)
                        url_for_params = cfg.urls.activation_success
                        url = self.url_for(**url_for_params)
                        return redirect(url)
                    mod.send_activation_code(user)
                    self.flash(self._("A new activation code has been sent out, please check your email") %user)
                    url_for_params = cfg.urls.activation_code_sent
                    url = self.url_for(**url_for_params)
                    return redirect(url)
                else:
                    self.flash(self._("This email address cannot not be found in our user database"), category="danger")
        return self.render(form = form)
Exemplo n.º 11
0
Arquivo: base.py Projeto: cryu/camper
 def wrapper(self, *args, **kwargs):
     if self.user is None:
         self.flash(u"Sie haben keine Berechtigung, diese Seite aufzurufen.", category="error")
         return redirect(self.url_for("index"))
     elif not self.user.has_permission("admin"):
         self.flash(u"Sie haben keine Berechtigung, diese Seite aufzurufen.", category="error")
         return redirect(self.url_for("index"))
     return method(self, *args, **kwargs)
Exemplo n.º 12
0
 def wrapper(self, *args, **kwargs):
     if self.user is None:
         self.flash("Sie haben nicht die erforderlichen Rechte, diese Seite einzusehen", category="danger")
         return redirect(self.url_for("index"))
     if self.user.has_permission("admin"):
         return method(self, *args, **kwargs)
     self.flash("Sie haben nicht die erforderlichen Rechte, diese Seite einzusehen", category="danger")
     return redirect(self.url_for("index"))
Exemplo n.º 13
0
 def wrapper(self, *args, **kwargs):
     if self.user is None:
         self.flash(self._(u"you don't have the permission to access this page."), category="error")
         return redirect(self.url_for("index"))
     elif not self.user.has_permission("admin"):
         self.flash(self._(u"you don't have the permission to access this page."), category="error")
         return redirect(self.url_for("index"))
     return method(self, *args, **kwargs)
Exemplo n.º 14
0
Arquivo: base.py Projeto: cryu/camper
 def wrapper(self, *args, **kwargs):
     if self.user is None:
         self.flash(u"Sie haben keine Berechtigung, diese Seite aufzurufen.", category="error")
         return redirect(self.url_for("index"))
     if unicode(self.user._id) in self.barcamp.admins:
         return method(self, *args, **kwargs)
     if self.user.has_permission("admin"):
         return method(self, *args, **kwargs)
     self.flash(u"Sie haben keine Berechtigung, diese Seite aufzurufen.", category="error")
     return redirect(self.url_for("index"))
Exemplo n.º 15
0
Arquivo: base.py Projeto: cryu/camper
 def wrapper(self, *args, **kwargs):
     if self.user is None:
         self.flash(self._("you don't have the correct permissions to access this page."), category="error")
         return redirect(self.url_for("index"))
     if self.user.has_permission("admin"):
         return method(self, *args, **kwargs)
     if unicode(self.user._id) in self.barcamp.admins:
         return method(self, *args, **kwargs)
     self.flash(self._("You don't have the correct permissions to access this page."), category="error")
     return redirect(self.url_for("index"))
Exemplo n.º 16
0
 def delete(self, slug = None):
     uid = self.request.args.get("uid")
     if len(self.barcamp.admins)<2:
         self.flash(self._(u"you at least need to have one administrator."), category="error")
         return redirect(self.url_for("barcamps.permissions", slug = slug))
     if uid in self.barcamp.admins:
         self.barcamp.remove_admin_by_id(uid)
         self.barcamp.save()
     self.flash(self._(u"Administrator deleted."))
     return redirect(self.url_for("barcamps.permissions", slug = slug))
Exemplo n.º 17
0
 def wrapper(self, *args, **kwargs):
     if self.user is None:
         self.flash(self._(u"you don't have the permission to access this page."), category="error")
         return redirect(self.url_for("index"))
     if unicode(self.user._id) in self.barcamp.admins:
         return method(self, *args, **kwargs)
     if self.user.has_permission("admin"):
         return method(self, *args, **kwargs)
     self.flash(self._(u"you don't have the permission to access this page."), category="error")
     return redirect(self.url_for("index"))
Exemplo n.º 18
0
 def delete(self, slug=None):
     uid = self.request.args.get("uid")
     if len(self.barcamp.admins) < 2:
         self.flash(self._(u"you at least need to have one administrator."),
                    category="error")
         return redirect(self.url_for("barcamps.permissions", slug=slug))
     if uid in self.barcamp.admins:
         self.barcamp.remove_admin_by_id(uid)
         self.barcamp.save()
     self.flash(self._(u"Administrator deleted."))
     return redirect(self.url_for("barcamps.permissions", slug=slug))
Exemplo n.º 19
0
 def wrapper(self, *args, **kwargs):
     if self.user is None:
         self.flash(self._(
             u"you don't have the permission to access this page."),
                    category="error")
         return redirect(self.url_for("index"))
     elif not self.user.has_permission("admin"):
         self.flash(self._(
             u"you don't have the permission to access this page."),
                    category="error")
         return redirect(self.url_for("index"))
     return method(self, *args, **kwargs)
Exemplo n.º 20
0
 def delete(self, slug = None):
     uid = self.request.args.get("uid")
     if uid == self.barcamp.created_by:
         self.flash(u"Dem Ersteller des Barcamps kann das Admin-Recht nicht entzogen werden.", category="error")
         return redirect(self.url_for("barcamp_permissions", slug = slug))
     if len(self.barcamp.admins)<2:
         self.flash(u"Es muss mindestens einen Administrator geben.", category="error")
         return redirect(self.url_for("barcamp_permissions", slug = slug))
     if uid in self.barcamp.admins:
         self.barcamp.remove_admin_by_id(uid)
         self.barcamp.save()
     self.flash(u"Administrator gelöscht.")
     return redirect(self.url_for("barcamp_permissions", slug = slug))
Exemplo n.º 21
0
    def post(self, slug = None):
        """set the visibility of the barcamp"""
        email = self.request.form.get("email")
        user = self.app.module_map.userbase.get_user_by_email(email)
        if user is None:
            self.flash(self._(u"a user with this email address wasn't found in our database."), category="error")
            return redirect(self.url_for("barcamps.permissions", slug = slug))

        uid = str(user._id)
        if uid not in self.barcamp.admins:
            self.barcamp.add_admin(user)
            self.barcamp.save()
            self.flash(self._(u"%s is not an administrator for this barcamp.") %user.fullname)

        return redirect(self.url_for("barcamps.permissions", slug = slug))
Exemplo n.º 22
0
    def post(self, slug = None):
        """set the visibility of the barcamp"""
        email = self.request.form.get("email")
        user = self.app.module_map.userbase.get_user_by_email(email)
        if user is None:
            self.flash("Ein Benutzer mit dieser E-Mail-Adresse wurde leider nicht gefunden.", category="error")
            return redirect(self.url_for("barcamp_permissions", slug = slug))

        uid = str(user._id)
        if uid not in self.barcamp.admins:
            self.barcamp.add_admin(user)
            self.barcamp.save()
            self.flash(u"%s ist nun ebenfalls ein Admin für dieses Barcamp." %user.fullname)

        return redirect(self.url_for("barcamp_permissions", slug = slug))
Exemplo n.º 23
0
 def delete(self, seg_id = None, p_id = None):
     """delete a proposal"""
     p = self.config.dbs.proposals.get(p_id)
     p.set_workflow("deleted")
     p.save()
     self.flash(u"Der Vorschlag wurde erfolgreich gelöscht", category="danger")
     return redirect(self.url_for('segment_view', seg_id=seg_id))
Exemplo n.º 24
0
    def post(self, slug = None):
        """render the view"""
        barcamp_id = self.barcamp._id

        # delete pages
        self.config.dbs.pages._remove({'barcamp' : unicode(self.barcamp._id)})
        
        # delete sessions
        sessions = self.config.dbs.sessions._remove({'barcamp_id' : str(barcamp_id)})
        
        # delete blog entries
        blogs = self.config.dbs.blog._remove({'barcamp' : str(barcamp_id)})

        # delete galleries
        galleries = self.config.dbs.galleries._remove({'barcamp' : str(barcamp_id)})
        
        # delete participant data
        data = self.config.dbs.participant_data._remove({'barcamp_id' : str(barcamp_id)})
        
        # delete tickets
        data = self.config.dbs.tickets._remove({'barcamp_id' : str(barcamp_id)})

        # delete user favs
        data = self.config.dbs.userfavs._remove({'barcamp_id' : str(barcamp_id)})

        # delete barcamp
        self.barcamp.remove()
        self.flash(self._("The barcamp and all it's contents have been deleted!"), category="success")
        return redirect(self.url_for("index"))
Exemplo n.º 25
0
 def delete(self, slug=None):
     uid = self.request.args.get("uid")
     if uid == self.barcamp.created_by:
         self.flash(
             u"Dem Ersteller des Barcamps kann das Admin-Recht nicht entzogen werden.",
             category="error")
         return redirect(self.url_for("barcamp_permissions", slug=slug))
     if len(self.barcamp.admins) < 2:
         self.flash(u"Es muss mindestens einen Administrator geben.",
                    category="error")
         return redirect(self.url_for("barcamp_permissions", slug=slug))
     if uid in self.barcamp.admins:
         self.barcamp.remove_admin_by_id(uid)
         self.barcamp.save()
     self.flash(u"Administrator gelöscht.")
     return redirect(self.url_for("barcamp_permissions", slug=slug))
Exemplo n.º 26
0
class Permissions(BarcampBaseHandler):
    """screen for private/public and admin management"""

    template = "admin/permissions.html"

    @ensure_barcamp()
    @logged_in()
    @is_admin()
    def get(self, slug=None):
        """render the view"""
        return self.render(title=self.barcamp.name, **self.barcamp)

    @ensure_barcamp()
    @logged_in()
    @is_admin()
    def post(self, slug=None):
        """set the workflow state for the barcamp"""
        try:
            self.barcamp.set_workflow(self.request.form.get("wf", ""))
            self.barcamp.save()
        except WorkflowError, e:
            print e
            self.flash(self._("you cannot perform this action."),
                       category="error")
            return redirect(self.url_for(".admin_wizard", slug=slug))

        # send out the notification email
        wf = self.request.form.get("wf", "")
        if wf == "registration":
            self.flash(self._("The barcamp is now open for registration."),
                       category="success")
        elif wf == "public":
            self.flash(self._("The barcamp is now public."),
                       category="success")

            # this can be multiple addresses split by comma
            send_to = self.app.config.new_bc_notification_addr
            if send_to:
                send_tos = [e.strip() for e in send_to.split(",")]
                mailer = self.app.module_map['mail']
                if self.barcamp.start_date and self.barcamp.end_date:
                    date = "%s - %s" % (
                        self.barcamp.start_date.strftime('%d.%m.%Y'),
                        self.barcamp.end_date.strftime('%d.%m.%Y'))
                else:
                    date = "TBA"
                kwargs = dict(name=self.barcamp.name,
                              description=self.barcamp.description,
                              date=date,
                              url=self.url_for("barcamps.index",
                                               slug=self.barcamp.slug,
                                               _full=True))
                payload = self.render_lang("emails/new_barcamp.txt", **kwargs)
                subject = self._("camper: new barcamp created")

                # now send it out to all recipients
                for send_to in send_tos:
                    mailer.mail(send_to, subject, payload)

        return redirect(self.url_for(".admin_wizard", slug=slug))
Exemplo n.º 27
0
Arquivo: base.py Projeto: cryu/camper
 def forbidden(self):
     """call this if you want to show the user a message that a permission is missing and redirect to the homepage"""
     self.flash(self._("You don't have the correct permissions to access this page."), category="error")
     # TODO: maybe check barcamp and permissions for the barcamp homepage and redirect there instead
     # TODO: maybe create a remember decorator which remember the last page in the session which is safe to redirect to.
     # the forbidden handler should delete it though
     return redirect(self.url_for("index"))
Exemplo n.º 28
0
 def get(self):
     """show the registration form"""
     cfg = self.module.config
     mod = self.module
     code = self.request.args.get("code", None)
     if self.request.method == 'POST':
         code = self.request.form.get("code", "")
     else:
         code = self.request.args.get("code", None)
     if code is not None:
         # TODO: check expiration time
         user = mod.get_user_by_activation_code(code)
         if user is not None:
             user.activate()
             mod.login(self, user=user, save=False)
             user.save()
             self.flash(
                 self._("Your account has been successfully activated.") %
                 user)
             url_for_params = cfg.urls.activation_success
             url = self.url_for(**url_for_params)
             return redirect(url)
         else:
             url = self.url_for(endpoint=".activation_code")
             params = {'url': url, 'code': code}
             self.flash(self._(
                 """The activation code is not valid. Please try again or click <a href="%(url)s">here</a> to get a new one."""
             ) % params,
                        category="danger")
     return self.render()
Exemplo n.º 29
0
    def get(self, slug = None):
        """render the view"""
        form = ParticipantCountForm(self.request.form, obj = self.barcamp, config = self.config)
        min_count = self.barcamp.size
        form['size'].validators = [validators.Required(), validators.NumberRange(min=min_count, message=self._("you cannot reduce the participant number, the minimum amount is %s") %min_count)]
        if self.request.method == 'POST' and form.validate():
            size = form.data['size']

            self.barcamp.size = size

            # now move people from the waiting list to the particpating list
            obj = self.barcamp
            while obj.size > len(obj.event.participants) and len(obj.event.waiting_list)>0:
                nuid = obj.event.waiting_list[0]
                obj.event.waiting_list = obj.event.waiting_list[1:]
                obj.event.participants.append(nuid)

                # send out the mail 
                user = self.app.module_map.userbase.get_user_by_id(nuid)
                self.mail_template("fromwaitinglist",
                        view = self.barcamp_view,
                        barcamp = self.barcamp,
                        title = self.barcamp.name,
                        send_to = user.email,
                        fullname = user.fullname,
                        **self.barcamp)

            self.barcamp.put()
            self.flash("Barcamp aktualisiert", category="info")
            return redirect(self.url_for("barcamps.index", slug = self.barcamp.slug))
        return self.render(form = form, barcamp = self.barcamp)
Exemplo n.º 30
0
    def get(self):
        """show the form for entering your email address. The form can be overwritten in the userbase module"""
        cfg = self.module.config
        mod = self.module
        form = cfg.pw_forgot_form(self.request.form)

        if self.request.method == 'POST':
            if form.validate():
                f = form.data
                user = mod.get_user_by_email(f['email'])
                if user is not None:

                    # send out pw forgot code and redirect to code sent success screen
                    mod.send_pw_code(user)
                    self.flash(
                        self.
                        _(u'A link to set a new password has been sent to you')
                        % user)
                    url_for_params = cfg.urls.pw_code_success
                    url = self.url_for(**url_for_params)
                    return redirect(url)
                else:
                    self.flash(
                        self._(u'The email address is not in our database.'))
        return self.render(form=form)
Exemplo n.º 31
0
 def get(self):
     """show the password set form"""
     cfg = self.module.config
     mod = self.module
     code = self.request.args.get("code", None)
     if self.request.method == 'POST':
         code = self.request.form.get("code", "")
     else:
         code = self.request.args.get("code", None)
     if code is not None:
         user = mod.get_user_by_activation_code(code)
         if user is not None:
             user.activate()
             mod.login(self, user=user, save=False)
             user.save()
             self.flash(
                 self._("Your password has been successfully changed"))
             url_for_params = cfg.urls.activation_success
             url = self.url_for(**url_for_params)
             return redirect(url)
         else:
             url = self.url_for(endpoint=".activation_code")
             params = {'url': url, 'code': code}
             self.flash(self._("Your password change has failed" % params),
                        category="danger")
             self.flash(cfg.messages.activation_failed % params,
                        category="danger")
     return self.render()
Exemplo n.º 32
0
    def get(self, slug=None):
        """render the view"""
        obj = copy.copy(self.barcamp)
        form = LegalEditForm(self.request.form,
                             obj=self.barcamp,
                             config=self.config)
        if self.barcamp.paid_tickets:
            for field in form:
                form[field.name].validators.append(validators.Required())
        else:
            for field in form:
                form[field.name].validators.append(validators.Optional())

        if self.request.method == 'POST' and form.validate():

            f = form.data

            # update it so we have the new data for comparison
            self.barcamp.update(f)
            self.barcamp.put()
            self.flash(self._("The barcamp has been updated."),
                       category="info")
            return redirect(
                self.url_for("barcamps.legaledit", slug=self.barcamp.slug))

        return self.render(form=form, bcid=str(self.barcamp._id))
Exemplo n.º 33
0
    def get(self, slug = None):
        """render the view"""
        form = ParticipantDataEditForm(self.request.form, config = self.config)
        registration_form = self.barcamp.registration_form
        if self.request.method == 'POST' and form.validate():
            f = form.data
            f['name'] = unicode(uuid.uuid4())
            
            # clean up choices
            new_choices = []
            for c in f['choices'].split("\n"):
                choice = c.strip()
                if choice:
                    new_choices.append((choice, choice)) # value and name are the same

            f['choices'] = new_choices

            self.barcamp.registration_form.append(f)
            self.barcamp.save()
            return redirect(self.url_for("barcamps.registration_form_editor", slug = self.barcamp.slug))

        return self.render(
            view = self.barcamp_view,
            barcamp = self.barcamp,
            title = self.barcamp.name,
            form = form,
            fields = self.barcamp.registration_form,
            **self.barcamp
        )
Exemplo n.º 34
0
    def post(self, slug=None):
        """render the view"""
        barcamp_id = self.barcamp._id

        # delete pages
        self.config.dbs.pages._remove({'barcamp': unicode(self.barcamp._id)})

        # delete sessions
        sessions = self.config.dbs.sessions._remove(
            {'barcamp_id': str(barcamp_id)})

        # delete blog entries
        blogs = self.config.dbs.blog._remove({'barcamp': str(barcamp_id)})

        # delete galleries
        galleries = self.config.dbs.galleries._remove(
            {'barcamp': str(barcamp_id)})

        # delete participant data
        data = self.config.dbs.participant_data._remove(
            {'barcamp_id': str(barcamp_id)})

        # delete tickets
        data = self.config.dbs.tickets._remove({'barcamp_id': str(barcamp_id)})

        # delete user favs
        data = self.config.dbs.userfavs._remove(
            {'barcamp_id': str(barcamp_id)})

        # delete barcamp
        self.barcamp.remove()
        self.flash(
            self._("The barcamp and all it's contents have been deleted!"),
            category="success")
        return redirect(self.url_for("index"))
Exemplo n.º 35
0
 def get(self):
     """show the password set form"""
     cfg = self.module.config
     mod = self.module
     code = self.request.args.get("code", None)
     if self.request.method == 'POST':
         code = self.request.form.get("code", "")
     else:
         code = self.request.args.get("code", None)
     if code is not None:
         user = mod.get_user_by_activation_code(code)
         if user is not None:
             user.activate()
             mod.login(self, user=user, save = False)
             user.save()
             self.flash(self._("Your password has been successfully changed"))
             url_for_params = cfg.urls.activation_success
             url = self.url_for(**url_for_params)
             return redirect(url)
         else:
             url = self.url_for(endpoint=".activation_code")
             params = {'url': url, 'code' : code}
             self.flash(self._("Your password change has failed" %params), category="danger")
             self.flash(cfg.messages.activation_failed %params, category="danger")
     return self.render()
Exemplo n.º 36
0
    def get(self, slug=None):
        """render the view"""

        tickets = self.config.dbs.tickets
        userbase = self.app.module_map.userbase

        ticket_classes = self.barcamp.ticketlist
        for tc in ticket_classes:
            for status in [
                    'pending', 'confirmed', 'canceled', 'cancel_request'
            ]:
                tc[status] = tickets.get_tickets(barcamp_id=self.barcamp._id,
                                                 ticketclass_id=tc._id,
                                                 status=status)
                # compute users
                uids = [t.user_id for t in tc[status]]
                users = userbase.get_users_by_ids(uids)
                userdict = {}
                for user in users:
                    userdict[str(user._id)] = user
                for ticket in tc[status]:
                    ticket['user'] = userdict[ticket.user_id]

        # make sure we are supposed to be shown
        if not self.barcamp.ticketmode_enabled:
            self.flash(self._('Ticketing Mode not enabled.'),
                       category="danger")
            return redirect(
                self.url_for("barcamps.admin_ticketeditor",
                             slug=self.barcamp.slug))

        return self.render(view=self.barcamp_view,
                           barcamp=self.barcamp,
                           ticket_classes=ticket_classes,
                           title=self.barcamp.name)
Exemplo n.º 37
0
    def get(self, slug = None):
        """render the view"""

        tickets = self.config.dbs.tickets
        userbase = self.app.module_map.userbase

        ticket_classes = self.barcamp.ticketlist
        for tc in ticket_classes:
            for status in ['pending', 'confirmed', 'canceled', 'cancel_request']:
                tc[status] = tickets.get_tickets(
                    barcamp_id = self.barcamp._id,
                    ticketclass_id = tc._id,
                    status = status)
                # compute users
                uids = [t.user_id for t in tc[status]]
                users = userbase.get_users_by_ids(uids)
                userdict = {}
                for user in users:
                    userdict[str(user._id)] = user
                for ticket in tc[status]:
                    ticket['user'] = userdict[ticket.user_id]

        # make sure we are supposed to be shown
        if not self.barcamp.ticketmode_enabled:
            self.flash(self._('Ticketing Mode not enabled.'), category="danger")
            return redirect(self.url_for("barcamps.admin_ticketeditor", slug = self.barcamp.slug))

        return self.render(
            view = self.barcamp_view,
            barcamp = self.barcamp,
            ticket_classes = ticket_classes,
            title = self.barcamp.name)
Exemplo n.º 38
0
    def get(self):
        """render the view"""
        form = EMailForm(self.request.form,
                         obj=self.user,
                         config=self.config,
                         app=self.app,
                         handler=self)
        if self.request.method == "POST":
            if form.validate():
                email = form.data['email']
                # now save it temporarily and send an activation email
                code = self.user.set_new_email(email)

                activation_url = self.url_for("confirm_email",
                                              _full=True,
                                              _append=True,
                                              code=code)

                self.mail_text("emails/new_reply_to.txt",
                               self._('Confirm your Reply-To address'),
                               send_to=email,
                               activation_url=activation_url)
                self.user.save()
                self.flash(self._(
                    "Please check your inbox of the new email for a confirmation mail and confirm it"
                ),
                           category="info")
                url = self.url_for("profile", username=self.user.username)
                return redirect(url)
            else:
                self.flash(self._("There have been errors in the form"),
                           category="danger")
        return self.render(form=form, user=self.user)
Exemplo n.º 39
0
Arquivo: edit.py Projeto: sk1p/camper
 def get(self):
     """render the view"""
     form = EditForm(self.request.form,
                     obj=self.user,
                     config=self.config,
                     app=self.app,
                     handler=self)
     if self.user.image:
         try:
             asset = self.app.module_map.uploader.get(self.user.image)
             image = self.url_for(
                 "asset", asset_id=asset.variants['medium_user']._id)
         except:
             image = None
     else:
         image = None
     if self.request.method == "POST":
         if form.validate():
             self.user.update(form.data)
             self.user.save()
             self.flash(self._("Your profile has been updated"),
                        category="info")
             url = self.url_for("profile", username=self.user.username)
             return redirect(url)
         else:
             self.flash(self._("There have been errors in the form"),
                        category="danger")
     return self.render(form=form, user=self.user, image=image)
Exemplo n.º 40
0
    def get(self):
        """show the login form"""
        cfg = self.module.config
        mod = self.module
        form = cfg.login_form
        obj_class = cfg.user_class

        langs = [getattr(self, 'LANGUAGE', 'en')]
        form = cfg.login_form(self.request.form, handler = self)
        if self.request.method == 'POST':
            if form.validate():
                f = form.data
                try:
                    remember = self.module.config.use_remember and self.request.form.get("remember")
                    user = mod.login(self, **f)
                    url_for_params = cfg.urls.login_success
                    url = self.url_for(**url_for_params)
                    self.flash(self._("Hello %(fullname)s, you are now logged in.") %user)
                    return redirect(url)
                except PasswordIncorrect, e:
                    log.warn("login failed: incorrect password", username = e.username)
                    self.flash(self._("Invalid credentials. You might have mistyped something, please check your spelling."), category="danger")
                except UserUnknown, e:
                    log.warn("login failed: unknown user", username = e.username)
                    self.flash(self._("Invalid credentials. You might have mistyped something, please check your spelling."), category="danger")
                except UserNotActive, e:
                    if cfg.use_double_opt_in:
                        log.warn("login failed: user account not yet activated")
                        self.flash(self._("""Your user account has not been activated. In order to receive a new activation email <a href="%s">click here</a>""") 
                                %self.url_for(".activation_code"), category="warning")
                    else:
                        log.warn("login failed: unknown error", user = user)
                        self.flash(self._("Login failed, please try again."), category="danger")
Exemplo n.º 41
0
 def forbidden(self):
     """call this if you want to show the user a message that a permission is missing and redirect to the homepage"""
     self.flash(self._("You don't have the correct permissions to access this page."), category="error")
     # TODO: maybe check barcamp and permissions for the barcamp homepage and redirect there instead
     # TODO: maybe create a remember decorator which remember the last page in the session which is safe to redirect to.
     # the forbidden handler should delete it though
     return redirect(self.url_for("index"))
Exemplo n.º 42
0
    def post(self, slug = None):
        """only a post without parameters is done to add."""
        view = self.barcamp_view
        event = self.barcamp.event
        uid = unicode(self.user._id)

        if len(event.participants) >= self.barcamp.size:
            self.flash(self._("Unfortunately list of participants is already full. You have been put onto the waiting list and will be informed should you move on to the list of participants."), category="danger")
            if uid not in event.waiting_list:
                event.waiting_list.append(uid)
                self.barcamp.subscribers.remove(uid)
                self.barcamp.put()
                self.mail_text("emails/welcome.txt", self._('You are now on the waiting list for %s' %self.barcamp.name),
                    view = view,
                    barcamp = self.barcamp,
                    title = self.barcamp.name,
                    **self.barcamp)
        else:
            self.flash(self._("You are now on the list of participants for this barcamp."), category="success")
            if uid not in event.participants:
                event.participants.append(uid)
                if uid in self.barcamp.subscribers:
                    self.barcamp.subscribers.remove(uid)
                self.barcamp.put()
                self.mail_text("emails/welcome.txt", self._('Welcome to %s' %self.barcamp.name),
                    view = view,
                    barcamp = self.barcamp,
                    title = self.barcamp.name,
                    **self.barcamp)
        return redirect(self.url_for("barcamp_userlist", slug = self.barcamp.slug))
Exemplo n.º 43
0
    def get(self, slug=None):
        """render the view"""
        form = ParticipantDataEditForm(self.request.form, config=self.config)
        registration_form = self.barcamp.registration_form
        if self.request.method == 'POST' and form.validate():
            f = form.data
            f['name'] = unicode(uuid.uuid4())

            # clean up choices
            new_choices = []
            for c in f['choices'].split("\n"):
                choice = c.strip()
                if choice:
                    new_choices.append(
                        (choice, choice))  # value and name are the same

            f['choices'] = new_choices

            self.barcamp.registration_form.append(f)
            self.barcamp.save()
            return redirect(
                self.url_for("barcamps.registration_form_editor",
                             slug=self.barcamp.slug))

        return self.render(view=self.barcamp_view,
                           barcamp=self.barcamp,
                           title=self.barcamp.name,
                           form=form,
                           fields=self.barcamp.registration_form,
                           **self.barcamp)
Exemplo n.º 44
0
 def get(self):
     """show the registration form"""
     cfg = self.module.config
     mod = self.module
     code = self.request.args.get("code", None)
     if self.request.method == 'POST':
         code = self.request.form.get("code", "")
     else:
         code = self.request.args.get("code", None)
     if code is not None:
         # TODO: check expiration time
         user = mod.get_user_by_activation_code(code)
         if user is not None:
             user.activate()
             mod.login(self, user=user, save = False)
             user.save()
             self.flash(self._("Your account has been successfully activated.") %user)
             url_for_params = cfg.urls.activation_success
             url = self.url_for(**url_for_params)
             return redirect(url)
         else:
             url = self.url_for(endpoint=".activation_code")
             params = {'url': url, 'code' : code}
             self.flash(self._("""The activation code is not valid. Please try again or click <a href="%(url)s">here</a> to get a new one.""") %params, category="danger")
     return self.render()
Exemplo n.º 45
0
Arquivo: add.py Projeto: cryu/camper
    def get(self):
        """render the view"""
        form = BarcampAddForm(self.request.form, config = self.config)
        if self.request.method == 'POST' and form.validate():
            f = form.data
            f['admins'] = [self.user._id]
            f['created_by'] = self.user._id
            f['subscribers'] = [self.user._id]
            f['location'] = {
                'name'      : f['location_name'],
                'street'    : f['location_street'],
                'city'      : f['location_city'],
                'zip'       : f['location_zip'],
                'email'     : f['location_email'],
                'phone'     : f['location_phone'],
                'url'       : f['location_url'],
                'description' : f['location_description'],
                'country'   : 'de',
            }

            pid = unicode(uuid.uuid4())[:8]
            pid = f['planning_pad'] = "%s_%s" %(f['slug'],pid)
            did = f['slug']
            try:
                self.config.etherpad.createPad(padID=pid, text=u"Planung")
                self.config.etherpad.createPad(padID=did, text=u"Dokumentation")
            except:
                self.flash(self._("Attention: One or both of the etherpads exist already!"), category="warning")
                pass
            f['documentation_pad'] = did

            # retrieve geo location
            if form.data['location_street']:
                url = "http://nominatim.openstreetmap.org/search?q=%s, %s&format=json&polygon=0&addressdetails=1" %(
                    form.data['location_street'],
                    form.data['location_city'],
                )
                data = requests.get(url).json()
                if len(data)==0:
                    # trying again but only with city
                    url = "http://nominatim.openstreetmap.org/search?q=%s&format=json&polygon=0&addressdetails=1" %(
                        form.data['location_city'],
                    )
                    data = requests.get(url).json()
                if len(data)==0:
                    self.flash(self._("the city was not found in the geo database"), category="danger")
                    return self.render(form = form)
                # we have at least one entry, take the first one
                result = data[0]
                f['location']['lat'] = result['lat']
                f['location']['lng'] = result['lon']

            # create and save the barcamp object
            barcamp = db.Barcamp(f, collection = self.config.dbs.barcamps)
            barcamp = self.config.dbs.barcamps.put(barcamp)

            self.flash(self._("%s has been created") %f['name'], category="info")
            return redirect(self.url_for("index"))
        return self.render(form = form, slug = None)
Exemplo n.º 46
0
 def delete(self, slug = None):
     """delete a form entry"""
     idx = self.request.args.get("idx", None)
     rf = self.barcamp.registration_form
     if idx is not None and int(idx) < len(rf) and int(idx) >= 0:
         del self.barcamp.registration_form[int(idx)]
         self.barcamp.save()
     return redirect(self.url_for("barcamps.registration_form_editor", slug = self.barcamp.slug))
Exemplo n.º 47
0
 def get(self):
     """show the login form"""
     cfg = self.module.config
     self.module.logout(self)
     self.flash(self._(u"You are now logged out."))
     url_for_params = cfg.urls.logout_success
     url = self.url_for(**url_for_params)
     return redirect(url)
Exemplo n.º 48
0
    def get(self, slug=None):
        """verify the reply to code and inform the user"""

        code = self.request.args.get("code", "")
        confirmed = self.user.verify_email_code(code)
        self.user.save()
        if confirmed:
            self.flash(
                self._('You have successfully changed your email address!'),
                category="info")
            return redirect(
                self.url_for("profile", username=self.user.username))
        else:
            self.flash(
                self._('Unfortunately the code was wrong. Please try again!'),
                category="danger")
            return redirect(self.url_for("email_edit"))
Exemplo n.º 49
0
 def get(self):
     """show the login form"""
     cfg = self.module.config
     self.module.logout(self)
     self.flash(self._(u"You are now logged out."))
     url_for_params = cfg.urls.logout_success
     url = self.url_for(**url_for_params)
     return redirect(url)
Exemplo n.º 50
0
Arquivo: edit.py Projeto: cryu/camper
 def get(self, slug=None):
     """render the view"""
     obj = copy.copy(self.barcamp)
     obj['location_name'] = self.barcamp.location['name']
     obj['location_street'] = self.barcamp.location['street']
     obj['location_city'] = self.barcamp.location['city']
     obj['location_zip'] = self.barcamp.location['zip']
     obj['location_country'] = self.barcamp.location['country']
     obj['location_email'] = self.barcamp.location['email']
     obj['location_phone'] = self.barcamp.location['phone']
     obj['location_url'] = self.barcamp.location['url']
     obj['location_description'] = self.barcamp.location['description']
     form = BarcampEditForm(self.request.form, obj=obj, config=self.config)
     if self.barcamp.public:
         del form['slug']
     if self.request.method == 'POST' and form.validate():
         f = form.data
         f['location'] = {
             'name': f['location_name'],
             'street': f['location_street'],
             'city': f['location_city'],
             'zip': f['location_zip'],
             'email': f['location_email'],
             'phone': f['location_phone'],
             'url': f['location_url'],
             'description': f['location_description'],
             'country': 'de',
         }
         # do the nominatim request to find out lat/long but only if street and city have not changed
         if (form.data['location_street'] != self.barcamp.location['street']
                 or
                 form.data['location_city'] != self.barcamp.location['city']
                 or form.data['location_zip'] !=
                 self.barcamp.location['zip']) or True:
             url = "http://nominatim.openstreetmap.org/search?q=%s, %s&format=json&polygon=0&addressdetails=1" % (
                 form.data['location_street'],
                 form.data['location_city'],
             )
             data = requests.get(url).json()
             if len(data) == 0:
                 # trying again but only with city
                 url = "http://nominatim.openstreetmap.org/search?q=%s&format=json&polygon=0&addressdetails=1" % (
                     form.data['location_city'], )
                 data = requests.get(url).json()
             if len(data) == 0:
                 self.flash(
                     self._("the city was not found in the geo database"),
                     category="danger")
                 return self.render(form=form)
             # we have at least one entry, take the first one
             result = data[0]
             f['location']['lat'] = result['lat']
             f['location']['lng'] = result['lon']
         self.barcamp.update(f)
         self.barcamp.put()
         self.flash("Barcamp aktualisiert", category="info")
         return redirect(self.url_for("barcamp", slug=self.barcamp.slug))
     return self.render(form=form)
Exemplo n.º 51
0
 def delete(self, slug=None, page_slug=None):
     """delete a page"""
     self.page.remove()
     self.flash(self._(u"the page has been deleted"))
     if self.barcamp is not None:
         url = self.url_for("barcamps.index", slug=self.barcamp.slug)
     else:
         url = self.url_for("index")
     return redirect(url)
Exemplo n.º 52
0
    def post(self, slug=None):
        """set the visibility of the barcamp"""
        email = self.request.form.get("email")
        user = self.app.module_map.userbase.get_user_by_email(email)
        if user is None:
            self.flash(
                "Ein Benutzer mit dieser E-Mail-Adresse wurde leider nicht gefunden.",
                category="error")
            return redirect(self.url_for("barcamp_permissions", slug=slug))

        uid = str(user._id)
        if uid not in self.barcamp.admins:
            self.barcamp.add_admin(user)
            self.barcamp.save()
            self.flash(u"%s ist nun ebenfalls ein Admin für dieses Barcamp." %
                       user.fullname)

        return redirect(self.url_for("barcamp_permissions", slug=slug))
Exemplo n.º 53
0
 def delete(self, slug = None, page_slug = None):
     """delete a page"""
     self.page.remove()
     self.flash(self._(u"the page has been deleted"))
     if self.barcamp is not None:
         url = self.url_for("barcamps.index", slug = self.barcamp.slug)
     else:
         url = self.url_for("index")
     return redirect(url)
Exemplo n.º 54
0
 def post(self, slug = None):
     """set the workflow state for the barcamp"""
     try:
         self.barcamp.set_workflow(self.request.form.get("wf",""))
         self.barcamp.save()
     except WorkflowError, e:
         print e
         self.flash(self._("you cannot perform this action."), category="error")
         return redirect(self.url_for(".admin_wizard", slug=slug))
Exemplo n.º 55
0
    def get(self, slug=None):
        """render the view"""
        form = DuplicateForm(self.request.form, config=self.config)
        slugify = UniqueSlugify(separator='_', max_length=50, to_lower=True)

        if self.request.method == 'POST' and form.validate():

            f = form.data

            # as a test just copy everything by just changing the existing camp
            self.barcamp.name = self._("Copy of ") + self.barcamp.name
            new_slug = slugify(self.barcamp.name)
            while self.config.dbs.barcamps.by_slug(new_slug):
                new_slug = new_slug + "_1"

            self.barcamp.slug = new_slug
            self.barcamp.workflow = "created"
            self.barcamp.registration_data = {}

            # either delete all events or just the people
            if "events" not in self.request.form:
                self.barcamp.events = {}
            else:
                for eid, event in self.barcamp.events.items():
                    event['participants'] = []
                    event['maybe'] = []
                    event['waiting_list'] = []
                    event['timetable']['sessions'] = {}
                    self.barcamp.events[eid] = event

            # delete ticket classes if switched off
            if "tickets" not in self.request.form:
                self.barcamp.ticket_classes = []
            else:
                # if events are deleted we need to delete them from the tickets, too
                if "events" not in self.request.form:
                    new_tcs = []
                    for tc in self.barcamp.ticket_classes:
                        tc['events'] = []
                        new_tcs.append(tc)
                    self.barcamp.ticket_classes = new_tcs

            # create new pad uids
            self.barcamp.planning_pad = unicode(uuid.uuid4())
            self.barcamp.documentation_pad = unicode(uuid.uuid4())

            # make it a new one
            self.barcamp['_id'] = ObjectId()

            barcamp = self.config.dbs.barcamps.put(self.barcamp)
            self.flash(self._("The barcamp has been duplicated."),
                       category="info")
            return redirect(
                self.url_for("barcamps.edit", slug=self.barcamp.slug))

        return self.render(form=form)
Exemplo n.º 56
0
 def delete(self, slug=None):
     """delete a form entry"""
     idx = self.request.args.get("idx", None)
     rf = self.barcamp.registration_form
     if idx is not None and int(idx) < len(rf) and int(idx) >= 0:
         del self.barcamp.registration_form[int(idx)]
         self.barcamp.save()
     return redirect(
         self.url_for("barcamps.registration_form_editor",
                      slug=self.barcamp.slug))
Exemplo n.º 57
0
Arquivo: view.py Projeto: cryu/camper
 def delete(self, slug = None, page_slug = None):
     """delete a page"""
     # TODO: delete page
     self.page.remove()
     self.flash(u"Die Seite wurde erfolgreich gelöscht")
     if self.barcamp is not None:
         url = self.url_for("barcamp", slug = self.barcamp.slug)
     else:
         url = self.url_for("index")
     return redirect(url)
Exemplo n.º 58
0
    def get(self):
        """show the form for entering a new password."""
        cfg = self.module.config
        mod = self.module

        # check pw code which comes via URL
        code = self.request.args.get("code", None)
        if code is None:
            self.flash(
                "The URL is missing a code for the password reset. Please enter the email address you registered with to receive a proper link",
                category="danger")
            url = self.url_for("userbase.pw_forgot")
            return redirect(url)

        user = mod.get_user_by_pw_code(code)
        if user is None:
            self.flash(
                "We couldn't find a user with that code, please try again",
                category="danger")
            url = self.url_for("userbase.pw_forgot")
            return redirect(url)

        # check for expiration time
        if user.pw_code_expires < datetime.datetime.now():
            self.flash("The code has expired, please try again",
                       category="danger")
            url = self.url_for("userbase.pw_forgot")
            return redirect(url)

        form = cfg.pw_change_form(self.request.form)

        if self.request.method == 'POST':
            if form.validate():
                f = form.data
                # send out pw forgot code and redirect to code sent success screen
                user.password = f['password']
                user.pw_code = None
                user.save()
                self.flash(self._(u'Your password has been changed') % user)
                url_for_params = cfg.urls.pw_code_success
                url = self.url_for(**url_for_params)
                return redirect(url)
        return self.render(form=form, code=code)