Esempio n. 1
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})
Esempio n. 2
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)
Esempio n. 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)
Esempio n. 4
0
def edit_profile(request):
    template_name = "edit_profile.html"
    if request.method == 'POST':
        userProfileForm = UserProfileForm(request.POST,
                                          instance=request.user.userprofile)

        print(userProfileForm.errors)

        if userProfileForm.is_valid():
            userProfileForm.save()
            return redirect('/authentication/profile')

    else:
        userProfileForm = UserProfileForm(instance=request.user.userprofile)

    args = {'userProfileForm': userProfileForm}
    return render(request, 'edit_profile.html', args)
Esempio n. 5
0
def signup(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST)
        if not form.is_valid():
            print form.errors
            messages.add_message(
                request, messages.ERROR,
                'There was some problems while creating your account. Please review some fields before submiting again.'
            )
            return render(request, 'signup.html', {'form': form})
        else:
            new_user = form.save(commit=False)
            new_user.adminuserid = 0
            new_user.save()
        messages.add_message(request, messages.SUCCESS,
                             'Your account were successfully created.')
        return HttpResponseRedirect('/authentication/signup/')

    else:
        return render(request, 'signup.html', {'form': UserProfileForm()})
Esempio n. 6
0
def user_profile(request, pk=None):
    user = request.user if pk is None else User.objects.get(pk=pk)
    table = PlaceTable(Place.objects.filter(user=user.id))
    table.paginate(page=request.GET.get("page", 1), per_page=25)
    RequestConfig(request).configure(table)
    if request.method == 'GET':
        context = {
            'profile_user': user,
            'profile': user.userprofile,
            'establishments': user.establishment_set.all(),
            'places': user.place_set.all(),
            'form': UserProfileForm(),
            'table': table,
        }

        return render(request, 'accounts/user_profile.html', context)
    else:
        form = UserProfileForm(request.POST, request.FILES, instance=user.userprofile)
        if form.is_valid():
            form.save()
            return redirect('current user profile')

        return redirect('current user profile')
Esempio n. 7
0
def register(request):
    if request.method == 'POST':
        form = ExtendedUserCreationForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        if form.is_valid() and profile_form.is_valid():
            user = form.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()

            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password)
            sign_in(request, user)

            return redirect('home:index')
    else:
        form = ExtendedUserCreationForm()
        profile_form = UserProfileForm()

    context = {'form': form, 'profile_form': profile_form}
    return render(request, 'auth/register.html', context)
Esempio n. 8
0
def signup(request):
    print "please signup here..."
    if request.method == "POST":
        print "yes"
        print request.POST, "asdasd"
        form = UserProfileForm(request.POST)
        if form.is_valid():
            print "valid..."
            new = form.save(commit=False)
            new.save()
        else:
            print form.errors

    return render(request, "signup.html")
Esempio n. 9
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
        })
Esempio n. 10
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)