예제 #1
0
def connect_move():
    form = MovementSensorForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        MovementSensor.create(secret_key=form.secret_key.data)
        flash("Successfully connected movement sensor!", 'success')
        return redirect(url_for('user.connections'))
    else:
        flash_errors(form)
    return render_extensions('users/connect_movement_sensor.html', form=form)
예제 #2
0
def change_password():
    form = PasswordForm()
    if form.validate_on_submit():
        current_user.set_password(form.password.data)
        current_user.save()
        return redirect(url_for('user.profile'))
    else:
        flash_errors(form)

    return render_extensions('users/change_password.html', resetform=form)
예제 #3
0
def connect_hr():
    form = HrSensorForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        HeartRateSensor.create(client_id=form.client_id.data,
                               client_secret=form.client_secret.data)
        flash("Successfully connected movement sensor!", 'success')
        return redirect(url_for('user.connections'))
    else:
        flash_errors(form)
    return render_extensions('users/connect_hr_sensor.html', form=form)
예제 #4
0
def home():
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash("You are logged in.", 'success')
            redirect_url = request.args.get("next") or url_for("user.profile")
            return redirect(redirect_url)
        else:
            flash_errors(form)
    return render_extensions("public/home.html", form=form)
예제 #5
0
def register():
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        new_user = User.create(username=form.username.data,
                               first_name=form.first_name.data,
                               last_name=form.last_name.data,
                               email=form.email.data,
                               password=form.password.data,
                               active=True)
        flash("Thank you for registering. You can now log in.", 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_extensions('public/register.html', form=form)
예제 #6
0
def connect_cr():
    form = CareReceiverForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        new_user = CareReceiver.create(first_name=form.first_name.data,
                                       last_name=form.last_name.data,
                                       age=int(form.age.data),
                                       weight=int(form.weight.data),
                                       height=int(form.height.data),
                                       sex=int(form.sex.data))
        flash("Successfully added a caregiver!", 'success')
        return redirect(url_for('user.connections'))
    else:
        flash_errors(form)
    return render_extensions('users/connect_carerecv.html', form=form)
예제 #7
0
def reset_with_token(token):
    try:
        from pulser.settings import Config

        ts = URLSafeTimedSerializer(Config.SECRET_KEY)
        email = ts.loads(token, salt="recover-key", max_age=86400)
    except:
        return render_template("404.html")

    form = PasswordForm()

    if form.validate_on_submit():
        emailuser = User.query.filter_by(email=email).first_or_404()
        emailuser.set_password(form.password.data)
        emailuser.save()
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)

    return render_extensions('users/reset_with_token.html',
                             resetform=form,
                             token=token)
예제 #8
0
def reset():
    form = EmailForm()
    if form.validate_on_submit():
        emailuser = User.query.filter_by(email=form.email.data).first_or_404()

        subject = "Password reset requested"
        from pulser.settings import Config

        ts = URLSafeTimedSerializer(Config.SECRET_KEY)
        token = ts.dumps(emailuser.email, salt='recover-key')

        recover_url = url_for('user.reset_with_token',
                              token=token,
                              _external=True)
        html = render_template('email/recover.html', recover_url=recover_url)

        msg = Message(html=html, recipients=[emailuser.email], subject=subject)
        mail.send(msg)

        return redirect(url_for('public.home'))
    else:
        flash_errors(form)

    return render_extensions('users/reset.html', resetform=form)