Beispiel #1
0
def register_view(request, *args, **kwargs):
    if request.method == "GET":
        context = {
            'user_form': RegistrationForm(),
            'profile_form': ProfileForm(),
        }

        return render(request, 'auth/register.html', context)

    elif request.method == 'POST':

        user_form = RegistrationForm(request.POST)
        profile_form = ProfileForm(request.POST, request.FILES)

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

            login(request, user)
            return redirect('home view')

    context = {
        'user_form': RegistrationForm(),
        'profile_form': ProfileForm(),
    }
    return render(request, 'auth/register.html', context)
Beispiel #2
0
def profile(request, username):
    if request.method == 'POST':
        form = ProfileForm(request.POST,
                           request.FILES,
                           instance=request.user.profile)

        if form.is_valid():
            obj = form.save(commit=False)
            request.user.username = request.POST[
                'username'] or request.user.username
            request.user.save()
            obj.save()
        return render(request, 'authentication/profile.html')

    form = ProfileForm(instance=request.user.profile)
    page_user = User.objects.get(username=username)
    data = {'page_user': page_user, 'page': 1, 'form': form}

    return render(request, 'authentication/profile.html', data)
Beispiel #3
0
def edit_user_view(request):

    if request.method == 'POST':
        form = ProfileForm(request.POST,
                           request.FILES,
                           instance=request.user.profile)

        if form.is_valid():
            obj = form.save(commit=False)
            request.user.username = request.POST[
                'username'] or request.user.username
            request.user.save()
            obj.save()
        return render(request, 'authentication/profile.html')

    form = ProfileForm(instance=request.user.profile)
    if request.user.username:
        return render(request, 'authentication/edit_profile.html',
                      {'form': form})
    else:
        return render(request, 'authentication/notuser.html')
Beispiel #4
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
    })