예제 #1
0
def signup():
    form = SignupForm(next=request.args.get("next"))

    if form.validate_on_submit():
        user = User()
        form.populate_obj(user)
        user.save()
        # Flask-Login
        login_user(user)

        # Flask-principal
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(user.username))

        flash(u"欢迎, %s" % user.username, "successfully")
        next_url = form.next.data
        if not next_url or next_url == request.path:
            next_url = url_for('user.posts', username=user.username)

        return redirect(next_url)
    return render_template("account/signup.html", form=form)
예제 #2
0
파일: account.py 프로젝트: beachmg/raychen
def signup():
    form = SignupForm(next=request.args.get("next"))

    if form.validate_on_submit():        
        user = User()
        form.populate_obj(user)
        user.save()
        # Flask-Login
        login_user(user)
        
        # Flask-principal
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(user.username))

        flash(u"欢迎, %s" % user.username, "successfully")
        next_url = form.next.data
        if not next_url or next_url == request.path:
            next_url = url_for('user.posts', username=user.username)

        return redirect(next_url)
    return render_template("account/signup.html", form=form)
예제 #3
0
def edit_user():
    user = User.query.get(current_user.id)
    edit_form = SignupForm()
    edit_form.populate_obj(user)
    return user.to_dict()
예제 #4
0
def edit_participant(timeslot_id, participant_id):
    """ Admin edit signed up participants, allows to do changes
        on an already signed up particpant """
    event = Events.query.filter(Events.active).first()
    slot = TimeSlots.query.get_or_404(timeslot_id)
    participant = Participants.query.get_or_404(participant_id)
    form = SignupForm(request.form, obj=participant)
    if event != None:
        eventid = event.id
        timeslots = TimeSlots.query.filter(TimeSlots.event_id == eventid).all()
        if timeslots != None:
            [available_slots_choices,
             available_special_slots_choices] = get_slots_choices(timeslots)
            form.availableslots.choices = available_slots_choices
            form.availablespecialslots.choices = available_special_slots_choices
    form.birthday.data = participant.birthday.strftime("%d.%m.%Y")
    form.email2.data = participant.email
    if len(available_slots_choices) > 0:
        for i in range(0, len(available_slots_choices)):
            if participant.slot in available_slots_choices[i]:
                form.availableslots.data = [participant.slot]
    if len(available_special_slots_choices) > 0:
        for i in range(0, len(available_special_slots_choices)):
            if participant.slot in available_special_slots_choices[i]:
                form.availablespecialslots.data = [participant.slot]

    if request.method == 'POST' and form.validate():
        try:
            form.populate_obj(participant)
            email = str(request.form['email'])
            email2 = str(request.form['email2'])
            if email != email2:
                message = 'Deine Mailadressen stimmen nicht überein!\
                Bitte geh zurück und korrigiere die Mailadresse.'

                return render_template('error.html', message=message)
            gender = Gender(int(request.form['gender']))
            birthday = str(request.form['birthday'])
            participant.birthday = datetime.strptime(birthday, '%d.%m.%Y')
            participant.gender = gender
            availablespecialslots = None
            if event.special_slots:
                availablespecialslots = request.form.getlist(
                    'availablespecialslots')
            availableslots = request.form.getlist('availableslots')
            slots = 0
            if availableslots:
                slots = int(availableslots[0])
            elif availablespecialslots:
                slots = int(availablespecialslots[0])
            else:
                message = 'Du hast kein passendes Datum ausgewählt!\
                Bitte geh zurück und wähle ein dir passendes Datum aus.'

                return render_template('error.html', message=message)
            participant.slot = int(slots)
            db.session.commit()
        except Exception as e:
            print('Exception of type {} occurred: {}'.format(type(e), str(e)))
            return render_template('error.html')
        return redirect(request.referrer)
    return render_template('edit_participant.html',
                           form=form,
                           event=event,
                           slot=slot,
                           participant=participant)