示例#1
0
    def post(self, request):

        if request.method == 'POST':
            user_form = UserForm(request.POST, prefix="usr")
            alumni_form = AlumniForm(request.POST, request.FILES, prefix="alu")
            if user_form.is_valid() and alumni_form.is_valid():
                password1 = request.POST.get('usr-password')
                password2 = request.POST.get('usr-confirm_password')
                if not match_password(password1, password2):
                    self.match_error = True
                    return render(
                        request, 'registration/signup_alumni.html', {
                            'user_form': user_form,
                            'alumni_form': alumni_form,
                            'registered': self.registered,
                            'phone_error': self.phone_error,
                            'match_error': self.match_error,
                            'country_list': self.country_list,
                            'city_list': self.city_list,
                            'region_list': self.region_list,
                        })
                try:
                    alu_country_name = request.POST.get('current_country')
                    alu_country = Country.objects.get(name=alu_country_name)
                except ObjectDoesNotExist:
                    alu_country = None

                try:
                    alu_state_name = request.POST.get('current_state')
                    alu_state = Region.objects.get(name=alu_state_name)
                except ObjectDoesNotExist:
                    alu_state = None

                try:
                    alu_city_name = request.POST.get('current_city')
                    alu_city = City.objects.get(name=alu_city_name)
                except ObjectDoesNotExist:
                    alu_city = None

                alu_phone = request.POST.get('alu-phone_number')

                if alu_country and alu_phone:
                    if not validate_phone(alu_country, alu_phone):
                        self.phone_error = True
                        return render(
                            request, 'registration/signup_alumni.html', {
                                'user_form': user_form,
                                'alumni_form': alumni_form,
                                'registered': self.registered,
                                'phone_error': self.phone_error,
                                'match_error': self.match_error,
                                'country_list': self.country_list,
                                'city_list': self.city_list,
                                'region_list': self.region_list,
                            })

                user = user_form.save(commit=False)

                user.set_password(user.password)
                user.is_active = False
                user.save()

                alumni = alumni_form.save(commit=False)

                alumni.user = user
                alumni.country = alu_country
                alumni.city = alu_city
                alumni.state = alu_state
                alumni.save()

                print('nhi nhi yha pahooncha')

                current_site = get_current_site(request)
                mail_subject = 'Activate your account.'
                message = render_to_string(
                    'registration/acc_active_email.html', {
                        'user':
                        user,
                        'domain':
                        current_site.domain,
                        'uid':
                        force_text(urlsafe_base64_encode(force_bytes(
                            user.pk))),
                        'token':
                        account_activation_token.make_token(user),
                    })
                to_email = alumni_form.cleaned_data.get('email')
                send_mail(mail_subject, message, settings.EMAIL_HOST_USER,
                          [to_email])
                print('reached')
                return render(request, 'HomePage/email_ask_confirm.html')

            else:
                print('yha pahooncha kya')
                return render(
                    request, 'registration/signup_alumni.html', {
                        'user_form': user_form,
                        'alumni_form': alumni_form,
                        'registered': self.registered,
                        'phone_error': self.phone_error,
                        'match_error': self.match_error,
                        'country_list': self.country_list,
                        'city_list': self.city_list,
                        'region_list': self.region_list,
                    })
示例#2
0
文件: views.py 项目: systers/vms
    def post(self, request):
        organization_list = get_organizations_ordered_by_name()
        if organization_list:
            if request.method == 'POST':
                user_form = UserForm(request.POST, prefix="usr")
                administrator_form = AdministratorForm(
                    request.POST, prefix="admin")

                if user_form.is_valid() and administrator_form.is_valid():
                    password1 = request.POST.get('usr-password')
                    password2 = request.POST.get('usr-confirm_password')
                    if not match_password(password1, password2):
                        self.match_error = True
                        return render(
                            request, 'registration/signup_administrator.html',
                            {
                                'user_form': user_form,
                                'administrator_form': administrator_form,
                                'registered': self.registered,
                                'phone_error': self.phone_error,
                                'match_error': self.match_error,
                                'organization_list': self.organization_list,
                            })
                    ad_country = request.POST.get('admin-country')
                    ad_phone = request.POST.get('admin-phone_number')

                    if ad_country and ad_phone:
                        if not validate_phone(ad_country, ad_phone):
                            self.phone_error = True
                            return render(
                                request,
                                'registration/signup_administrator.html', {
                                    'user_form': user_form,
                                    'administrator_form': administrator_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'match_error': self.match_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    user = user_form.save()
                    user.set_password(user.password)
                    user.save()

                    administrator = administrator_form.save(commit=False)
                    administrator.user = user

                    # if organization isn't chosen from dropdown,
                    # the organization_id will be 0
                    organization_id = request.POST.get('organization_name')
                    organization = get_organization_by_id(organization_id)

                    if organization:
                        administrator.organization = organization
                    else:
                        unlisted_org = request.POST.get('admin-unlisted_organization')
                        org = create_organization(unlisted_org)
                        administrator.organization = org

                    administrator.save()
                    registered = True
                    messages.success(request,
                                     'You have successfully registered!')
                    return HttpResponseRedirect(reverse('home:index'))
                else:
                    return render(
                        request, 'registration/signup_administrator.html', {
                            'user_form': user_form,
                            'administrator_form': administrator_form,
                            'registered': self.registered,
                            'phone_error': self.phone_error,
                            'match_error': self.match_error,
                            'organization_list': self.organization_list,
                        })
        else:
            return render(request, 'home/home.html', {'error': True})
示例#3
0
文件: views.py 项目: systers/vms
    def post(self, request):
        organization_list = get_organizations_ordered_by_name()
        if organization_list:
            if request.method == 'POST':
                user_form = UserForm(request.POST, prefix="usr")
                volunteer_form = VolunteerForm(
                    request.POST, request.FILES, prefix="vol")

                if user_form.is_valid() and volunteer_form.is_valid():
                    password1 = request.POST.get('usr-password')
                    password2 = request.POST.get('usr-confirm_password')
                    if not match_password(password1, password2):
                        self.match_error = True
                        return render(
                            request, 'registration/signup_volunteer.html', {
                                'user_form': user_form,
                                'volunteer_form': volunteer_form,
                                'registered': self.registered,
                                'phone_error': self.phone_error,
                                'match_error': self.match_error,
                                'organization_list': self.organization_list,
                            })

                    vol_country = request.POST.get('vol-country')
                    vol_phone = request.POST.get('vol-phone_number')
                    if (vol_country and vol_phone):
                        if not validate_phone(vol_country, vol_phone):
                            self.phone_error = True
                            return render(
                                request, 'registration/signup_volunteer.html',
                                {
                                    'user_form': user_form,
                                    'volunteer_form': volunteer_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    if 'resume_file' in request.FILES:
                        my_file = volunteer_form.cleaned_data['resume_file']
                        if not validate_file(my_file):
                            return render(
                                request, 'registration/signup_volunteer.html',
                                {
                                    'user_form': user_form,
                                    'volunteer_form': volunteer_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    user = user_form.save()

                    user.set_password(user.password)
                    user.save()

                    volunteer = volunteer_form.save(commit=False)
                    volunteer.user = user

                    # if an organization isn't chosen from the dropdown,
                    # then organization_id will be 0
                    organization_id = request.POST.get('organization_name')
                    organization = get_organization_by_id(organization_id)

                    if organization:
                        volunteer.organization = organization
                    else:
                        unlisted_org = request.POST.get('vol-unlisted_organization')
                        org = Organization.objects.create(name=unlisted_org, approved_status=False)
                        org.save()
                        volunteer.organization = org

                    volunteer.reminder_days = 1
                    volunteer.save()
                    current_site = get_current_site(request)
                    mail_subject = 'Activate your account.'
                    message = render_to_string(
                        'registration/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),
                        })
                    to_email = volunteer_form.cleaned_data.get('email')
                    email = EmailMessage(mail_subject, message, to=[to_email])
                    email.send()
                    return render(request, 'home/email_ask_confirm.html')
                else:
                    return render(
                        request, 'registration/signup_volunteer.html', {
                            'user_form': user_form,
                            'volunteer_form': volunteer_form,
                            'registered': self.registered,
                            'phone_error': self.phone_error,
                            'organization_list': self.organization_list,
                        })
        else:
            return render(request, 'home/home.html', {'error': True})
示例#4
0
    def post(self, request):
        organization_list = get_organizations_ordered_by_name()
        if organization_list:
            if request.method == 'POST':
                user_form = UserForm(request.POST, prefix="usr")
                administrator_form = AdministratorForm(request.POST,
                                                       prefix="admin")

                if user_form.is_valid() and administrator_form.is_valid():
                    password1 = request.POST.get('usr-password')
                    password2 = request.POST.get('usr-confirm_password')
                    if not match_password(password1, password2):
                        self.match_error = True
                        return render(
                            request, 'registration/signup_administrator.html',
                            {
                                'user_form': user_form,
                                'administrator_form': administrator_form,
                                'registered': self.registered,
                                'phone_error': self.phone_error,
                                'match_error': self.match_error,
                                'organization_list': self.organization_list,
                            })
                    ad_country = request.POST.get('admin-country')
                    ad_phone = request.POST.get('admin-phone_number')

                    if ad_country and ad_phone:
                        if not validate_phone(ad_country, ad_phone):
                            self.phone_error = True
                            return render(
                                request,
                                'registration/signup_administrator.html', {
                                    'user_form': user_form,
                                    'administrator_form': administrator_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'match_error': self.match_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    user = user_form.save()
                    user.set_password(user.password)
                    user.save()

                    administrator = administrator_form.save(commit=False)
                    administrator.user = user

                    # if organization isn't chosen from dropdown,
                    # the organization_id will be 0
                    organization_id = request.POST.get('organization_name')
                    organization = get_organization_by_id(organization_id)

                    if organization:
                        administrator.organization = organization
                    else:
                        unlisted_org = request.POST.get(
                            'admin-unlisted_organization')
                        org = create_organization(unlisted_org)
                        administrator.organization = org

                    administrator.save()
                    registered = True
                    messages.success(request,
                                     'You have successfully registered!')
                    return HttpResponseRedirect(reverse('home:index'))
                else:
                    return render(
                        request, 'registration/signup_administrator.html', {
                            'user_form': user_form,
                            'administrator_form': administrator_form,
                            'registered': self.registered,
                            'phone_error': self.phone_error,
                            'match_error': self.match_error,
                            'organization_list': self.organization_list,
                        })
        else:
            return render(request, 'home/home.html', {'error': True})
示例#5
0
    def post(self, request):
        organization_list = get_organizations_ordered_by_name()
        if organization_list:
            if request.method == 'POST':
                user_form = UserForm(request.POST, prefix="usr")
                volunteer_form = VolunteerForm(request.POST,
                                               request.FILES,
                                               prefix="vol")

                if user_form.is_valid() and volunteer_form.is_valid():
                    password1 = request.POST.get('usr-password')
                    password2 = request.POST.get('usr-confirm_password')
                    if not match_password(password1, password2):
                        self.match_error = True
                        return render(
                            request, 'registration/signup_volunteer.html', {
                                'user_form': user_form,
                                'volunteer_form': volunteer_form,
                                'registered': self.registered,
                                'phone_error': self.phone_error,
                                'match_error': self.match_error,
                                'organization_list': self.organization_list,
                            })

                    vol_country = request.POST.get('vol-country')
                    vol_phone = request.POST.get('vol-phone_number')
                    if (vol_country and vol_phone):
                        if not validate_phone(vol_country, vol_phone):
                            self.phone_error = True
                            return render(
                                request, 'registration/signup_volunteer.html',
                                {
                                    'user_form': user_form,
                                    'volunteer_form': volunteer_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    if 'resume_file' in request.FILES:
                        my_file = volunteer_form.cleaned_data['resume_file']
                        if not validate_file(my_file):
                            return render(
                                request, 'registration/signup_volunteer.html',
                                {
                                    'user_form': user_form,
                                    'volunteer_form': volunteer_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    user = user_form.save()

                    user.set_password(user.password)
                    user.save()

                    volunteer = volunteer_form.save(commit=False)
                    volunteer.user = user

                    # if an organization isn't chosen from the dropdown,
                    # then organization_id will be 0
                    organization_id = request.POST.get('organization_name')
                    organization = get_organization_by_id(organization_id)

                    if organization:
                        volunteer.organization = organization
                    else:
                        unlisted_org = request.POST.get(
                            'vol-unlisted_organization')
                        org = Organization.objects.create(
                            name=unlisted_org, approved_status=False)
                        org.save()
                        volunteer.organization = org

                    volunteer.reminder_days = 1
                    volunteer.save()
                    current_site = get_current_site(request)
                    mail_subject = 'Activate your account.'
                    message = render_to_string(
                        'registration/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),
                        })
                    to_email = volunteer_form.cleaned_data.get('email')
                    email = EmailMessage(mail_subject, message, to=[to_email])
                    email.send()
                    return render(request, 'home/email_ask_confirm.html')
                else:
                    return render(
                        request, 'registration/signup_volunteer.html', {
                            'user_form': user_form,
                            'volunteer_form': volunteer_form,
                            'registered': self.registered,
                            'phone_error': self.phone_error,
                            'organization_list': self.organization_list,
                        })
        else:
            return render(request, 'home/home.html', {'error': True})
示例#6
0
文件: views.py 项目: Monal5031/vms
    def post(self, request):
        organization_list = get_organizations_ordered_by_name()
        country_list = Country.objects.all()

        if request.method == 'POST':
            user_form = UserForm(request.POST, prefix="usr")
            administrator_form = AdministratorForm(
                request.POST, prefix="admin")

            if user_form.is_valid() and administrator_form.is_valid():
                password1 = request.POST.get('usr-password')
                password2 = request.POST.get('usr-confirm_password')
                if not match_password(password1, password2):
                    self.match_error = True
                    return render(
                        request, 'registration/signup_administrator.html',
                        {
                            'user_form': user_form,
                            'administrator_form': administrator_form,
                            'registered': self.registered,
                            'phone_error': self.phone_error,
                            'match_error': self.match_error,
                            'organization_list': organization_list,
                            'country_list': self.country_list,
                        })
                try:
                    admin_country_name = request.POST.get('country')
                    admin_country = Country.objects.get(name=admin_country_name)
                except ObjectDoesNotExist:
                    admin_country = None

                try:
                    admin_state_name = request.POST.get('state')
                    admin_state = Region.objects.get(name=admin_state_name)
                except ObjectDoesNotExist:
                    admin_state = None

                try:
                    admin_city_name = request.POST.get('city')
                    admin_city = City.objects.get(pk=admin_city_name)
                except ObjectDoesNotExist:
                    admin_city = None

                admin_phone = request.POST.get('admin-phone_number')
                if (admin_country and admin_phone):
                    if not validate_phone(admin_country, admin_phone):
                        self.phone_error = True
                        return render(
                            request,
                            'registration/signup_administrator.html', {
                                'user_form': user_form,
                                'administrator_form': administrator_form,
                                'registered': self.registered,
                                'phone_error': self.phone_error,
                                'match_error': self.match_error,
                                'organization_list':
                                organization_list,
                                'country_list': self.country_list,
                            })

                user = user_form.save()
                user.set_password(user.password)
                user.save()

                administrator = administrator_form.save(commit=False)
                administrator.user = user

                # if organization isn't chosen from dropdown,
                # the organization_id will be 0
                organization_id = request.POST.get('organization_name')
                organization = get_organization_by_id(organization_id)

                if organization:
                    administrator.organization = organization
                else:
                    unlisted_org = request.POST.get('admin-unlisted_'
                                                    'organization')
                    org = create_organization(unlisted_org)
                    administrator.organization = org

                administrator.country = admin_country
                administrator.state = admin_state
                administrator.city = admin_city

                administrator.save()
                current_site = get_current_site(request)
                mail_subject = 'Activate your account.'
                message = render_to_string(
                    'registration/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),
                    })
                to_email = administrator_form.cleaned_data.get('email')
                email = EmailMessage(mail_subject, message, to=[to_email])
                email.send()
                return render(request, 'home/email_ask_confirm.html')
            else:
                return render(
                    request, 'registration/signup_administrator.html', {
                        'user_form': user_form,
                        'administrator_form': administrator_form,
                        'registered': self.registered,
                        'phone_error': self.phone_error,
                        'match_error': self.match_error,
                        'organization_list': organization_list,
                        'country_list': self.country_list,
                    })