コード例 #1
0
def email(request):
    if 'session_key' not in request.session:
        return HttpResponseRedirect(reverse(important))
    session, created = Session.objects.get_or_create(
        key=request.session['session_key'])
    form = EmailForm(session=session)
    if request.POST:
        form = EmailForm(request.POST, session=session)
        if form.is_valid():
            user, created = User.objects.get_or_create(
                username=form.cleaned_data['email'],
                email=form.cleaned_data['email'])
            session.user = user
            session.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Added your email address %s.' % (user.email))
            send_mail(
                'Your diabetes problems account',
                'You can continue your session at anytime by visiting %s' %
                (request.build_absolute_uri(
                    reverse(start, kwargs={'session_key': session.key})), ),
                '*****@*****.**', [user.email],
                fail_silently=True)
            return response(request, redirect=reverse('main-home'))
    return response(request, render='main/form.html', data={'form': form})
コード例 #2
0
def email(request):
    if 'session_key' not in request.session:
        return HttpResponseRedirect(reverse(important))
    session, created = Session.objects.get_or_create(key=request.session['session_key'])
    form = EmailForm(session = session)
    if request.POST:
        form = EmailForm(request.POST, session = session)
        if form.is_valid():
            user, created = User.objects.get_or_create(username=form.cleaned_data['email'], email=form.cleaned_data['email'])
            session.user = user
            session.save()
            messages.add_message(request,messages.SUCCESS,'Added your email address %s.' % (user.email))
            send_mail(
                'Your diabetes problems account',
                'You can continue your session at anytime by visiting %s' % (
                    request.build_absolute_uri(reverse(start, kwargs={'session_key':session.key})),
                    ),
                '*****@*****.**',
                [user.email],
                fail_silently=True
                )
            return response(request, redirect=reverse('main-home'))
    return response(request,
        render='main/form.html',
        data = { 'form':form }
        )
コード例 #3
0
ファイル: views.py プロジェクト: herbieduah/theAgency
def email_form(request):
    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/thanks-for-your-input/4')
    else:
        form = EmailForm()
    return render(request, 'main/email_form.html', {'form': form})
コード例 #4
0
def test_logout(django_user_model):
    user = django_user_model.objects.create(username='******')
    user.set_password('takeajacket')
    user.save()
    form_data = {
        'email': '*****@*****.**',
    }
    form = EmailForm(data=form_data)
    assert form.is_valid()
    c = Client()
    logged_in = c.login(username='******', password='******')
    assert logged_in
    response = c.get('/logout/', follow=True)
    assert response.status_code == 200
    assert b'You have been logged out' in response.content
コード例 #5
0
def test_email_form(django_user_model):
    user = django_user_model.objects.create(username='******')
    user.set_password('takeajacket')
    user.save()
    form_data = {
        'email': '*****@*****.**',
    }
    form = EmailForm(data=form_data)
    assert form.is_valid()
    c = Client()
    response = c.post('/auth/', form_data)
    assert response.status_code == 302
    response = c.get('/login/')
    assert response.status_code == 200
    assert b'Login email sent! Please check your inbox and click on the link.' in response.content
コード例 #6
0
def myaccount(request):
    profile = request.user.get_profile()

    if request.method == 'POST':
        form = EmailForm(request.POST)
        #check the form
        if form.is_valid():
            email = form.cleaned_data['email']
            otherprofile = find_email(email)
            if otherprofile == profile:
                return render_to_response("error.html", {
                    "message":
                    """This email address is already linked to your account.
                """,
                    "returnpage": "/myaccount/"
                },
                                          context_instance=RequestContext(
                                              request))
            if otherprofile != None:
                return render_to_response("error.html", {
                    "message":
                    """There is already an account using this email. You can
                not add it to your secondary emails list.
                """,
                    "returnpage": "/myaccount/"
                },
                                          context_instance=RequestContext(
                                              request))

            secondary = OtherEmail(profile=profile, email=email)
            secondary.save()
            try:
                secondary.send_confirmation_mail()
            except:
                # ignore SMTP error
                pass
            return HttpResponseRedirect(reverse('main.views.myaccount'))
    else:
        form = EmailForm()
    return render_to_response(
        'myaccount.html', {
            'form': form,
            'secondary_emails': profile.secondary_emails.all(),
            'moderator_on': profile.subscription_set.filter(moderator=True),
            'mylists': profile.own_lists.all(),
            'subscriptions': profile.subscription_set.all(),
        },
        context_instance=RequestContext(request))
コード例 #7
0
def display_list_info(request, name):
    list = getListFromName(name)
    subscription = None
    profile = None
    if request.user.is_authenticated():
        profile = request.user.get_profile()
        subscription = profile.list_subscription(list)
    su = request.user.is_authenticated() and request.user.is_staff
    if not list.public and subscription == None and not su:
        raise Http404
    can_browse_subscribers = list.subscribers_list_visible or (
        subscription and subscription.moderator)
    form = EmailForm()
    return render_to_response('list_info.html', {
        'profile':
        profile,
        'list':
        list,
        'can_browse_archive':
        list.can_browse_archive(subscription != None) or request.user.is_staff,
        'can_browse_subscribers':
        can_browse_subscribers or request.user.is_staff,
        'subscription':
        subscription,
        'form':
        form,
    },
                              context_instance=RequestContext(request))
コード例 #8
0
ファイル: views.py プロジェクト: Hessaaljeri/Landing-page
def sendmail(request):
	form = EmailForm(request.POST or None)

	if form.is_valid():
		name = form.cleaned_data.get('name')
		email = form.cleaned_data.get('email')
		message = form.cleaned_data.get('message')
		recipients = [email]

		# send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None, connection=None, html_message=None)
		send_mail(name, ('From: %s - Message: %s' % (email, message)), email, ['*****@*****.**'], fail_silently=False)
		
		return HttpResponse('Your Message Has Been Sent, Thank You')
	context = {
		"form": form,
	}
コード例 #9
0
def email_request(request):
    # Options for POST request can be found in the EmailForm model. In addition to the required parameters, there's
    # an optional parameter, mail_client, which specifies which service to use, otherwise it uses default.

    form = EmailForm(request.POST)

    status_code = 400
    response_data = {"success": False}
    if form.is_valid():
        sender = MailSender()
        mail_response = sender.send_mail_request(
            form.cleaned_data,
            mail_service=form.cleaned_data.get('mail_client'))
        if mail_response.ok:
            response_data["success"] = True
            status_code = 200

        response_data["message"] = mail_response.content

    return JsonResponse(response_data, status=status_code)
コード例 #10
0
ファイル: services.py プロジェクト: jeeyoungk/UWCoopRanking
def _check_email(email):
  email_form = EmailForm({'email':email})
  if not email_form.is_valid():
    message = email_form.errors.values()[0][0]
    return {'status': 'INVALID_USER',
            'message':djangof('<span>{{message}}</span>', dict(message=message))}
  username = email_to_username(email)
  try:
    _user = User.objects.get(username=username)
  except User.DoesNotExist:
    # Create new user,
    # generate default password,
    # Send the notification email.
    new_user = User.objects.create_user(username, email)
    set_default_password(new_user)
    new_user.save()
    new_user.get_profile().save()
    action_factory.user_new(new_user)
    return {'status': 'NEW_USER'}
  return {'status': 'REGISTERED'}
コード例 #11
0
def home(request):
    if 'session_key' not in request.session:
        session = Session()
        session.save()
        request.session['session_key'] = session.key
        return pick(request)
        return response(request,
                        render='main/welcome.html',
                        data={'email_form': EmailForm(session=session)})
    session, created = Session.objects.get_or_create(
        key=request.session['session_key'])
    return response(
        request,
        data={
            'problems': session.problems(),
        },
        render='main/home.html',
    )
コード例 #12
0
def index(request):
    response_code = -1
    mail_sent_to = None
    if request.method == "POST":
        form = EmailForm(request.POST)
        if form.is_valid():
            sender = MailSender()
            mail_response = sender.send_mail_request(
                form.cleaned_data,
                mail_service=form.cleaned_data['mail_client'])
            if mail_response.ok:
                mail_sent_to = "{} ({})".format(form.cleaned_data['to_name'],
                                                form.cleaned_data['to_email'])
                form = EmailForm()
    else:
        form = EmailForm()

    context = {
        'form': form,
        'mail_sent_to': mail_sent_to,
        'response_code': response_code
    }
    return render(request, 'main/email_form.html', context)
コード例 #13
0
ファイル: views.py プロジェクト: auzigog/django-sendgrid
def send_simple_email(request):
	if request.method == 'POST':
		form = EmailForm(request.POST)
		if form.is_valid():
			subject = request.POST["subject"]
			message = request.POST["message"]
			from_email = request.POST["sender"]
			recipient_list = request.POST["to"]
			recipient_list = [r.strip() for r in recipient_list.split(",")]
			category = request.POST["category"]
			# https://docs.djangoproject.com/en/dev/ref/forms/fields/#booleanfield
			html = getattr(request.POST, "html", False)
			enable_gravatar = getattr(request.POST, "enable_gravatar", False)
			enable_click_tracking = getattr(request.POST, "enable_click_tracking", False)
			add_unsubscribe_link = getattr(request.POST, "add_unsubscribe_link", False)
			
			sendGridEmail = SendGridEmailMessage(
				subject,
				message,
				from_email,
				recipient_list,
			)
			if html:
				sendGridEmail.content_subtype = "html"
				
			if category:
				logger.debug("Category {c} was given".format(c=category))
				sendGridEmail.sendgrid_headers.setCategory(category)
				sendGridEmail.update_headers()
				
			filterSpec = {}
			if enable_gravatar:
				logger.debug("Enable Gravatar was selected")
				filterSpec["gravatar"] = {
					"enable": 1
				}
				
			if enable_gravatar:
				logger.debug("Enable click tracking was selected")
				filterSpec["clicktrack"] = {
					"enable": 1
				}
				
			if add_unsubscribe_link:
				logger.debug("Add unsubscribe link was selected")
				# sendGridEmail.sendgrid_headers.add
				filterSpec["subscriptiontrack"] = {
					"enable": 1,
					"text/html": "<p>Unsubscribe <%Here%></p>",
				}
				
			if filterSpec:
				filterutils.update_filters(sendGridEmail, filterSpec, validate=True)
				
			logger.debug("Sending SendGrid email {e}".format(e=sendGridEmail))
			response = sendGridEmail.send()
			logger.debug("Response {r}".format(r=response))
			return HttpResponseRedirect('/')
	else:
		form = EmailForm()

	c = { "form": form }
	c.update(csrf(request))
	return render_to_response('main/send_email.html', c)
コード例 #14
0
def list_subscribe(request, name):
    list = getListFromName(name)
    if request.method != 'POST':
        # should not happen
        return render_to_response("error.html", {
            "message": "Unknown page, how did you get there ?.",
            "returnpage": "/list/%s/" % unicode(list)
        },
                                  context_instance=RequestContext(request))
    if request.user.is_authenticated():
        profile = request.user.get_profile()
        subscription = profile.list_subscription(list)
        if subscription != None:
            return render_to_response("error.html", {
                "message":
                "You are already subscribed to this list, how did you get there ?",
                "returnpage": "/list/%s/" % unicode(list)
            },
                                      context_instance=RequestContext(request))
        # ok, actually subscribe this user
        do_subscribe(profile, list)
        return render_to_response('subscribed.html', {
            'list': list,
        },
                                  context_instance=RequestContext(request))

    # ok : the remaining case is a non-identified user, trying to subscribe
    form = EmailForm(request.POST)

    #check the form
    if not form.is_valid():
        can_browse_archive = list.can_browse_archive(False)
        return render_to_response('list_info.html', {
            'profile': None,
            'list': list,
            'can_browse_archive': can_browse_archive,
            'subscription': None,
            'form': form
        },
                                  context_instance=RequestContext(request))

    # check the email is not already known
    email = form.cleaned_data['email']
    profile = find_email(email)
    if profile != None:
        return render_to_response(
            "error.html", {
                "errorname": "Warning!",
                "message": """There is already an account using this email.
        
        If this is you, please identify yourself to proceed, if not, please choose another email to subscribe.

        If you have forgotten your password, you can <a href="/accounts/password/reset/">ask to change it here</a>.
        """,
                "returnpage": "/accounts/login?next=/list/%s/" % unicode(list)
            },
            context_instance=RequestContext(request))

    # first we need to create a user/profile
    from registration.models import RegistrationProfile
    # use a random password for now on, to be sure nobody can connect
    # the activation page will set the password
    password = User.objects.make_random_password()
    # we have meaningless 'username' in colibri, we only use the 'email'
    # field for authentication
    username = User.objects.make_random_password(25)
    new_user = RegistrationProfile.objects.create_inactive_user(
        username=username,
        password=password,
        site=Site.objects.get_current(),
        email=email,
        send_email=False)
    profile = create_profile(new_user)

    # send an email about the new account
    registration_profile = RegistrationProfile.objects.get(user=new_user)
    subject = "Confirmation for subscribing to , "
    message = render_to_string(
        'subscribe_email.txt', {
            'activation_key': registration_profile.activation_key,
            'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
            'list': list,
            'email': email,
            'password': password,
            'site': Site.objects.get_current()
        })
    send_mail(subject, message, list.list_address_extended('owner'), [email])

    # actual subscribing + email
    do_subscribe(profile, list)

    return render_to_response('subscribed_and_account_created.html', {
        'list': list,
    },
                              context_instance=RequestContext(request))