Пример #1
0
def create(request):
    user = UserForm(request.POST)
    if user.is_valid():
        user.save()
        return HttpResponse("Successfully create new account")
    else:
        return HttpResponse("Your input data is not valid </br>" + str(user._errors))
Пример #2
0
def sign_up(request):
    if request.method == 'POST':
        params = request.POST.copy()
        
        params['password'] = make_password(params['password'])
        params['created_at'] = timezone.now()
        params['updated_at'] = timezone.now()
        params['date_joined'] = timezone.now()
        params['last_login'] = timezone.now()

        form = UserForm(data = params, auto_id=True)
        
        if form.is_valid():
            user = form.save()
            user.is_active = True
            user.save()
            
            form_msg = _("the user was successfully registered")
            return render(request, 'users/_sign_up_success.html', {'form_msg': form_msg})
        else:
            form_errors = form.errors
#           form_cleaned = form.cleaned_data
            return render(request, 'users/_sign_up_errors.html', {'form_errors': form_errors})
    else:
        form = UserForm(auto_id=True)
        context = {'form': form}
        return render(request, 'home/index.html', context)
Пример #3
0
def personal_data(request):
    results = {}
    if request.is_ajax():
        form = DoctorForm(request.POST, instance=request.user.userprofile.current_doctor)
        user_form = UserForm(request.POST, instance=request.user.userprofile.current_doctor.refer_userprofile.user)
        if form.is_valid() and user_form.is_valid():
            form.save()
            user_form.save()
            results['return'] = True
        else:
            print
            results['errors'] = form.errors + user_form.errors
            results['return'] = False
    else:
        results['return'] = False
    return HttpResponse(json.dumps(results))
Пример #4
0
def personal_data(request):
    results = {}
    if request.is_ajax():
        user_form = UserForm(request.POST, instance=request.user)
        userprofile_form = UserProfileForm(request.POST, instance=request.user.userprofile)
        if user_form.is_valid() and userprofile_form.is_valid():
            user_form.save()
            userprofile_form.save()
            results['return'] = True
        else:
            combo = userprofile_form.errors
            combo.update(user_form.errors)
            results['errors'] = combo
            results['return'] = False
    else:
        results['return'] = False
    return HttpResponse(json.dumps(results))
Пример #5
0
def register(request):
	# Redirect user if already logged in.
	if request.user:
		if request.user.is_authenticated():
			return HttpResponseRedirect('/home')

	# 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():
			# Save the user's form data to the database.
			user = user_form.save()

			# 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()

			# 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

			# 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.save()

			return HttpResponseRedirect('/home')

		# Invalid form or forms - mistakes or something else?
		# Print problems to the terminal.
		# They'll also be shown to the user.
		else:
			context_dict = {
				'user_form': user_form,
				'profile_form': profile_form,
			}
			return render(request, 'index.html', context_dict)

	# Not a HTTP POST, this should never happen
	else:
		context_dict = {
			'user_form': UserForm(),
			'profile_form': UserProfileForm(),
			'error_messages': ['Invalid HTTP request.']
		}
		return render(request,'index.html',context_dict)
Пример #6
0
def edit_user(request, username):
    profile = None
    try:
        user = User.objects.get(username=username)
        try:
            profile = user.profile
        except Profile.DoesNotExist:
            pass # ! Just go ahead !
    except User.DoesNotExist:
        return redirect(home)

    if request.user.has_perm('auth.change_user') or request.user.username == username:
        if request.method == 'POST':
            form = UserForm(request.POST, instance=user)

            if profile:
                profile_form = ProfileForm(request.POST, instance = profile)
            else:
                profile_form = ProfileForm(request.POST)

            if form.is_valid():
                updated_user = form.save()
                if profile_form.is_valid():
                    new_profile = profile_form.save(commit=False)
                    new_profile.user = updated_user
                    new_profile.save()

                return redirect(user_profile, username=username)
        else:
            form = UserForm(instance=user)
            if profile:
                profile_form = ProfileForm(instance=profile)
            else:
                profile_form = ProfileForm()

        context = {'form': form,
                    'username': username,
                    'profile_form': profile_form,
        }

        return render(request, "edit_user.html", context)

    return redirect(home)
Пример #7
0
 def post(self, request, *args, **kwargs):
     #user = self.instance.user
     user = EvoUser.objects.get(pk=request.user.id)
     
     form_class = self.get_form_class()
     
     params = request.POST.copy()
     params['password']   = user.password
     params['created_at'] = user.created_at
     params['updated_at'] = timezone.now()
     params['date_joined']= user.date_joined
     params['last_login'] = user.last_login
     
     form = UserForm(data = params, instance=user, auto_id=True)
    
     if form.is_valid():
         user = form.save()
         form_msg = _("the user was successfully registered")
         return render(request, 'users/_edit_success.html', {'form_msg': form_msg})
     else:
         form_errors = form.errors
         form_cleaned = form.cleaned_data
         return render(request, 'users/_edit_errors.html', {'form_errors': form_errors})
Пример #8
0
def register_social(request):
	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():
			# Save the user's form data to the database.
			user = user_form.save()

			# 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()

			# 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

			# 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.save()

			user.backend = 'django.contrib.auth.backends.ModelBackend'
			login(request, user)

			backend = request.session['partial_pipeline']['backend']
			return redirect('social:complete', backend=backend)

		# 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)

			context_dict = {
				'user_form': user_form,
				'profile_form': profile_form,
				'backend': request.session['partial_pipeline']['backend'],
			}

			return render(request, 'register_social.html', context_dict)

	else:
		partial_user_data = request.session.get('partial_user_data')

		context_dict = {
			'user_form': UserForm(initial=partial_user_data),
			'profile_form': UserProfileForm(),
			'backend': request.session['partial_pipeline']['backend'],
		}

		request.session.pop('partial_user_data')

		return render(request, 'register_social.html', context_dict)