Esempio n. 1
0
def register():
    """Register new user_bp."""
    if current_user and current_user.is_authenticated:
        return redirect(url_for("user_bp.dashboard"))
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        import random
        import string
        lettersAndDigits = string.ascii_letters + string.digits
        rand = random.SystemRandom()
        User.create(username=form.email.data,
                    email=form.email.data,
                    password=form.password.data,
                    phone=form.phone.data,
                    active=True,
                    first_name=form.fname.data,
                    last_name=form.lname.data,
                    gtid=form.gtid.data,
                    sample_id=''.join(
                        (rand.choice(lettersAndDigits) for i in range(16))))
        flash("Thank you for registering.", "success")
        send_welcome(form.email.data, form.fname.data, form.lname.data)
        user = User.query.filter_by(email=form.email.data).first()
        login_user(user)
        result_num = Results.query.filter_by(user_id=user.id).count() + 1
        resultId = f"{user.sample_id}_{result_num}"
        Results.create(user_id=user.id,
                       result_id=resultId,
                       tube_id=form.tubeid.data,
                       updated_time=roundSeconds(dt.datetime.now()))
        return redirect(url_for('user_bp.dashboard'))
    else:
        flash_errors(form)
    return render_template("public/register.html", form=form)
Esempio n. 2
0
def user_info():
    """List participant details"""

    barcode = request.args.get('barcode')
    user = User.query.filter_by(sample_id=barcode.split("_")[0]).first()
    info = UserInfo.query.filter_by(user_id=user.id).first()
    if not info:
        UserInfo.create(user_id=user.id)
        info = UserInfo.query.filter_by(user_id=user.id).first()
        form = userInfoForm(request.form)
    else:
        form = userInfoForm(request.form)
        # form.sex = info.sex
        # form.race = info.race
        # form.ethnicity = info.ethnicity
        # form.process()
    if current_user.is_admin:
        if form.validate_on_submit():
            if user.gtid != form.gtid.data:
                user.gtid = form.gtid.data
                user.save()
            today = dt.date.today()
            dob = form.dob.data
            info.update(
                commit=True,
                age=today.year - dob.year,
                # sex=form.sex.data,
                dob=dob
                # race=form.race.data,
                # ethnicity=form.ethnicity.data,
                # address=form.address.data,
                # zipcode=form.zipcode.data,
                # county=form.county.data
            )
            result = Results.query.filter_by(result_id=barcode).first()
            result.result_text = "Sample received, awaiting processing"
            result.result = None
            result.updated_time = roundSeconds(dt.datetime.now())
            result.save()
            AuditLog.create(
                user_id=user.id,
                result_id=result.id,
                status=f"Specimen received, in tube {result.tube_id}")
            flash('Added sample for processing', 'success')
            return redirect(url_for('manage.sample'))
        else:
            flash_errors(form)
        return render_template("manage/user_info.html",
                               form=form,
                               barcode=barcode,
                               user=user,
                               info=info)
Esempio n. 3
0
def add_tube():
    form = addTubeForm()
    if form.validate_on_submit():
        result_num = Results.query.filter_by(
            user_id=current_user.id).count() + 1
        resultId = f"{current_user.sample_id}_{result_num}"
        Results.create(user_id=current_user.id,
                       result_id=resultId,
                       tube_id=form.tubeid.data,
                       updated_time=roundSeconds(dt.datetime.now()))
        return redirect(url_for('user_bp.dashboard'))
    else:
        flash_errors(form)
    return render_template('users/add_tube.html',
                           title="Associated Tube ID with account",
                           form=form)
Esempio n. 4
0
def forgot():
    """Register new user_bp."""
    user = ''
    if current_user and current_user.is_authenticated:
        user = current_user.username
    form = ForgotForm(request.form)
    if form.validate_on_submit():
        if form.email.data:
            user = User.query.filter_by(email=form.email.data).first()
            if user:
                user.update(recovery_key=get_random_alphaNumeric_string())
                reset_pwd(user.email, user.username, user.recovery_key)
        return redirect(url_for("public.home"))
    else:
        flash_errors(form)
    return render_template("public/forgot.html", forgot=form, un=user)
Esempio n. 5
0
def reset():
    """Register new user_bp."""
    import random
    import string

    form = ResetForm(request.form)
    code = request.args.get("code")
    if form.validate_on_submit():
        if form.code.data:
            user = User.query.filter_by(recovery_key=form.code.data).first()
            if user:
                user.update(recovery_key="")
                user.set_password(form.password.data)
                user.save()
                login_user(user)
        return redirect(url_for("user_bp.dashboard"))
    else:
        flash_errors(form)
    return render_template("public/reset.html", reset=form, code=code)
Esempio n. 6
0
def home():
    """Home page."""
    form = LoginForm(request.form)
    total = Results.query.filter(Results.result.isnot(None)).count()
    if total == 0: total = 1
    positive = Results.query.filter_by(result=True).count()
    negative = Results.query.filter_by(result=False).count()
    # Handle logging in
    if request.method == "POST":
        if form.validate_on_submit():
            login_user(form.user, remember=True)
            flash("You are logged in.", "success")
            redirect_url = request.args.get("next") or url_for(
                "user_bp.dashboard")
            return redirect(redirect_url)
        else:
            flash_errors(form)
    return render_template("public/home.html",
                           form=form,
                           total=total,
                           positive=positive,
                           negative=negative)