Beispiel #1
0
def load_user(unique):
    """
    Loads a user after successfully logging into the app.
    """
    user = User.objects(id=unique)
    if user.count() == 1:
        return user[0]
    return None
Beispiel #2
0
def remove_patient():
    """
    Removes a patient from a physician's list of current patients.
    After, we redirect the user back to the dashboard.
    """
    if request.form['slug'] is None:
        return "An error occurred, please try again later."
    else:
        slug = request.form['slug']
        patient = Patient.objects.get_or_404(slug=slug)
        name = "{} {}".format(patient.first_name, patient.last_name)

        # Remove this patient from the physician's list of active patients.
        User.objects(id=current_user.id).update_one(pull__patients=patient)

        # Remove all physician's config settings on this patient.
        for config in current_user.patient_config:
            if config.patient.id == patient.id:
                current_user.patient_config.filter(patient=patient).delete()

        flash('The patient {} has been removed successfully from your dashboard.'.format(name), 'success')
        return jsonify({"status": 200})
Beispiel #3
0
def register():
    """
    Registers a Physician to use our system. Physicians will be required to
    enter a username, email address, password, and password confirmation.
    """
    form = UserRegistrationForm(request.form)
    if request.method == 'POST':
        try:
            if User.objects(email=form.email.data).count() > 0:
                u = User.objects(email=form.email.data)[0]
                if not u.confirmed:
                    flash("That email address has already been registered, but has not been confirmed. "
                          "Please click the link in the confirmation email to continue.", 'warning')
                    return render_template('register.html', form=form)
        except AttributeError:
            pass  # Users table is empty, so no need to check.

        if form.validate():

            # Create the new user with "unconfirmed" state.
            new_user = User(username=form.username.data.lower(), full_name=form.full_name.data, email=form.email.data)
            new_user.set_password(form.password.data)
            new_user.confirmed = False

            try:
                # Try to save this new user (implicitly validating the uniqueness of email/username)
                new_user.save()

                # Generate and send a confirmation email to this new Physician user
                email_sent = email_physician_confirmation(email=form.email.data, name=form.full_name.data)

                if email_sent:
                    success_msg = "Account successfully created. Please check your email for a confirmation link " \
                                  " in order to login."
                    flash(success_msg, 'success')
                    return redirect('/')
                else:
                    flash('We were unable to send your confirmation email. Please ensure the provided email address " \
                          "is correct.', 'warning')

            except NotUniqueError:
                flash("That username or email is already registered. Please try a different one.", 'warning')

            return render_template('register.html', form=form)

        else:
            flash("Invalid input: please see the suggestions below.", 'warning')
    return render_template('register.html', form=form)
Beispiel #4
0
def admin():
    if str(current_user) != 'admin':
        flash('Error: Restricted Access', 'warning')
        return redirect('/')
    userForms = []
    for user in User.objects():
        form = AdminViewer.AdminUsers(request.form, [user.username, user.email])
        form.username.data = user.username
        form.email.data = user.email
        form.meta = user.id
        userForms.append(form)

    patientForm = AdminViewer.AdminPatients(request.form)
    if request.method == 'POST':
        string = '%s' % request.form.__str__()
        flash(string, 'success')
        return redirect('/admin')
    return render_template('admin.html', userForms=userForms)
Beispiel #5
0
def drop():
    from recover.models import Patient, User, PatientInvite
    PatientInvite.drop_collection()
    Patient.drop_collection()
    User.drop_collection()