Exemple #1
0
    def view_home(self):
        request = self.request
        my_bootstrap.need()    # we need css
        log.debug("Locale: " + get_locale_name(request))
        if not request.POST and self.logged_in and self.user:
            data = {'HomeForm--yourmail': self.user.email,
                    'HomeForm--yourname': self.user.username
                    }
        else:
            data = None
        form = home_form(request, data=request.POST or data)
        if request.POST and form.validate():  # if submitted and and valid, create Pot and participant, and then go to pot site
            log.debug("gutes Formular!")
            pot = Pot(form.potname.value)
            DBSession.add(pot)
            participant = Participant(name=form.yourname.value, email=form.yourmail.value)
            pot.participants.append(participant)
            if form .yourmail.value:
                mails.new_pot_mail(request, pot, participant, request.route_url('pot', identifier=participant.identifier))
            if self.logged_in:
                self.user.participations.append(participant)
            return HTTPFound(location=request.route_url('pot', identifier=participant.identifier))

        log.debug("Form: %s with model %s", str(id(form)), str(form.model))
        log.debug("Field: %s", str(id(form.potname)))
        log.debug("Form has errors? %s", str(form.errors))
        return {'form': form, 'logged_in': self.logged_in}
Exemple #2
0
def view_register(context, request):
    my_bootstrap.need()    # we need css
    form = register_form(request)
    if request.POST and form.validate():  # if submitted and and valid, create user
        existing_user = DBSession.query(User).filter_by(username=form.username.value).first()  # check for eyisting user with this name, returns existing user or None
        if not existing_user:
            user = User(form.username.value, form.yourmail.value, form.password.value)
            DBSession.add(user)
            return HTTPFound(location=request.route_url('home'))
        else:
            log.debug("Register failed for {0}".format(form.username.value))
            request.session.flash(_(u'username already taken. Please choose another username.'), 'error')
    return {'form': form, 'logged_in': authenticated_userid(request)}