Exemplo n.º 1
0
def register_view(request):
    # Authentication check. Users logged in cannot view this page.
    if request.user.is_authenticated():
        return HttpResponseRedirect('/profile/')
    elif Account.objects.all().count() == 0:
        return HttpResponseRedirect('/setup/')
    # Get the template data from the session
    template_data = views.parse_session(request, {'form_button': "Register"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = PatientRegisterForm(request.POST)
        if form.is_valid():
            views.register_user(
                form.cleaned_data['email'],
                form.cleaned_data['password_first'],
                form.cleaned_data['firstname'],
                form.cleaned_data['lastname'],
                Account.ACCOUNT_PATIENT,
                form.cleaned_data['insurance']
            )
            user = authenticate(
                username=form.cleaned_data['email'].lower(),  # Make sure it's lowercase
                password=form.cleaned_data['password_first']
            )
            logger.log(Action.ACTION_ACCOUNT, "Account login", user.account)
            login(request, user)
            request.session['alert_success'] = "Successfully registered with HealthNet."
            return HttpResponseRedirect('/profile/')
    else:
        form = PatientRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/register.html', template_data)
Exemplo n.º 2
0
def setup_view(request):
    if Account.objects.all().count() > 0:
        request.session['alert_success'] = "Setup has already been completed."
        return HttpResponseRedirect('/')
    # Get the template data from the session
    template_data = views.parse_session(request, {'form_button': "Register"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = AccountRegisterForm(request.POST)
        if form.is_valid():
            views.register_user(
                form.cleaned_data['email'],
                form.cleaned_data['password_first'],
                form.cleaned_data['firstname'],
                form.cleaned_data['lastname'],
                Account.ACCOUNT_ADMIN
            )
            user = authenticate(
                username=form.cleaned_data['email'].lower(),  # Make sure it's lowercase
                password=form.cleaned_data['password_first']
            )
            logger.log(Action.ACTION_ACCOUNT, "Account login", user.account)
            login(request, user)
            request.session['alert_success'] = "Successfully setup HealthNet's primary admin account."
            return HttpResponseRedirect('/profile/')
    else:
        form = AccountRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/setup.html', template_data)
Exemplo n.º 3
0
def register_view(request):
    # Authentication check. Users logged in cannot view this page.
    if request.user.is_authenticated():
        return HttpResponseRedirect('/profile/')
    elif Account.objects.all().count() == 0:
        return HttpResponseRedirect('/setup/')
    # Get the template data from the session
    template_data = views.parse_session(request, {'form_button': "Register"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = PatientRegisterForm(request.POST)
        if form.is_valid():
            views.register_user(form.cleaned_data['email'],
                                form.cleaned_data['password_first'],
                                form.cleaned_data['firstname'],
                                form.cleaned_data['lastname'],
                                Account.ACCOUNT_PATIENT,
                                form.cleaned_data['insurance'])
            user = authenticate(
                username=form.cleaned_data['email'].lower(
                ),  # Make sure it's lowercase
                password=form.cleaned_data['password_first'])
            logger.log(Action.ACTION_ACCOUNT, "Account login", user.account)
            login(request, user)
            request.session[
                'alert_success'] = "Successfully registered with HealthNet."
            return HttpResponseRedirect('/profile/')
    else:
        form = PatientRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/register.html', template_data)
Exemplo n.º 4
0
def setup_view(request):
    if Account.objects.all().count() > 0:
        request.session['alert_success'] = "Setup has already been completed."
        return HttpResponseRedirect('/')
    # Get the template data from the session
    template_data = views.parse_session(request, {'form_button': "Register"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = AccountRegisterForm(request.POST)
        if form.is_valid():
            views.register_user(form.cleaned_data['email'],
                                form.cleaned_data['password_first'],
                                form.cleaned_data['firstname'],
                                form.cleaned_data['lastname'],
                                Account.ACCOUNT_ADMIN)
            user = authenticate(
                username=form.cleaned_data['email'].lower(
                ),  # Make sure it's lowercase
                password=form.cleaned_data['password_first'])
            logger.log(Action.ACTION_ACCOUNT, "Account login", user.account)
            login(request, user)
            request.session[
                'alert_success'] = "Successfully setup HealthNet's primary admin account."
            return HttpResponseRedirect('/profile/')
    else:
        form = AccountRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/setup.html', template_data)
Exemplo n.º 5
0
def createemployee_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request,
                                                       [Account.ACCOUNT_ADMIN])
    if authentication_result is not None: return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request, {'form_button': "Register"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = EmployeeRegisterForm(request.POST)
        if form.is_valid():
            user = views.register_user(form.cleaned_data['email'],
                                       form.cleaned_data['password_first'],
                                       form.cleaned_data['firstname'],
                                       form.cleaned_data['lastname'],
                                       form.cleaned_data['employee'])
            logger.log(Action.ACTION_ADMIN,
                       'Admin registered ' + user.username,
                       request.user.account)
            request.session[
                'alert_success'] = "Successfully created new employee account."
            return HttpResponseRedirect('/admin/users/')
    else:
        form = EmployeeRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/admin/createemployee.html',
                  template_data)
Exemplo n.º 6
0
def createemployee_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN])
    if authentication_result is not None: return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(
        request,
        {'form_button': "Register"}
    )
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = EmployeeRegisterForm(request.POST)
        if form.is_valid():
            user = views.register_user(
                form.cleaned_data['email'],
                form.cleaned_data['password_first'],
                form.cleaned_data['firstname'],
                form.cleaned_data['lastname'],
                form.cleaned_data['employee']
            )
            logger.log(Action.ACTION_ADMIN, 'Admin registered ' + user.username, request.user.account)
            request.session['alert_success'] = "Successfully created new employee account."
            return HttpResponseRedirect('/admin/users/')
    else:
        form = EmployeeRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/admin/createemployee.html', template_data)
Exemplo n.º 7
0
def handle_user_csv(f):
    """
    Handles a CSV containing User information.
    The first row should contain the following information
        FirstName,LastName,Account,Username,Email,Hospital
    with the following lines containing information about zero or more Users.
    :param f: The file object containing the CSV
    :return: The # of successes and failures
    """
    success = 0
    fail = 0
    is_first = True
    for row in f:
        if is_first:
            is_first = False
            continue    # breaks out of for loop
        line = re.split('[,]', row.decode("utf-8").strip())
        if line[0]:
            f_name = line[0]
            l_name = line[1]
            role = line[2].lower()
            username = line[3].lower()
            insurance = line[4]
            try:
                if role == "doctor":
                    views.register_user(
                        username, 'password', f_name, l_name,
                        Account.ACCOUNT_DOCTOR,
                        )
                elif role == "nurse":
                    views.register_user(
                        username, 'password', f_name, l_name,
                        Account.ACCOUNT_NURSE,
                        )
                elif role == "admin":
                    views.register_user(
                        username, 'password', f_name, l_name,
                        Account.ACCOUNT_ADMIN,
                        )
                else:
                    views.register_user(
                        username, 'password', f_name, l_name,
                        Account.ACCOUNT_PATIENT,
                        insurance,
                        )
                success += 1
            except (IntegrityError, ValueError):
                fail += 1
                continue
    return success, fail
Exemplo n.º 8
0
def handle_user_csv(f):
    """
    Handles a CSV containing User information.
    The first row should contain the following information
        FirstName,LastName,Account,Username,Email,Hospital
    with the following lines containing information about zero or more Users.
    :param f: The file object containing the CSV
    :return: The # of successes and failures
    """
    success = 0
    fail = 0
    is_first = True
    for row in f:
        if is_first:
            is_first = False
            continue    # breaks out of for loop
        line = re.split('[,]', row.decode("utf-8").strip())
        if line[0]:
            f_name = line[0]
            l_name = line[1]
            role = line[2].lower()
            username = line[3].lower()
            insurance = line[4]
            try:
                if role == "doctor":
                    views.register_user(
                        username, 'password', f_name, l_name,
                        Account.ACCOUNT_DOCTOR,
                        )
                elif role == "nurse":
                    views.register_user(
                        username, 'password', f_name, l_name,
                        Account.ACCOUNT_NURSE,
                        )
                elif role == "admin":
                    views.register_user(
                        username, 'password', f_name, l_name,
                        Account.ACCOUNT_ADMIN,
                        )
                else:
                    views.register_user(
                        username, 'password', f_name, l_name,
                        Account.ACCOUNT_PATIENT,
                        insurance,
                        )
                success += 1
            except (IntegrityError, ValueError):
                fail += 1
                continue
    return success, fail