Esempio n. 1
0
def register_user(request):
    form = Registration()
    if request.method == 'POST':
        form = Registration(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.set_password(form.cleaned_data['password'])
            user.is_active = False
            user.save()

            ut = Usertype.objects.create(user=user, is_user=True)
            ut.save()
            profile = Profile.objects.create(profile=ut)
            profile.save()

            current_site = get_current_site(request)
            mail_subject = 'Activate your account.'
            message = render_to_string(
                'authentication/activate_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(
                        user.pk)).decode(),
                    'token': account_activation_token.make_token(user),
                })
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return HttpResponse(
                'Please confirm your email address to complete the registration'
            )

    return render(request, 'authentication/register.html', {'form': form})
Esempio n. 2
0
def register_party(request):
    form_basic = Registration()
    form_party = PartyRegistration()
    if request.method == 'POST':
        form_basic = Registration(request.POST)
        form_party = PartyRegistration(request.POST)
        if form_basic.is_valid() and form_party.is_valid():
            user = form_basic.save(commit=False)
            description = form_party.cleaned_data['description']
            name = form_party.cleaned_data['name']
            user.set_password(form_basic.cleaned_data['password'])
            user.save()

            # ut = Usertype.objects.create(user=user, is_party=True)
            # ut.save()
            with connection.cursor() as cursor:
                cursor.execute('insert into authentication_usertype(user_id, is_user, is_party) values (%s,%s,%s)',
                               [user.pk, False, True])
            # party = Party.objects.create(party=ut, description=description, name=name)
            # party.save()
            with connection.cursor() as cursor:
                cursor.execute(
                    'insert into authentication_party(name, description, created_at, credit_amount,party_id) values (%s,%s,%s,%s,%s)',
                    [name, description, datetime.now(), 0, user.pk])

            return redirect('authentication:login_user')

    return render(request, 'authentication/register.html',
                  {'form': form_basic, 'form_party': form_party})
Esempio n. 3
0
def register_party(request):
    form_basic = Registration()
    form_party = PartyRegistration()
    if request.method == 'POST':
        form_basic = Registration(request.POST)
        form_party = PartyRegistration(request.POST)
        if form_basic.is_valid() and form_party.is_valid():
            user = form_basic.save(commit=False)
            description = form_party.cleaned_data['description']
            name = form_party.cleaned_data['name']
            user.set_password(form_basic.cleaned_data['password'])
            user.save()

            ut = Usertype.objects.create(user=user, is_party=True)
            ut.save()
            party = Party.objects.create(party=ut,
                                         description=description,
                                         name=name)
            party.save()

            return HttpResponse('Party successfully created.')

    return render(request, 'authentication/register.html', {
        'form': form_basic,
        'form_party': form_party
    })
Esempio n. 4
0
def register_user(request):
    form = Registration()
    form_profile = CreateProfile()
    if request.method == 'POST':
        form = Registration(request.POST)
        form_profile = CreateProfile(request.POST)
        if form.is_valid() and form_profile.is_valid():
            user = form.save(commit=False)
            user.set_password(form.cleaned_data['password'])
            user.is_active = False
            user.save()

            # ut = Usertype.objects.create(user=user, is_user=True)
            # ut.save()
            with connection.cursor() as cursor:
                cursor.execute(
                    'insert into authentication_usertype(user_id, is_user, is_party) values (%s,%s,%s)',
                    [user.pk, True, False])

            # profile = form_profile.save(commit=False)
            # profile.profile = ut
            # profile.save()
            first_name = form_profile.cleaned_data['first_name']
            last_name = form_profile.cleaned_data['last_name']
            phone_num = form_profile.cleaned_data['phone_num']
            location = form_profile.cleaned_data['location']
            gender = form_profile.cleaned_data['gender']
            with connection.cursor() as cursor:
                cursor.execute(
                    'insert into authentication_profile(first_name, last_name, phone_num, location, gender, profile_id) values (%s,%s,%s, %s,%s,%s)',
                    [
                        first_name, last_name, phone_num, location, gender,
                        user.pk
                    ])

            current_site = get_current_site(request)
            mail_subject = 'Activate your account.'
            message = render_to_string(
                'authentication/activate_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(
                        user.pk)).decode(),
                    'token': account_activation_token.make_token(user),
                })
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return HttpResponse(
                'Please confirm your email address to complete the registration'
            )
    return render(request, 'authentication/register.html', {
        'form': form,
        'form_profile': form_profile
    })
Esempio n. 5
0
def register(request):
    if request.method == 'POST':
        form = Registration(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 gamestore account!'
            message = render_to_string(
                'authEmail.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(
                        user.pk)).decode(),
                    'token': authenticationToken.make_token(user),
                })
            user.email_user(subject, message)
            return redirect('authEmailSent')
    else:
        form = Registration()
    return render(request, 'register.html', {
        'form': form,
    })