Esempio n. 1
0
File: views.py Progetto: boxed/curia
def report_bug(request):
    class ReportForm(django.forms.Form):
        description = django.forms.CharField(required=False, widget = django.forms.Textarea, label=_('Description'))
        
    if request.POST:
        form = ReportForm(request.POST)
        
        if form.is_valid():
            urls = get_string(request, 'urls')
            if 'HTTP_USER_AGENT' in request.META:
                user_agent = request.META['HTTP_USER_AGENT']
            else:
                user_agent = 'unknown'
            bug = Bug.objects.create(description=strip_p(form.cleaned_data['description']), reporter=request.user, browser=user_agent, urls=urls)
            
            from django.core.mail import send_mail
            from django.template import loader, Context

            t = loader.get_template('bugs/new_bug_admin_email.html')
            c = {'bug':bug} 
            subject =  _('%s has reported a bug') % request.user
            html_message = t.render(Context(c))
    
            from curia.html2text import html2text
            from curia.mail import send_html_mail_with_attachments
            text_message = html2text(html_message)
            from django.contrib.sites.models import Site
            from django.conf import settings
            send_html_mail_with_attachments(subject=subject, message=text_message, html_message=html_message, from_email='support@'+Site.objects.get_current().domain, recipient_list=[x[1] for x in settings.ADMINS])

            return HttpResponse('0')
    else:
        form = ReportForm(initial={})
    
    return HttpResponseRedirect(request, 'bugs/report.html', {'form':form})
Esempio n. 2
0
File: views.py Progetto: boxed/curia
def send_notification_mail(user, transaction):
    if transaction.rejected:
        subject =  _('%s has rejected a debt') % user
        template = 'debts/transaction_rejected_email.html'
        recipient = transaction.to_user
    else:
        subject =  _('%s has added a debt') % user
        template = 'debts/transaction_added_email.html'
        recipient = transaction.from_user
    account = get_account_for_user(recipient)

    from django.core.mail import send_mail
    from django.template import loader, Context
    
    if account.balance == 0:
        status = 'neutral'
    elif account.balance < 0:
        status = 'negative'
    else:
        status = 'positive'

    t = loader.get_template(template)
    html_message = t.render(Context({'transaction':transaction, 'user':user, 'account':account, 'status':status} ))

    from curia.html2text import html2text
    from curia.mail import send_html_mail_with_attachments
    text_message = html2text(html_message)
    
    from django.contrib.sites.models import Site
    send_html_mail_with_attachments(subject=subject, message=text_message, html_message=html_message, from_email='debts@'+Site.objects.get_current().domain, recipient_list=[recipient.email])
Esempio n. 3
0
def create_countdown(request):
    if request.method == 'POST':
        form = CountdownForm(request.POST)
        if form.is_valid():
            countdown = form.save()
            countdown.password = User.objects.make_random_password(5)
            countdown.save()

            # mail creator
            c = {
                'countdown':
                countdown,
                'url':
                'http://%s%s' % (Site.objects.get_current().domain,
                                 countdown.get_absolute_url()),
            }
            html_message = loader.get_template(
                'countdown/created_email.html').render(Context(c))

            text_message = html2text(html_message)
            send_html_mail_with_attachments(subject=_('Countdown created'),
                                            message=text_message,
                                            html_message=html_message,
                                            from_email='robot@' +
                                            Site.objects.get_current().domain,
                                            recipient_list=[countdown.creator])

            return HttpResponseRedirect(countdown.get_absolute_url())
    else:
        now = datetime.now()
        form = CountdownForm(
            initial={'target_time': datetime(now.year, now.month, now.day)})

    return render_to_response(request, 'countdown/create.html', {'form': form})
Esempio n. 4
0
def edit_countdown(request, countdown_id):
    countdown = Countdown.objects.get(pk=countdown_id)
    if countdown.password != request.REQUEST['password']:
        return render_to_response(request, 'countdown/access_denied.html')

    if request.method == 'POST':
        form = CountdownForm(request.POST, instance=countdown)
        if form.is_valid():
            countdown = form.save()

            # mail creator
            c = {
                'countdown':
                countdown,
                'url':
                'http://%s%s' % (Site.objects.get_current().domain,
                                 countdown.get_absolute_url()),
            }
            html_message = loader.get_template(
                'countdown/created_email.html').render(Context(c))

            text_message = html2text(html_message)
            send_html_mail_with_attachments(subject=_('Countdown created'),
                                            message=text_message,
                                            html_message=html_message,
                                            from_email='robot@' +
                                            Site.objects.get_current().domain,
                                            recipient_list=[countdown.creator])

            return HttpResponseRedirect(countdown.get_absolute_url())
    else:
        form = CountdownForm(instance=countdown)

    return render_to_response(request, 'countdown/edit_countdown.html',
                              {'form': form})
Esempio n. 5
0
def edit_countdown(request, countdown_id):
    countdown = Countdown.objects.get(pk=countdown_id)
    if countdown.password != request.REQUEST['password']:
        return render_to_response(request, 'countdown/access_denied.html')
        
    if request.method == 'POST':
        form = CountdownForm(request.POST, instance=countdown)
        if form.is_valid():
            countdown = form.save()
            
            # mail creator
            c = {
                'countdown': countdown,
                'url': 'http://%s%s' % (Site.objects.get_current().domain, countdown.get_absolute_url()),
            }
            html_message = loader.get_template('countdown/created_email.html').render(Context(c))

            text_message = html2text(html_message)
            send_html_mail_with_attachments(subject=_('Countdown created'), message=text_message, html_message=html_message, from_email='robot@'+Site.objects.get_current().domain, recipient_list=[countdown.creator])
            
            return HttpResponseRedirect(countdown.get_absolute_url())
    else:
        form = CountdownForm(instance=countdown)
        
    return render_to_response(request, 'countdown/edit_countdown.html', {'form':form})
Esempio n. 6
0
File: views.py Progetto: boxed/curia
def register(request):    
    class RegisterForm(django.forms.Form):
        email =  django.forms.CharField(label=_('E-mail address'))

    if request.POST:
        form = RegisterForm(request.POST)

        # validate email
        email = form.data['email']
        if not EmailValidator(email):
            form.errors['email'].append(_('%s is not a valid email address') % email)

        if form.is_valid():
            email = form.cleaned_data['email']

            password = None
            try:
                user = User.objects.get(email=email)
                return HttpResponseRedirect('/registration/request_new_password/')
            except User.DoesNotExist:
                password = User.objects.make_random_password(6)
                user = User.objects.create(email=email, username=User.objects.make_random_password(30), is_active=False)     
                user.set_password(password)
                user.save()

            if Invite.objects.filter(group=request.community, user=user, choice='-').count() == 0:
                Invite.objects.create(user=user, group=request.community, inviter=get_public_user(), message='')

            from django.template import loader, Context

            t = loader.get_template('registration/register_email.html')
            c = {
                'password': password,
                'email': email,
                'domain': request.domain,
                'community': request.community,
                } 
            subject =  _('Confirm e-mail for %s') % request.community
            html_message = t.render(Context(c))

            from curia.html2text import html2text
            from curia.mail import send_html_mail_with_attachments
            text_message = html2text(html_message)
            from django.contrib.sites.models import Site
            send_html_mail_with_attachments(subject=subject, message=text_message, html_message=html_message, from_email='register@'+Site.objects.get_current().domain, recipient_list=[email])

            return render_to_response(request, 'registration/register_email_sent.html', {})
    else:
        form = RegisterForm(initial={})

    return render_to_response(request, 'registration/register.html', {'form':form})
Esempio n. 7
0
File: views.py Progetto: boxed/curia
def report_bug(request):
    class ReportForm(django.forms.Form):
        description = django.forms.CharField(required=False,
                                             widget=django.forms.Textarea,
                                             label=_('Description'))

    if request.POST:
        form = ReportForm(request.POST)

        if form.is_valid():
            urls = get_string(request, 'urls')
            if 'HTTP_USER_AGENT' in request.META:
                user_agent = request.META['HTTP_USER_AGENT']
            else:
                user_agent = 'unknown'
            bug = Bug.objects.create(description=strip_p(
                form.cleaned_data['description']),
                                     reporter=request.user,
                                     browser=user_agent,
                                     urls=urls)

            from django.core.mail import send_mail
            from django.template import loader, Context

            t = loader.get_template('bugs/new_bug_admin_email.html')
            c = {'bug': bug}
            subject = _('%s has reported a bug') % request.user
            html_message = t.render(Context(c))

            from curia.html2text import html2text
            from curia.mail import send_html_mail_with_attachments
            text_message = html2text(html_message)
            from django.contrib.sites.models import Site
            from django.conf import settings
            send_html_mail_with_attachments(
                subject=subject,
                message=text_message,
                html_message=html_message,
                from_email='support@' + Site.objects.get_current().domain,
                recipient_list=[x[1] for x in settings.ADMINS])

            return HttpResponse('0')
    else:
        form = ReportForm(initial={})

    return HttpResponseRedirect(request, 'bugs/report.html', {'form': form})
Esempio n. 8
0
def sync(request):
    op = request.POST['operation']
    context, created = Context.objects.get_or_create(name=request.POST['context'], email=request.POST['email'])
    if created:
        context.code = User.objects.make_random_password()
        context.save()
        from django.core.mail import send_mail
        from django import template
        t = template.loader.get_template('new_sync_context_mail.html')                                         
        html_message = t.render(template.Context({'context':context, 'email':request.POST['email']}))
    
        from curia.html2text import html2text
        from curia.mail import send_html_mail_with_attachments
        text_message = html2text(html_message)
    
        from django.contrib.sites.models import Site
        send_html_mail_with_attachments(subject='New RandomNote synchronization account', message=text_message, html_message=html_message, from_email='*****@*****.**', recipient_list=[request.POST['email']])
    entity = Entity.objects.get_or_create(name=request.POST['entity'])[0]
    objectURI = request.POST['objectURI']
    #print '"%s"' % request.POST['time'][:19]
    time = datetime.strptime(request.POST['time'][:19], '%Y-%m-%d %H:%M:%S')
    # TODO: handle time zone
    #time.timezone = request.POST['time'][-5:]

    #print context, entity, objectURI, time
    if op == 'delete':
        #print 'delete'
        try:
            ManagedObject.objects.get(context=context, entity=entity, objectURI=objectURI).delete()
        except ManagedObject.DoesNotExist:
            pass
    elif op == 'modify':
        data = request.POST['data']
        try:
            obj = ManagedObject.objects.get(context=context, entity=entity, objectURI=objectURI)
            #print 'modify existing'
            obj.modified = time
            obj.data = data
            obj.save()
        except ManagedObject.DoesNotExist:
            #print 'new object'
            ManagedObject.objects.create(context=context, entity=entity, objectURI=objectURI, data=data)
    #elif op == 'add'
    return HttpResponse('success')
Esempio n. 9
0
File: views.py Progetto: boxed/curia
def request_new_password(request):
    class RequestForm(django.forms.Form):
        email = django.forms.CharField(max_length=150,required=True, label=_('Email'))
    
    if request.POST:
        form = RequestForm(request.REQUEST)
        try:
            user = User.objects.get(email=request.REQUEST['email'])
        except User.DoesNotExist:
            form.errors['email'] = (_('There is no user with this email'),)

        if form.is_valid():
            from django.template import loader, Context

            password = User.objects.make_random_password(6)
            email = form.cleaned_data['email']
            t = loader.get_template('registration/retrieve.html')
            c = {
                'password': password,
                'email': email,
                'domain': request.domain,
                } 
            subject =  _('New password request on Eldmyra.se')
            html_message = t.render(Context(c))

            from curia.html2text import html2text
            from curia.mail import send_html_mail_with_attachments
            text_message = html2text(html_message)
            from django.contrib.sites.models import Site
            send_html_mail_with_attachments(subject=subject, message=text_message, html_message=html_message, from_email='retrieve@'+Site.objects.get_current().domain, recipient_list=[email])

            try:
                forgot = ForgotPassword.objects.get(user=user)
                forgot.delete()
            except:
                pass
            ForgotPassword.objects.create(user=user, password=password, created_from='')

            return render_to_response(request, 'registration/request_email_sent.html')
    
    else:
        form = RequestForm(initial={})      
    
    return render_to_response(request, 'registration/request_new_password.html', {'form':form, 'disable_login_box':True})
Esempio n. 10
0
File: views.py Progetto: boxed/curia
def send_notification_mail(user, transaction):
    if transaction.rejected:
        subject = _('%s has rejected a debt') % user
        template = 'debts/transaction_rejected_email.html'
        recipient = transaction.to_user
    else:
        subject = _('%s has added a debt') % user
        template = 'debts/transaction_added_email.html'
        recipient = transaction.from_user
    account = get_account_for_user(recipient)

    from django.core.mail import send_mail
    from django.template import loader, Context

    if account.balance == 0:
        status = 'neutral'
    elif account.balance < 0:
        status = 'negative'
    else:
        status = 'positive'

    t = loader.get_template(template)
    html_message = t.render(
        Context({
            'transaction': transaction,
            'user': user,
            'account': account,
            'status': status
        }))

    from curia.html2text import html2text
    from curia.mail import send_html_mail_with_attachments
    text_message = html2text(html_message)

    from django.contrib.sites.models import Site
    send_html_mail_with_attachments(subject=subject,
                                    message=text_message,
                                    html_message=html_message,
                                    from_email='debts@' +
                                    Site.objects.get_current().domain,
                                    recipient_list=[recipient.email])
Esempio n. 11
0
def create_countdown(request):
    if request.method == 'POST':
        form = CountdownForm(request.POST)
        if form.is_valid():
            countdown = form.save()
            countdown.password = User.objects.make_random_password(5)
            countdown.save()
            
            # mail creator
            c = {
                'countdown': countdown,
                'url': 'http://%s%s' % (Site.objects.get_current().domain, countdown.get_absolute_url()),
            }
            html_message = loader.get_template('countdown/created_email.html').render(Context(c))

            text_message = html2text(html_message)
            send_html_mail_with_attachments(subject=_('Countdown created'), message=text_message, html_message=html_message, from_email='robot@'+Site.objects.get_current().domain, recipient_list=[countdown.creator])
            
            return HttpResponseRedirect(countdown.get_absolute_url())
    else:
        now = datetime.now()
        form = CountdownForm(initial={'target_time':datetime(now.year, now.month, now.day)})
        
    return render_to_response(request, 'countdown/create.html', {'form':form})
Esempio n. 12
0
import codecs
log = codecs.open('curia_schedule.log', 'w', 'utf-8')

for user in users:
    if user.email != '':
        new_stuff = {}
        for community in user.groups.exclude(name='everyone'):
            notifications = Notification.objects.filter(user=user, originator_group=community)
            from curia.notifications import get_subscription_entries
            subscription_entries = get_subscription_entries(user, community)
    
            if len(notifications) != 0 or len(subscription_entries) != 0:
                new_stuff[community] = {'notifications':notifications, 'subscription_entries':subscription_entries}
        
        if len(new_stuff) != 0:
            communities = u', '.join([unicode(x) for x in new_stuff.keys()])
            c = {'new_stuff':new_stuff, 'communities':communities}
            subject =  _("%s has something new for you") % communities
            html_message = loader.get_template('notification_email.html').render(Context(c))
            text_message = loader.get_template('notification_email.txt').render(Context(c))
            send_html_mail_with_attachments(subject=subject, message=text_message, html_message=html_message, from_email='*****@*****.**', recipient_list=[user.email])
            meta = user.meta
            meta.last_notification_email_time = datetime.now()
            meta.save()
            log.write(u'sent to %s\n' % user)
    else:
        log.write(u'user %s has no email address\n' % user)

# mail user reminders for events

log.close()
Esempio n. 13
0
File: views.py Progetto: boxed/curia
def create_community(request):
    community_types = [
        ('Friends', _("Friends")),
        ('Organization', _("Organization")),
        ('Happening', _("Happening")),
        ('Project group', _("Project group")),
        ('Online group', _("Online group")),
        ('Other group', _("Other group"))
    ]
    
    class CreateForm(django.forms.Form):
        name = django.forms.CharField(min_length=4, label=_('Name of community'))
        domain = django.forms.CharField(min_length=4, label=_('Domain'), initial='', help_text='.eldmyra.se')
        email = django.forms.CharField(max_length=150,required=True, label=_('Your e-mail address'))
        confirm_email = django.forms.CharField(max_length=150,required=True, label=_('Confirm your e-mail address'))
        community_type = django.forms.ChoiceField(choices=community_types, label=_('Describe yourself'), widget = django.forms.RadioSelect)
        user_contract = django.forms.BooleanField(required=False, widget=CheckboxInput(attrs={'label':_('I have read and accepted the <a href="/registration/administrator_agreement/" target="blank">administrator agreement</a>')}), label='')

    if request.POST:
        form = CreateForm(request.POST)
        
        email = form.data["email"]
        if email != '':
            if not EmailValidator(email):
                form.errors['email'] = (_('%s is not a valid email address') % email,)
                        
        try: 
            form.data["user_contract"]
        except:
            form.errors['user_contract'] = (_("You must accept the user agreement."),)
        
        if form.data["email"] != form.data["confirm_email"]:
            form.errors['confirm_email'] = (_("Emails did not match."),)
        
        try:
            Group.objects.get(name=form.data["name"])
            form.errors['name'] = (_("That name is already taken."),)
        except Group.DoesNotExist:
            pass
        
        forbidden_names = ['support','login','administrator','administration','admin','administrate','administrering','administrera','eldmyra']
        for forbidden_name in forbidden_names:
            if form.data['name'].lower() == forbidden_name:
                form.errors['name'] = (_("You may not call your community %s.") % forbidden_name,)
                
        forbidden_domains = ['blogg','blog','start','community','eldmyra','admin','fest','rollspel','ninja','dota','administrering','administrera','student','hantverk','demo','test','support','login','administrator','administration']
        for forbidden_domain in forbidden_domains:
            if form.data['domain'].lower() == forbidden_domain:
                form.errors['domain'] = (_("You may not use the domain name %s.eldmyra.se") % forbidden_domain, )      

        try:
            user = User.objects.get(email=request.REQUEST['email'])
        except User.DoesNotExist:
            user = None
            
        try:
            MetaGroup.objects.get(domain=form.data['domain']+'.eldmyra.se')
            form.errors['domain'] = (_('Domain name is taken, please choose another'),)
        except MetaGroup.DoesNotExist:
            pass

        if form.is_valid():
            password = None
            new_user = False
            if not user:                
                # Create new user
                password = User.objects.make_random_password(6)
                user = User.objects.create(email=form.cleaned_data['email'], username=User.objects.make_random_password(30), is_active=False)     
                user.set_password(password)
                user.save()
                new_user = True

            community = Group.objects.create(name=form.cleaned_data['name'])
            meta_group = MetaGroup.objects.create(group=community, created_by=user, domain=form.cleaned_data['domain']+'.eldmyra.se')
            presentation = Document.objects.create(owner_group=community, is_presentation=True)
            new_version = Version(document=presentation,title='Presentation', contents='', owner=user)
            new_version.save()
            community.user_set.add(user)

            if new_user:
                Invite.objects.create(user=user, group=community, inviter=user, message='')

            from django.template import loader, Context

            t = loader.get_template('registration/community_email.html')
            c = {
                'password': password,
                'email': form.cleaned_data['email'],
                'domain': meta_group.domain,
                'inviter': None,
                'message': '',
                'community': community,
                } 
            subject =  _('Your community %s has been registered at Eldmyra.se!') % (community)
            html_message = t.render(Context(c))
            
            from curia.html2text import html2text
            from curia.mail import send_html_mail_with_attachments
            text_message = html2text(html_message)
            from django.contrib.sites.models import Site
            send_html_mail_with_attachments(subject=subject, message=text_message, html_message=html_message, from_email='invite@'+Site.objects.get_current().domain, recipient_list=[form.cleaned_data['email']])
            
            # Homepage / Do not create a homepage, the no external page view is default for new communitites
            #document = Document.objects.create(owner_group=community, owner_user=user, is_presentation=False)
            #new_version = Version(document=document,title='Hem', contents='', owner=user)
            #new_version.save()
            
            # set up access rights
            #from curia.authentication import grant_access, get_public_user
            #grant_access(command='view', user=get_public_user(), obj=document)
            
            # create menu item
            #from curia.homepage.models import MenuItem
            #MenuItem.objects.create(group=community, content_type=get_content_type(document), object_id=document.id, title='Hem', url=document.get_absolute_url(), order=0, parent=None)

            from curia.labels.models import SuggestedLabel
            from curia.forums.models import Thread
            SuggestedLabel.objects.create(title=_('Events'), label=_('Events'), group=community, created_by=user, content_type=get_content_type(Thread))
            SuggestedLabel.objects.create(title=_('Links'), label=_('Links'), group=community, created_by=user, content_type=get_content_type(Thread))

            Label.objects.create(object_id=community.id, deleted=False, name=form.cleaned_data['community_type'], content_type=get_content_type(community), created_by = user, owner_user=user, owner_group=community)
            
            if new_user:
                return render_to_response(request, 'registration/create_community_done.html', {'community':community, 'disable_login_box':True})
            else:
                return HttpResponseRedirect(community.get_external_absolute_url())
    else:
        form = CreateForm()

    return render_to_response(request, 'registration/create_community.html', {'form':form, 'disable_login_box':True})    
Esempio n. 14
0
File: views.py Progetto: boxed/curia
def invite(request):    
    check_access(request.user, obj=request.community, command='administrate users')

    class InviteForm(django.forms.Form):
        emails =  django.forms.CharField(label=_('E-mail addresses of friends to invite'), help_text=_('Separate with comma to invite several people at once, e.g [email protected], [email protected]'))
        message = django.forms.CharField(widget = django.forms.Textarea, required=False, label=_('Personal message'))
        
    if request.POST:
        form = InviteForm(request.POST)
        
        # validate emails
        email_seperator = re.compile(r'[ ,;]')
        emails = email_seperator.split(form.data['emails'])
        for email in emails:
            if email != '':
                if not EmailValidator(email):
                    form.errors['emails'].append(_('%s is not a valid email address') % email)
        
        if form.is_valid():
            emails = email_seperator.split(form.cleaned_data['emails'])
            message = form.cleaned_data['message']
                
            for email in emails:
                if email != '':                 
                    password = None
                    try:
                        user = User.objects.get(email=email)
                        if user in request.community.user_set.all():
                            continue
                        if user.is_active == False:
                            password = user.username
                    except User.DoesNotExist:
                        password = User.objects.make_random_password(20)
                        user = User.objects.create(email=email, username=password, is_active=False)     
                        user.set_password(password)
                        user.save()
                                    
                    if Invite.objects.filter(group=request.community, user=user, choice='-').count() == 0:
                        Invite.objects.create(user=user, group=request.community, inviter=request.user, message=message)

                    from django.template import loader, Context

                    t = loader.get_template('registration/email.html')
                    c = {
                        'password': password,
                        'email': email,
                        'domain': request.domain,
                        'inviter': request.user,
                        'message': form.data['message'],
                        'community': request.community,
                        } 
                    subject =  _('%s has invited you to %s') % (request.user, request.community)
                    html_message = t.render(Context(c))

                    from curia.html2text import html2text
                    from curia.mail import send_html_mail_with_attachments
                    text_message = html2text(html_message)
                    from django.contrib.sites.models import Site
                    send_html_mail_with_attachments(subject=subject, message=text_message, html_message=html_message, from_email='invite@'+Site.objects.get_current().domain, recipient_list=[email])

            return HttpResponseRedirect('/registration/')                
            
    else:
        form = InviteForm(initial={})
    
    return render_to_response(request, 'registration/index.html', {'form':form, 'invited':Invite.objects.filter(group=request.community, choice='-') })