def newVolRegistration(request): ''' Renders a form for a new vol registration. A vols account is considered to be active if he is found in the list of the selected vols. ''' # A user who is logged in cannot register! if 'logged_in' in request.session and request.session['logged_in'] == True: # Redirect to dashboard return HttpResponseRedirect(reverse( 'dashboard', kwargs = { 'user_id': request.user.id, }, )) # Otherwise, create a registration form form = NewVolRegistrationForm() # If the form has been submitted if request.method == 'POST': # Fill the form with post data form = NewVolRegistrationForm(request.POST) if form.is_valid(): # If the form is valid, create the new user after checking roll number in the list of selected vols. inputs = form.cleaned_data if confirmVolSelection(inputs['roll_number']): try: user = User.objects.get(username=inputs['roll_number']) except User.DoesNotExist: user = User.objects.create_user(username = inputs['roll_number'], email = inputs['email'], password = inputs['password']) user.first_name, user.last_name = inputs['first_name'], inputs['last_name'] user.is_active = True user.groups.add(9) user.save() userprofile = UserProfile(user = user, unique_id = inputs['roll_number'], phone_number = inputs['phone_number']) userprofile.save() return render_to_response('newVolRegistrations/registration_success.html', locals(), context_instance=RequestContext(request)) if not user.is_active: user.is_active = True user.save() return render_to_response('newVolRegistrations/registration_done.html', locals(), context_instance=RequestContext(request)) else: error_msg = ''' It seems like you are not a vol selected this year. ''' return render_to_response('misc/error.html', locals(), context_instance = RequestContext(request)) # Otherwise, render the form # new_vol_reg = bool_vol_reg return render_to_response('newVolRegistrations/register_OFF.html', locals(), context_instance = RequestContext(request))
def generateNewVolAccounts(request): if not request.user.is_superuser: return HttpResponseForbidden('You are not authorized to view this page.') if not request.user.username == 'AE11B004': return HttpResponseForbidden('You are not authorized to run this view. Contact Anant.') form = CreateVolAccountsForm() showStats = False # For template rendering if request.method == 'POST': # assert False form = CreateVolAccountsForm(request.POST, request.FILES) # if form.is_valid(): vols = [] # assert False # Try to parse the file and extract the vols' roll_numbers one by one from the file for line in request.FILES['volfile']: # Remove the end-of-line character from the line line = line.replace('\n', '').replace('\r', '') # Ignore blank lines if line == '': continue vol_roll = line # assert False vols.append(vol_roll) numVolAccountsRequested = 0 volAccountsActivated = [] volAccountsCreated = [] for vol_roll in vols: numVolAccountsRequested += 1 try: user = User.objects.get(username=vol_roll) except User.DoesNotExist: user = User.objects.create_user(username = vol_roll, email = vol_roll.lower()+'@smail.iitm.ac.in', password = vol_roll) user.is_active = True user.save() userprofile = UserProfile(user = user, unique_id = vol_roll) userprofile.save() user.groups.add(9) volAccountsCreated.append(vol_roll) if not user.is_active: user.is_active = True user.save() volAccountsActivated.append(vol_roll) showStats = True return render_to_response('newVolRegistrations/volAccountsCreation.html', locals(), context_instance = RequestContext(request))
def register(request): ''' Renders a form for a new user registration. The user is accepted only after moderation by a member of the managerial team or advisory committee. ''' # A user who is logged in cannot register! if 'logged_in' in request.session and request.session['logged_in'] == True: # Redirect to dashboard return HttpResponseRedirect(reverse( 'dashboard', kwargs = { 'user_id': request.user.id, }, )) # Otherwise, create a registration form form = RegistrationForm() # If the form has been submitted if request.method == 'POST': # Fill the form with post data form = RegistrationForm(request.POST) if form.is_valid(): # If the form is valid, create the new user, but set the account as inactive inputs = form.cleaned_data user = User.objects.create_user(username = inputs['username'], email = inputs['email'], password = inputs['password']) user.first_name, user.last_name = inputs['first_name'], inputs['last_name'] user.is_active = False user.save() userprofile = UserProfile(user = user, unique_id = inputs['unique_id'], phone_number = inputs['phone_number']) userprofile.save() return render_to_response('users/registration_success.html', locals(), context_instance = RequestContext(request)) # Otherwise, render the form return render_to_response('users/register.html', locals(), context_instance = RequestContext(request))