コード例 #1
0
def register(request):
    mydb = mysql.connector.connect(host="us-cdbr-iron-east-01.cleardb.net", user="******", password='******',
                                   database='heroku_947e29c06a5b4a3')
    if request.user.is_authenticated:
        return render(request, 'base/profile.html')
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            air_crew = AirCrew()
            if air_crew.is_auth(form.cleaned_data['username']):
                user = User.objects.create_user(first_name =form.cleaned_data['first_name'], username = form.cleaned_data['username'],
                                                last_name = form.cleaned_data['last_name'], email=form.cleaned_data['Email'], password =form.cleaned_data['password'], )
                user.save()
                aircrew = AirCrew()
                aircrew.personal_num = form.cleaned_data['username']
                aircrew.movil = form.cleaned_data['movil']
                aircrew.category = form.cleaned_data['category']
                aircrew.status = form.cleaned_data['status']
                aircrew.InsertToDb()
                return redirect('/profile')
            else:
                return render(request, 'base/notauthorized.html')
    else:
        form = ContactForm()
    args = {'form': form}
    return render(request,'base/register.html', args)
コード例 #2
0
ファイル: views.py プロジェクト: xhslrkd/blog
def email(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            subject = form.cleaned_data['Subject']
            message = form.cleaned_data['Message']
            email = form.cleaned_data['Email']
            cc_myself = form.cleaned_data['CC_myself']
            recipients = ['*****@*****.**']
            if cc_myself:
                recipients.append(email)
                send_mail(
                    subject,
                    message,
                    email,
                    recipients,
                    fail_silently=False,
                )
            return HttpResponseRedirect('/resume/')
    else:
        form = ContactForm()
        return render(request, 'email.html', {
            'form': form,
            'title': 'Contact'
        })
コード例 #3
0
def contact(request):

    if request.method == 'POST':

        f = ContactForm(request.POST)

        if f.is_valid():
            subject    = f.cleaned_data['subject']
            first_name = f.cleaned_data['first_name']
            last_name  = f.cleaned_data['last_name']
            sender     = f.cleaned_data['email']
            phone      = f.cleaned_data['phone']
            message    = f.cleaned_data['message']
            cc_self    = f.cleaned_data['cc_self']

            recipients = ['*****@*****.**']

            if cc_self:
                recipients.append(sender)

            c = {
                'subject': subject,
                'first_name': first_name,
                'last_name': last_name,
                'sender': sender,
                'phone': phone,
                'message': message
                }

            # parse strings and create template objects, pair with context

            text_version = render_to_string('base/contact/email.txt', c)
            html_version = render_to_string('base/contact/email.html', c)

            # subclass EmailMessage with EmailMultiAlternatives and send

            mail = EmailMultiAlternatives(subject, text_version, '', recipients)
            mail.attach_alternative(html_version, 'text/html')
            mail.send()

            return HttpResponseRedirect('/contact/thanks/')

        else:
            f  = ContactForm(request.POST)
            t  = 'base/contact/contact.html'
            c1 = {'form': f}
            c2 = RequestContext(request)

            return render_to_response(t, c1, c2)

    else:

        f  = ContactForm()
        t  = 'base/contact/contact.html'
        c1 = {'form': f}
        c2 = RequestContext(request)

    return render_to_response(t, c1, c2)
コード例 #4
0
ファイル: views.py プロジェクト: arthuRHD/portfolio
 def post(self, request):
     form = ContactForm(request.POST)
     if form.is_valid():
         subject = form.cleaned_data['subject']
         from_email = form.cleaned_data['from_email']
         message = form.cleaned_data['message']
         try:
             send_mail(subject, message, from_email,
                       ['*****@*****.**'])
         except BadHeaderError:
             return HttpResponse('Invalid header found.', status=403)
         return HttpResponseRedirect("/veille/")
コード例 #5
0
ファイル: views.py プロジェクト: tokersey/LSA
def index(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')
    else:
        form = ContactForm()

    return render(request, 'base/index.html', {
            'contacts': Contact.objects.all(),
            'form': form
        })
コード例 #6
0
def contact(request):
    form = ContactForm()

    if request.is_ajax():
        form = ContactForm(request.POST)
        if form.is_valid():
            data = {
                'name': form.cleaned_data['name'],
                'phone': form.cleaned_data['phone'],
                'email': form.cleaned_data['email'],
                'message': form.cleaned_data['message']
            }

            return JsonResponse({'success': data})
        else:
            return JsonResponse({'errors': form.errors})

    return redirect(
        request.POST.get('url_form'))  # just so. Not really functional
コード例 #7
0
 def post(self, request):
     form = ContactForm(data=request.POST)
     if form.is_valid():
         receps = sec.CONTACT_ADDRESSES[request.POST['contact']]
         send_mail(
             request.POST.get('contact_topic'),
             request.POST.get('contact_name') + " wrote: \n" +
             request.POST.get('content'),
             request.POST.get('contact_email'),
             receps,
             fail_silently=False,
         )
         return render(request, 'base/contact.html', {
             'form': ContactForm(),
             'success': True
         })
     else:
         return render(request, 'base/contact.html', {
             'form': form,
             'success': False
         })
コード例 #8
0
ファイル: views.py プロジェクト: sashatankov/oeplatform
 def post(self, request):
     form = ContactForm(data=request.POST)
     if form.is_valid():
         receps = sec.CONTACT_ADDRESSES.get(
             request.POST["contact_category"], "technical")
         send_mail(
             request.POST.get("contact_topic"),
             request.POST.get("contact_name") + " wrote: \n" +
             request.POST.get("content"),
             request.POST.get("contact_email"),
             receps,
             fail_silently=False,
         )
         return render(request, "base/contact.html", {
             "form": ContactForm(),
             "success": True
         })
     else:
         return render(request, "base/contact.html", {
             "form": form,
             "success": False
         })
コード例 #9
0
def register(request):
    if request.user.is_authenticated:
        return render(request, 'base/profile.html')
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                first_name=form.cleaned_data['first_name'],
                username=form.cleaned_data['username'],
                last_name=form.cleaned_data['last_name'],
                password=form.cleaned_data['password'],
            )
            user.save()
            aircrew = AirCrew()
            aircrew.personal_num = form.cleaned_data['username']
            aircrew.movil = form.cleaned_data['movil']
            aircrew.category = form.cleaned_data['category']
            aircrew.status = form.cleaned_data['status']
            aircrew.InsertToDb()
            return redirect('/profile')
    else:
        form = ContactForm()
    args = {'form': form}
    return render(request, 'base/register.html', args)
コード例 #10
0
ファイル: views.py プロジェクト: damienallen/dallen
def contact(request):

    if request.method == 'POST':

        form = ContactForm(data=request.POST)
        ip_address = get_ip(request)

        if form.is_valid():

            name = request.POST.get('name')
            email = request.POST.get('email')
            subject = request.POST.get('subject')
            message = request.POST.get('message')

            sg = sendgrid.SendGridAPIClient(apikey=SENDGRID_KEY)
            from_email = sendgrid.helpers.mail.Email(email)
            subject = '[Contact Form] %s' % subject
            to_email = sendgrid.helpers.mail.Email(CONTACT_EMAIL)
            content = sendgrid.helpers.mail.Content("text/plain", message)
            mail = sendgrid.helpers.mail.Mail(from_email, subject, to_email, content)

            # Captcha check
            r = requests.post(
                'https://www.google.com/recaptcha/api/siteverify',
                data={
                    'secret': RECAPTCHA_SECRET,
                    'response': request.POST.get('recaptcha', None),
                    'remoteip': ip_address
                }
            )
            print(r.status_code, r.json()['success'])
            if not r.json()['success']:
                return JsonResponse(
                    {
                        'sent': False,
                        'captcha': False,
                        'message': 'Captcha check failed!'
                    },
                    status=400
                )

            # Save email to database
            Email.objects.create(
                name=name,
                email=email,
                subject=subject.replace('[Contact Form] ', ''),
                message=message,
                ip=ip_address
            )

            # Send email
            response = sg.client.mail.send.post(request_body=mail.get())
            print(response.status_code)
            print(response.headers)

            if response.status_code >= 200 and response.status_code < 300:
                return JsonResponse(
                    {
                        'sent': True,
                        'captcha': True,
                        'message': 'Message delivered!'
                    },
                    status=200
                )

            else:
                return JsonResponse(
                    {
                        'sent': False,
                        'captcha': True,
                        'message': 'Error %s, please try again!' % response.status_code
                    },
                    status=400
                )

        else:
            return JsonResponse(
                {
                    'sent': False,
                    'captcha': None,
                    'message': 'Invalid form input!',
                    'errors': form.errors
                },
                status=400
            )

    else:
        return JsonResponse(
            {
                'sent': False,
                'captcha': None,
                'message': 'Only POST method allowed!'
            },
            status=400
        )