Exemplo n.º 1
0
 def post(self, request):
     form = SignUpForm(request.POST)
     if form.is_valid():
         email = form.cleaned_data['email']
         first_name = form.cleaned_data['first_name']
         last_name = form.cleaned_data['last_name']
         password = form.cleaned_data['password2']
         user = User.objects.create(username=email,
                                    first_name=first_name,
                                    last_name=last_name,
                                    email=email)
         user.set_password(raw_password=password)
         user.is_active = False
         user.save()
         current_site = get_current_site(request)
         mail_subject = 'Aktywacja konta (Oddam w dobre ręce)'
         message = render_to_string(
             'acc_active_email.html', {
                 'user': user,
                 'domain': current_site.domain,
                 'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                 'token': account_activation_token.make_token(user=user),
             })
         to_email = form.cleaned_data.get('email')
         email = EmailMessage(mail_subject, message, to=[to_email])
         email.send()
         context = {
             'activate_acc':
             'Na podany adres email został wysłany link aktywacyjny.'
         }
         return render(request, 'email_verification.html', context)
     return render(request, 'register.html', {'form': form})
Exemplo n.º 2
0
def user_login(request):
    error_message = ''
    if request.method == 'POST':
        user = AuthenticationForm(request.POST)
        user = SignUpForm(request.POST)
        print(user)
        login(request, user)
        return redirect('home')
    else:
        return redirect('home')
Exemplo n.º 3
0
def signup(request):
    error_message = ''
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        sub_form = ProfileForm(request.POST)
        if form.is_valid() & sub_form.is_valid():
            user = form.save()
            new_form = sub_form.save(commit=False)
            new_form.user_id = user.id
            if request.FILES:
                new_form.image = request.FILES['image']
            new_form.save()
            login(request, user)
            mail = send_mail('Welcome to Wayfarer',
                             'Thanks for signing up! Please enjoy the app!',
                             '*****@*****.**', [user.email])
            return redirect('profile', user_id=user.id)
        else:
            error_message = form.non_field_errors
            sub_form = ProfileForm()
            context = {
                'form': form,
                'sub_form': sub_form,
                'error_message': error_message
            }
            return render(request, 'registration/signup.html', context)
    else:
        form = SignUpForm()
        sub_form = ProfileForm()
        context = {
            'form': form,
            'sub_form': sub_form,
        }  ## 'error_message': error_message}
        return render(request, 'registration/signup.html', context)
Exemplo n.º 4
0
def profile_edit(request):
    error_message = ''
    if request.method == 'POST':
        form = EditUserForm(request.POST, instance=request.user)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect('profile')
    else:
        error_message = 'Invalid sign up - try again'
    form = SignUpForm()
    context = {'form': form, 'error_message': error_message}
    return render(request, 'index.html', context)
def sign_up(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})
Exemplo n.º 6
0
def sign_up(request):

    # If this is a POST request then process the Form data
    if request.method == 'POST':

        # Create a form instance and populate it with data from the request (binding):
        form = SignUpForm(request.POST)

        # Check if the form is valid:
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            school = form.cleaned_data['school']

            # Create user and save to the database
            user = User.objects.create_user(username=username,
                                            email=None,
                                            password=password)
            user.save()

            signUpModel = SignUpModel(username=username,
                                      password=password,
                                      school=school)
            signUpModel.save()

            # redirect to a new URL:
            return HttpResponseRedirect(reverse('home'))

    # If this is a GET (or any other method) create the default form.
    else:
        form = SignUpForm(request.POST)
    context = {
        'form': form,
    }

    return render(request, 'sign_up.html', context)
Exemplo n.º 7
0
def signup(request):
    error_message = ''
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect('home')
        else:
            error_message = 'Invalid sign up - try again'
    form = SignUpForm()
    context = {'form': form, 'error_message': error_message}
    return render(request, 'registration/signup.html', context)
Exemplo n.º 8
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db(
            )  # load the profile instance created by the signal
            user.email = form.cleaned_data.get('email')
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=user.username, password=raw_password)
            login(request, user)
            return redirect('loggedInLandingPage')
    else:
        form = SignUpForm()
    return render(request, 'registration/sign_up.html', {'form': form})
Exemplo n.º 9
0
def signup(request):
    error_message = ''
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        profile_form = ProfileForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()
            profile_form = ProfileForm(request.POST, instance=user.profile)
            profile_form.full_clean()
            profile_form.save()
            login(request, user)
            return redirect('index')
        else:
            print(form.errors)
            error_message = form.errors
    form = SignUpForm()
    profile_form = ProfileForm()
    context = {
        'form': form,
        'error_message': error_message,
        'profile_form': profile_form
    }
    return render(request, 'registration/signup.html', context)
Exemplo n.º 10
0
def signup_and_login_forms(request):
    return {'login_form': AuthenticationForm(), 'signup_form': SignUpForm()}
Exemplo n.º 11
0
 def get(self, request):
     form = SignUpForm()
     return render(request, 'register.html', {'form': form})