Пример #1
0
def user_registration(request):
    try:
        emp = EmployeeInfo.objects.all().get(user = request.user )
    except EmployeeInfo.DoesNotExist:
        emp = None
    if request.user.is_authenticated() and emp is not None and (emp.is_Admin or emp.is_HOD or emp.is_Manager ) :
        if request.POST :
            userForm = UserForm(request.POST)
            if userForm.is_valid() :
                userForm.save()
                request.session["count1"] += 1
                request.session["username"] = userForm.cleaned_data['username'] 
                return HttpResponseRedirect('../../../' + request.GET["empType"])
            else:
                c = Context({'emp1':emp ,'form':userForm })
                return render_to_response('registration.html', context_instance=RequestContext(request,c))
            
            
        else:
            userForm = UserForm()
            
            #t = get_template('employeeRegistration.html')
            c = Context({'emp1':emp ,'form':userForm})
            return render_to_response('registration.html', context_instance=RequestContext(request,c))
    else:
        return HttpResponseRedirect('../../../login')
Пример #2
0
def createUser(request):

	if request.method == 'POST':		
		
		form = UserForm(request.POST)		
							
		if form.is_valid():

			user = User()
			
			user.birth_date = form.cleaned_data.get('birth_date')
			user.randomId = form.cleaned_data.get('randomId')	
			user.username = form.cleaned_data.get('username')		
			user.password = form.cleaned_data.get('password')							
			user.save()		
			#import pdb; pdb.set_trace()		
			# messages.success(request, 'Form submission successful')
			return redirect('list')
		else:
			form = UserForm(request.POST)
		
		return redirect('add')	
Пример #3
0
def updateUser(request, val):
	
	oldUser = User.objects.get(username=val)

	#oldUser.delete()

	form = UserForm(request.POST)
	
	if form.is_valid():

		oldUser.birth_date = form.cleaned_data.get('birth_date')
		oldUser.randomId = form.cleaned_data.get('randomId')	
		oldUser.username = form.cleaned_data.get('username')		
		oldUser.password = form.cleaned_data.get('password')
		#import pdb; pdb.set_trace()
		oldUser.save()
		# messages.add_message(request, messages.INFO, 'Successfully change the user!')	
		# messages.error = (request, "Hello World")
		# messages.add_message(request, messages.ERROR, 'Why wont')
	else:
		messages.warning(request, "Please input correct data")
		form = UserForm(request.POST)

	return redirect('list')
Пример #4
0
def users_register(request):
    if request.user.is_authenticated:
        return redirect('/')
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = ProfileForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            # set to false to prevent users from login without confirming email
            user.is_active = False
            user.save()


            current_site = get_current_site(request)
            mail_subject = 'Activate your account.'
            message = render_to_string('Users/active_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user)
            })
            to_email = user_form.cleaned_data.get('email')
            email = EmailMessage(
                        mail_subject, message, to=[to_email]
            )
            email.send()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'profile_pic' in request.FILES:
                print('found it')
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()
            registered = True
        else:
            print(user_form.errors,profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = ProfileForm()
    return render(request,'Users/registration.html',
                          {'user_form':user_form,
                           'profile_form':profile_form,
                           'registered':registered})
Пример #5
0
def register(request):

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid() and registered == False:
            # Save the user's form data to the database.
            user = user_form.save()

            #call the userFactory

            user.first_name = request.POST['fname']
            user.last_name = request.POST['lname']
            user.email = request.POST['email']
            user.website = request.POST['website']
            user.custType = request.POST['custType']
            user.phoneNumber = request.POST['phoneNumber']


            try:
                user.address = request.POST['address']
            except:
                print("address not correct")





            print(user.first_name)
            print(user.last_name)

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            profile = UserFactory(user)
            #profile.custType=custType
            # profile = UserFactory(user)

            print("in views, exited factory call")
            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
            # profile = profile_form.save(commit=False)
            # profile.user = user
            # profile.username = user
            # profile.fname = user.first_name
            # profile.lname = user.last_name
            # profile.userEmail = user.email
            # profile.website=user.website
            #profile.picture = request.POST['picture']



            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance.
            #profile.is_Market = False

            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        #elif user_form.is_valid() and profile_form.is_valid() and registered == False:
            #return render(request, '/Users/login.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
            return redirect('/Users/login/')

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print (user_form.errors, profile_form.errors)


    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.

    return render(request,
            'Users/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})