示例#1
0
def register(request):
	context = RequestContext(request)

	registered = False

	if request.method == 'POST':
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)

		if user_form.is_valid() and profile_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()

			profile = profile_form.save(commit=False)
			profile.user = user
			profile.save()

			new_user = authenticate(username=request.POST['username'], password=request.POST['password'])
			login(request, new_user)

			registered = True

			return HttpResponseRedirect('/')
		else:
			print(user_form.errors, profile_form.errors)

	else:
		user_form = UserForm()
		profile_form = UserProfileForm()

	return render_to_response(
			'authentication/register.html',
			{'user_form': user_form, 'profile_form': profile_form},
			context)	
示例#2
0
def register(request):	
	registered = False
	if request.method == "POST":
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)
		print profile_form
		print request.FILES['picture']
		if user_form.is_valid() and profile_form.is_valid():
			
			user = user_form.save(commit=False)
			user.set_password(user.password)
			user.is_active=True
			user.save()
			profile = profile_form.save(commit=False)
			profile.user = user
			profile.lastLoginDate = datetime.now()
			profile.ipaddress=get_client_ip(request)
			if request.FILES['picture']:
				profile.picture = request.FILES['picture']
			profile.save()
			registered = True
		else:
			print user_form.errors, profile_form.errors
			messages.info(request,str(user_form.errors)+str(profile_form.errors))
	else:
		user_form = UserForm()
		profile_form = UserProfileForm()
	return render(request,'site/register.html',{'title':'Sign Up','current_page':'register',\
		'user_form':user_form,'profile_form':profile_form,'registered':registered})
示例#3
0
def register(request):
    registered = False
    response = {}
    if request.method == "POST":
        method = request.POST['method']
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        mobile_id = request.POST['mobile_id']
        print profile_form
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            user.set_password(user.password)
            user.is_active = True
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.mobile_id = mobile_id
            profile.lastLoginDate = datetime.now()
            profile.ipaddress = get_client_ip(request)
            profile.save()
            registered = True
            response['success'] = 1
        else:
            print user_form.errors, profile_form.errors
            response['success'] = 0
    return JsonResponse(response)
示例#4
0
def register(request):
    register = False
    if request.method == 'POST':
        user_form = UserForm(request.POST)
        print('debug1')
        if user_form.is_valid():
            username = user_form.cleaned_data.get('username')
            password = user_form.cleaned_data.get('password')
            dob = user_form.cleaned_data.get('date_of_birth')
            email = user_form.cleaned_data.get('email')
            print('debug1.1')
            profile_pic = user_form.cleaned_data.get('profile_pic')
            userIDV = random.randint(0, 999999)
            print('debug1.2')
            user = User.objects.create_user(userID=userIDV,
                                            username=username,
                                            date_of_birth=dob,
                                            email=email,
                                            profile_pic=profile_pic,
                                            password=password)
            if 'profile_pic' in request.FILES:
                print('found it')
                user.profile_pic = request.FILES['profile_pic']
            user.save()
            register = True
        else:
            print(user_form.errors)
    else:
        user_form = UserForm()
    return render(request, 'signup.html', {
        'user_form': user_form,
        'registered': register
    })
示例#5
0
def register(request):
    if request.user.is_authenticated():
        return redirect("/")
    else:
        # 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():
                # 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()

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

            # 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,
                'authentication/register.html',
                {'user_form': user_form, 'profile_form': profile_form, 'registered': registered} )
    def post(self, request):
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            user.set_password(user.password)
            user.save()
            login(request, user)
            return redirect('index')

        else:
            return HttpResponse(user_form.errors)
示例#7
0
    def post(self, request):
        user_form = UserForm(data=request.POST)

        if user_form.is_valid():
            user = user_form.save(commit=False)
            user.set_password(user.password)
            user.save()
            return redirect('index')

        else:
            template_response = views.login(request, template_name='authentication/login.html',
                                            extra_context={'signup_form': user_form})
            return template_response
示例#8
0
def signup(request):
	if request.user.is_authenticated():
		request.session['username']=request.user.username;
		return HttpResponseRedirect('/authentication/profile')
	elif request.method=="POST":
		signupform=UserForm(request.POST)
		if signupform.is_valid():
			new_user=User.objects.create_user(**signupform.cleaned_data)
			new_user.backend='django.contib.auth.backends.ModelBackend'
			messages.add_message(request,messages.SUCCESS,'Succesfully registered')
			return HttpResponseRedirect('/authentication/signup')
		else:
			return render(request,'authentication/signup.html',{'form':signupform})
	else:
		signupform=UserForm()
		return render(request,'authentication/signup.html',{'form':signupform})
示例#9
0
def logout_user(request):
    logout(request)
    form = UserForm(request.POST or None)
    context = {
        "form": form,
    }
    return render(request, 'authentication/login.html', context)
示例#10
0
def create_user(request):
    # u = User()
    # u.username = "******"
    # u.password = "******"
    # u.save()
    form = UserForm()
    return render(request, "authentication/auth_create.html", locals())
示例#11
0
def Login(request):
    """
    Adds signup form as an extra context variable
    """
    signup_form = UserForm()
    template_response = views.login(request, template_name='authentication/login.html',
                                    extra_context={'signup_form': signup_form})
    return template_response
示例#12
0
def register(request):
    form = UserForm(request.POST or None)
    if form.is_valid():
        user = form.save(commit=False)
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        user.set_password(password)
        user.save()
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                boutiques = Boutique.objects.filter(user=request.user)
                return render(request, 'produit/index.html', {'boutique': boutiques})
    context = {
        "form": form,
    }
    return render(request, 'authentication/register.html', context)
示例#13
0
def register(request):
    registered = False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        print profile_form
        print request.FILES['picture']
        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save(commit=False)
            user.set_password(user.password)
            user.is_active = True
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.lastLoginDate = datetime.now()
            profile.ipaddress = get_client_ip(request)
            if request.FILES['picture']:
                profile.picture = request.FILES['picture']
            profile.save()
            registered = True
        else:
            print user_form.errors, profile_form.errors
            messages.info(request,
                          str(user_form.errors) + str(profile_form.errors))
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render(request,'site/register.html',{'title':'Sign Up','current_page':'register',\
     'user_form':user_form,'profile_form':profile_form,'registered':registered})
示例#14
0
def register(request):
    registered = False

    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            profile.save()
            log.info("NEW USER REGISTERED " + user.username)
            registered = True
        else:
            print(user_form.errors, profile_form.errors)

    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'authentication/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
示例#15
0
def register(request):
    template = 'authentication/register.html'
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()
            registered = True
            #messages.success(request, "Usuario registrado")
            return HttpResponseRedirect(reverse('log:login'))
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    data = {
        'user_form': user_form,
        'profile_form': profile_form,
        'registered': registered
    }
    return render(request, template, data)
示例#16
0
def update(request, id):
    """ Update User data """

    user = get_object_or_404(User, pk=id)

    user_form = UserForm(data=request.POST or None, instance=user)

    profile_form = UserProfileForm(data=request.POST or None,
                                   files=request.FILES or None,
                                   instance=user.userprofile)

    if user_form.is_valid() and profile_form.is_valid():
        user_form.save()
        profile_form.save()
        messages.success(request, 'Usuario actualizado!')

    context = {
        'user_form': user_form,
        'profile_form': profile_form,
        'menu': 'users'
    }
    return render(request, 'users/update.html', context)
示例#17
0
def edit_user(request, pk):
    """
    Update the user profile
    """
    # querying the User object with pk from url
    user = User.objects.get(pk=pk)

    # prepopulate UserProfileForm with retrieved user values from above.
    user_form = UserForm(instance=user)

    # The sorcery begins from here, see explanation below
    ProfileInlineFormset = inlineformset_factory(User,
                                                 UserProfile,
                                                 fields=(
                                                     'type_user',
                                                     'address',
                                                     'bio',
                                                     'website',
                                                     'phonenumber',
                                                     'genre',
                                                     'available',
                                                     'profile_pic',
                                                     'soundcloud_username',
                                                 ))
    formset = ProfileInlineFormset(instance=user)

    if request.user.is_authenticated() and request.user.id == user.id:
        if request.method == "POST":
            user_form = UserForm(request.POST, request.FILES, instance=user)
            formset = ProfileInlineFormset(request.POST,
                                           request.FILES or None,
                                           instance=user)
            if user_form.is_valid():
                created_user = user_form.save(commit=False)
                formset = ProfileInlineFormset(request.POST,
                                               request.FILES or None,
                                               instance=created_user)
                if formset.is_valid():
                    created_user.save()
                    formset.save()
                    return HttpResponseRedirect('/home/')

        return render(request, "registration/update.html", {
            "pk": pk,
            "noodle_form": user_form,
            "formset": formset,
        })
    else:
        raise PermissionDenied
示例#18
0
def users(request):
    accounts_active = "active"
    if request.method == "POST":
        action = request.POST.get('action', '')
        if action == "CREATE":
            userform = UserForm(request.POST)
            if userform.is_valid():
                userform.instance.set_password(request.POST['password'])
                userform.save()
        elif action == "UPDATE":
            user = User.objects.get(id=request.POST['id'])
            userform = UpdateUserForm(request.POST, instance=user)
            if userform.is_valid():
                userform.save()
        elif action == "DELETE":
            for user in User.objects.filter(id__in=json.loads(str(request.POST.get('user_id',"[]")))):
                user.delete()
        return HttpResponseRedirect('/accounts/users/')
    form = UserForm()
    users = User.objects.all()
    user_forms = {u.id:UpdateUserForm(instance=u) for u in users}
    scripts = ["users"]
    return render_to_response('pages/accounts.html', locals(), context_instance=RequestContext(request))
示例#19
0
def create(request):

    if request.method == 'POST':
        user_form = UserForm(request.POST)

        if user_form.is_valid():
            user = user_form.save()
            UserProfile.objects.create(user=user)
            messages.success(request, 'Usuario creado!')
            return redirect(reverse('users:index'))

    else:
        user_form = UserForm()

    context = {
        'user_form': user_form,
        'menu': 'users',
    }

    return render(request, 'users/create.html', context)
示例#20
0
def register(request):
    if request.user.is_authenticated():
        messages.add_message(request, messages.INFO,
                             'You are already logged in.')
        return redirect(reverse('home'))
    if request.POST:
        userform = UserForm(request.POST)
        userprofileform = ProfileForm(request.POST)
        if userform.is_valid() and userprofileform.is_valid():
            user = userform.save()
            userprofile = userprofileform.save(commit=False)
            userprofile.user = user
            userprofile.save()
            return redirect(reverse('login'))
    else:
        userform = UserForm()
        userprofileform = ProfileForm()
    return render(request, 'auth/register.html', {
        'userform': userform,
        'userprofileform': userprofileform
    })
示例#21
0
def register(request):
    registered = False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            user.set_password(user.password)
            user.last_login = datetime.now()
            user.is_active = True
            user.save()
            profile = profile_form.save(commit=False)
            print user
            profile.user = user
            profile.signUpDate = datetime.now()
            profile.ip_address = get_client_ip(request)
            print profile.ip_address
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']
            profile.save()

            registered = True
        else:
            print 'user' + str(user_form.errors)
            print 'profile' + str(profile_form.errors)
            messages.info(request,
                          str(user_form.errors) + str(profile_form.errors))
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render(
        request, 'auth/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })