Exemplo n.º 1
0
def register_start(request, template):
    form = EmailForm(request.GET or None)
    if form.is_valid():
        email = form.cleaned_data["email"]
        confirmation_code = random_string(15)
        
        try:
            registrationManager = RegistrationManager.objects.get(email=email)
        except RegistrationManager.DoesNotExist:
            registrationManager = RegistrationManager(email=email, confirmation_code=confirmation_code)
            registrationManager.save()
        
        url = registrationManager.confirmation_url()
        
        template = loader.get_template('registration/confirmation_email.html')
        context = RequestContext(request, {
                'email': email, 
                'url': url, 
        })
        send_mail('[Upright] Activate your account', template.render(context), '*****@*****.**', [email])
        
        return HttpResponseRedirect('/accounts/register/confirm')

    c = RequestContext(request, {'form': form, 'user': request.user })
    c.update(csrf(request))
    return render_to_response(template, c)
Exemplo n.º 2
0
def create_mail(request, account_id):

    if request.method == 'GET':
        account = get_object_or_404(Account, pk=account_id)
        contacts_list = list(account.contacts.all().values('email'))
        email_form = EmailForm()
        return render(
            request, 'create_mail_accounts.html', {
                'account_id': account_id,
                'contacts_list': contacts_list,
                'email_form': email_form
            })

    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            send_email.delay(form.data.get('message_subject'),
                             form.data.get('message_body'),
                             from_email=account_id,
                             recipients=form.data.get('recipients').split(','))

            return JsonResponse({'error': False})
        else:
            return JsonResponse({'error': True, 'errors': form.errors})


# @login_required
# def get_account_details(request, account_id):
#     from django.core import serializers
#     import json
#     fields = ['name', 'email', 'phone', 'industry', 'billing_address_line', 'billing_street', 'billing_city',
#         'billing_state', 'billing_postcode', 'billing_country', 'website', 'description',
#         'created_by__email', 'created_on', 'tags__name', 'status', 'contacts__email', 'assigned_to__email']
#     data = serializers.serialize('json', Account.objects.filter(id=account_id), fields=fields)
#     return JsonResponse({'data': json.loads(data)[0]})
Exemplo n.º 3
0
 def test_EmailForm_not_valid_missing_subject(self):
     form = EmailForm(
         data={
             'first_name': 'teo',
             'last_name': 'budeanu',
             'email': '*****@*****.**',
             'message': 'This is a test.'
         })
     self.assertFalse(form.is_valid())
Exemplo n.º 4
0
 def test_EmailForm_valid(self):
     form = EmailForm(
         data={
             'first_name': 'teo',
             'last_name': 'budeanu',
             'email': '*****@*****.**',
             'subject': 'test',
             'message': 'This is a test.'
         })
     self.assertTrue(form.is_valid())
Exemplo n.º 5
0
 def test_EmailForm_not_valid_with_invalid_email(self):
     form = EmailForm(
         data={
             'first_name': 'teo',
             'last_name': 'budeanu',
             'email': 'teo',
             'subject': 'test',
             'message': 'This is a test.'
         })
     self.assertFalse(form.is_valid())
Exemplo n.º 6
0
def email_login(request):
    """
    Connect email.
    """
    if request.method == "POST":
        form = EmailForm(request.POST)
        if form.is_valid():
            return complete(request, "email")
    else:
        form = EmailForm()

    return render_to_response(
        "accounts/email.html", RequestContext(request, {"title": _("Register email"), "form": form})
    )
Exemplo n.º 7
0
def create_mail(request):
    if request.method == "GET":
        account = get_object_or_404(Account, pk=request.GET.get("account_id"))
        contacts_list = list(account.contacts.all().values("email"))
        TIMEZONE_CHOICES = [(tz, tz) for tz in pytz.common_timezones]
        email_form = EmailForm(account=account)
        return render(
            request,
            "create_mail_accounts.html",
            {
                "account_id": request.GET.get("account_id"),
                "contacts_list": contacts_list,
                "email_form": email_form,
                "timezones": TIMEZONE_CHOICES,
                "settings_timezone": settings.TIME_ZONE,
            },
        )

    if request.method == "POST":
        account = Account.objects.filter(
            id=request.POST.get("account_id")).first()
        if account:
            form = EmailForm(request.POST, account=account)
            if form.is_valid():
                contacts = form.data.get("recipients").split(",")
                email_obj = Email.objects.create(
                    from_account=account,
                    message_body=form.cleaned_data.get("message_body"),
                    message_subject=form.cleaned_data.get("message_subject"),
                    from_email=form.cleaned_data.get("from_email"),
                    timezone=form.cleaned_data.get("timezone"),
                )
                email_obj.recipients.add(*contacts)
                if request.POST.get("scheduled_later") != "true":
                    send_email.delay(email_obj.id)
                else:
                    email_obj.scheduled_later = True
                    email_obj.scheduled_date_time = form.cleaned_data.get(
                        "scheduled_date_time")
                    email_obj.save()

                return JsonResponse({"error": False})
            else:
                return JsonResponse({"error": True, "errors": form.errors})
        else:
            return JsonResponse({
                "error": True,
                "message": "Account does not exist."
            })
Exemplo n.º 8
0
def create_mail(request):
    if request.method == 'GET':
        account = get_object_or_404(Account, pk=request.GET.get('account_id'))
        contacts_list = list(account.contacts.all().values('email'))
        TIMEZONE_CHOICES = [(tz, tz) for tz in pytz.common_timezones]
        email_form = EmailForm(account=account)
        return render(
            request, 'create_mail_accounts.html', {
                'account_id': request.GET.get('account_id'),
                'contacts_list': contacts_list,
                'email_form': email_form,
                "timezones": TIMEZONE_CHOICES,
                "settings_timezone": settings.TIME_ZONE
            })

    if request.method == 'POST':
        account = Account.objects.filter(
            id=request.POST.get('account_id')).first()
        if account:
            form = EmailForm(request.POST, account=account)
            if form.is_valid():
                contacts = form.data.get('recipients').split(',')
                email_obj = Email.objects.create(
                    from_account=account,
                    message_body=form.cleaned_data.get('message_body'),
                    message_subject=form.cleaned_data.get('message_subject'),
                    from_email=form.cleaned_data.get('from_email'),
                    timezone=form.cleaned_data.get('timezone'),
                )
                email_obj.recipients.add(*contacts)
                if request.POST.get('scheduled_later') != 'true':
                    send_email.delay(email_obj.id)
                else:
                    email_obj.scheduled_later = True
                    email_obj.scheduled_date_time = form.cleaned_data.get(
                        'scheduled_date_time')
                    email_obj.save()

                return JsonResponse({'error': False})
            else:
                return JsonResponse({'error': True, 'errors': form.errors})
        else:
            return JsonResponse({
                'error': True,
                'message': "Account does not exist."
            })
Exemplo n.º 9
0
def create_mail(request, account_id):

    if request.method == 'GET':
        account = get_object_or_404(Account, pk=account_id)
        contacts_list = list(account.contacts.all().values('email'))
        email_form = EmailForm()
        return render(request, 'create_mail_accounts.html', {'account_id': account_id,
            'contacts_list': contacts_list, 'email_form': email_form})

    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            send_email.delay(form.data.get('message_subject'), form.data.get('message_body'),
                from_email=account_id, recipients=form.data.get('recipients').split(','))

            return JsonResponse({'error': False})
        else:
            return JsonResponse({'error': True, 'errors': form.errors})
Exemplo n.º 10
0
def resend_verification_email_view(request):
    # if this is a POST request we need to process the form data
    if request.user.is_authenticated():       # only if the no user logged
        return HttpResponseRedirect(reverse('accounts:dashboard'))

    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():

            email = form.cleaned_data['email']
            user = User.objects.get(email=email)

            if user.userextended.is_email_verified:
                return render(request, "accounts/resend_verification_email.html", {'already_verified': True})
            send_verification_email(user)
            return render(request, "accounts/resend_verification_email.html", {'success': True})

    else:
        form = EmailForm()

    return render(request, "accounts/resend_verification_email.html", {'form': form})
Exemplo n.º 11
0
def forget_password_view(request):
    if request.user.is_authenticated():   # forgot password is only if user couldn't login
        return HttpResponseRedirect(reverse('accounts:dashboard'))
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = EmailForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            email = form.cleaned_data['email']
            user = User.objects.get(email=email)
            if not user.userextended.is_email_verified:
                return render(request, "accounts/resend_verification_email.html", {'already_verified': False})
            send_forgot_password_verification_email(user)
            return render(request, "accounts/forgot_password.html", {'success': True})

    # if a GET (or any other method) we'll create a blank form
    else:
        form = EmailForm()

    return render(request, "accounts/forgot_password.html", {'form': form, 'already_verified': True})
Exemplo n.º 12
0
def CloudEmailView(request):
    if request.user.is_superuser:
        if request.method == 'POST':
            email_form = EmailForm(data=request.POST)
            types_form = userlist = TypesForm(data=request.POST)
            if email_form.is_valid() and types_form.is_valid():
                users = UserModel.objects.all()
                email_subject = email_form.cleaned_data.get('subject')
                email_text = email_form.cleaned_data.get('text')
                masterusers = types_form.cleaned_data['masterusers']
                sportclubs = types_form.cleaned_data['sportclubs']
                commonusers = types_form.cleaned_data['commonusers']
                for user in users:
                    if masterusers and user.is_masteruser:
                        send_mail(
                            email_subject,
                            email_text,
                            '*****@*****.**',
                            [
                                user.email,
                            ],
                            fail_silently=False,
                        )
                    if sportclubs and user.is_sportclub:
                        send_mail(
                            email_subject,
                            email_text,
                            '*****@*****.**',
                            [
                                user.email,
                            ],
                            fail_silently=False,
                        )
                    if commonusers and user.is_commonuser:
                        send_mail(
                            email_subject,
                            email_text,
                            '*****@*****.**',
                            [
                                user.email,
                            ],
                            fail_silently=False,
                        )

                superuser_instance = get_object_or_404(UserModel,
                                                       slug=request.user.slug)
                superuser_instance_logs = superuser_instance.user_logs
                to = ''
                if commonusers:
                    to += 'Common Users '
                if sportclubs:
                    to += 'Sport Clubs '
                if masterusers:
                    to += 'Master Users '
                new_log = '''{previous_logs}\n
On {date_time}:\n
Sent Cloud Email To: {to}\n
Email Subject:
{subject}\n
Email Text:\n
{text}
-------------------------------------------------------
                '''.format(
                    previous_logs=superuser_instance_logs,
                    date_time=timezone.localtime(timezone.now()),
                    to=to,
                    subject=str(email_subject),
                    text=str(email_text),
                )
                superuser_instance.user_logs = new_log
                superuser_instance.save()
                return HttpResponseRedirect(
                    reverse('accounts:profile',
                            kwargs={'slug': request.user.slug}))
        else:
            email_form = EmailForm()
            types_form = TypesForm()

            return render(request, 'accounts/cloudemail.html', {
                'email_form': email_form,
                'types_form': types_form
            })
Exemplo n.º 13
0
def CloudEmailView(request):
    if request.user.is_superuser:
        if request.method == 'POST':
            email_form = EmailForm(data = request.POST)
            types_form = userlist = TypesForm(data = request.POST)
            if email_form.is_valid() and types_form.is_valid():
                users = UserModel.objects.all()
                email_subject = email_form.cleaned_data.get('subject')
                email_text = email_form.cleaned_data.get('text')
                masterusers = types_form.cleaned_data['masterusers']
                sportclubs = types_form.cleaned_data['sportclubs']
                commonusers = types_form.cleaned_data['commonusers']
                failed_to_users = ''' fails : \n'''
                success = ''' success : \n'''
                for user in users:
                    try:
                        if masterusers and user.is_masteruser :
                            send_mail(
                            email_subject,
                            email_text,
                            '*****@*****.**',
                            [user.email,],
                            fail_silently=False,
                            )
                        if sportclubs and user.is_sportclub :
                            send_mail(
                            email_subject,
                            email_text,
                            '*****@*****.**',
                            [user.email,],
                            fail_silently=False,
                            )
                        if commonusers and user.is_commonuser :
                            send_mail(
                            email_subject,
                            email_text,
                            '*****@*****.**',
                            [user.email,],
                            fail_silently=False,
                            )
                        success += 'username: '******' with email: ' + str(user.email) +'\n'
                    except:
                        failed_to_users += 'username: '******' with email: ' + str(user.email) +'\n'

                superuser_instance = get_object_or_404(UserModel, slug = request.user.slug)
                superuser_instance_logs = superuser_instance.user_logs
                to = ''
                if commonusers:
                    to += 'Common Users '
                if sportclubs:
                    to += 'Sport Clubs '
                if masterusers:
                    to += 'Master Users '
                now = jdatetime.datetime.now()
                dtime = str(now.year)+'-'+str(now.month)+'-'+ str(now.day)+'  '+str(now.hour)+':'+str(now.minute)+':'+str(now.second)
                new_log = '''{previous_logs}\n
On {date_time}:\n
Sent Cloud Email To: {to}\n
Email Subject:
{subject}\n
Email Text:\n
{text}
-------------------------------------------------------
                '''.format(previous_logs = superuser_instance_logs,
                           date_time = dtime,
                            to = to,
                            subject = str(email_subject),
                            text = str(email_text),)
                superuser_instance.user_logs = new_log
                superuser_instance.save()
                return render(request,'accounts/cloudemail.html',
                                      {'failed_to_users':failed_to_users,
                                      'success':success})
        else:
            email_form = EmailForm()
            types_form = TypesForm()

            return render(request,'accounts/cloudemail.html',
                                  {'email_form':email_form,
                                   'types_form':types_form})