Exemple #1
0
def index(request):
    if request.method == 'POST':
        registration = SignUpForm(request.POST)
        if registration.is_valid():
            registration.save()
            username = registration.cleaned_data.get('username')
            raw_password = registration.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('mainpage')
    else:
        registration = SignUpForm()

    if request.method == 'POST':
        login_form = LogInForm(request.POST)
        if login_form.is_valid():
            login_form.save()
            username = login_form.cleaned_data.get('username')
            password = login_form.cleaned_data.get('password')
            user = authenticate(request, username=username, password=password)
            if user is not None:
                login(request, user)
                return redirect('mainpage')
            else:
                return redirect('http://facebook.com')

    else:
        login_form = LogInForm()

    return render(request, 'homepage.html', {
        'registration': registration,
        'login': login_form
    })
Exemple #2
0
def signup(request):
    if request.user.is_authenticated:
        return HttpResponseRedirect(reverse('index'))
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()
            user.profile.pen_name, user.profile.bio = form.cleaned_data.get('pen_name'), form.cleaned_data.get('bio')
            if form.cleaned_data['photo']:
                user.profile.photo = form.cleaned_data['photo']
            user.profile.save()
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=user.username, password=raw_password)
            login(request, user)

            return HttpResponseRedirect(reverse('index'))

    else:
        form = SignUpForm()
    context = {
        'form': form
    }
    return render(request, 'signup.html', context=context)
Exemple #3
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('list')
    else:
        form = SignUpForm()
    return TemplateResponse(request, 'blog/signup.html', {'form': form})
Exemple #4
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password')
            login(request, user)
            return redirect('post_list')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
Exemple #5
0
def signup_view(request):
    form=SignUpForm()
    if request.method=='POST':
        form=SignUpForm(request.POST)
        if form.is_valid():
            username=form.cleaned_data.get('username')
            user=form.save()
            user.set_password(user.password)
            user.save()
            messages.success(request,f' Account Created Successfully for {username} ! Now you can Login')
            return HttpResponseRedirect('/accounts/login')
    return render(request,'blog/signup.html',{'form':form})
Exemple #6
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('home')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
Exemple #7
0
def signup(request):
    pos = User.objects.all()
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request)
            return redirect('login')
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})
def createaccount(request):
    form = SignUpForm()
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            myuser = form.save()
            author_group = Group.objects.get(name='author')
            myuser.groups.add(author_group)
            messages.success(
                request,
                'your account created. now you can login into your account')
            return HttpResponseRedirect('/login')
    context = {}
    context['form'] = form
    return render(request, 'blog/signup.html', context)
Exemple #9
0
def register_user(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            user = authenticate(username=username, password=password)
            login(request, user)
            messages.success(request, ('Youre now registered'))
            return redirect('/home')
    else:
        form = SignUpForm()

    context = {'form': form}
    return render(request, 'register.html', context)
Exemple #10
0
def signup(request):
    if request.method == "POST":
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get("username")
            raw_password = form.cleaned_data.get("password1")
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            redirect_to = (request.POST.get("next", "").replace(
                "/accounts/signin/?next=", "").replace("/en", ""))
            if "accounts/" in redirect_to or redirect_to == "":
                return redirect("home")
            return HttpResponseRedirect(redirect_to)
    else:
        form = SignUpForm()
    return render(request, "signup.html", {"form": form})
Exemple #11
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            first_name = form.cleaned_data.get('first_name')
            last_name = form.cleaned_data.get('last_name')
            biography = form.cleaned_data.get('biography')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            new_author = Author.objects.create(user=request.user.id,
                                               first_name=first_name,
                                               last_name=last_name,
                                               biography=biography)
            return redirect('/')
    else:
        form = SignUpForm()
    return render(request, 'sign_up.html', {'form': form})
Exemple #12
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            subject = 'Activate Your MySite Account'
            message = render_to_string(
                'account_activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            user.email_user(subject, message)
            return redirect('account_activation_sent')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
Exemple #13
0
def signup(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')

    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            User.objects.create_user(username=username,
                                     email=email,
                                     password=password)
            user = authenticate(username=username, password=password)
            if user is not None:
                auth_login(request, user)
                return HttpResponseRedirect('/')
            else:
                return HttpResponseRedirect('/login')
    else:
        form = SignUpForm()

    return render(request, 'signup.html', {'form': form})