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 template data from session template_data = views.parse_session(request, {'form_button': "Register"}) # Proceed with 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'], # form.cleaned_data['speciality'], Account.ACCOUNT_PATIENT) user = authenticate(username=form.cleaned_data['email'].lower(), 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 VirtualClinic." return HttpResponseRedirect('/profile/') else: form = AccountRegisterForm() template_data['form'] = form return render(request, 'virtualclinic/register.html', template_data)
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() try: if role== "doctor": views.register_user( username,'password',f_name,l_name, Account.ACCOUNT_DOCTOR, ) elif role == "admin": views.register_user( username, 'password', f_name, l_name, Account.ACCOUNT_ADMIN, ) elif role == "lab": views.register_user( username, 'password', f_name, l_name, Account.ACCOUNT_LAB, ) elif role == "chemist": views.register_user( username, 'password', f_name, l_name, Account.ACCOUNT_CHEMIST, ) else: views.register_user( username, 'password', f_name, l_name, Account.ACCOUNT_PATIENT, ) success+=1 except (IntegrityError, ValueError): fail+=1 continue return success,fail