Ejemplo n.º 1
0
def users_create_external(request):
    """Create a new external user"""

    if not TruffeUser.static_rights_can('CREATE', request.user):
        raise Http404

    if request.method == 'POST':
        form = TruffeCreateUserForm(request.POST, request.FILES)

        if form.is_valid():
            password = TruffeUser.objects.make_random_password()

            # Automatically generate username based on firstname and lastname
            firstname = ''.join((char for char in form.cleaned_data['first_name'].lower() if char.isalpha()))
            lastname = ''.join((char for char in form.cleaned_data['last_name'].lower() if char.isalpha()))

            trial = '{}{}'.format(firstname[0], lastname[:8])
            int_trial = ''
            while TruffeUser.objects.filter(username='******'.format(trial, int_trial)).count():
                if int_trial:
                    int_trial += 1
                else:
                    int_trial = 1

            user = TruffeUser.objects.create_user('{}{}'.format(trial, int_trial), password=password, **form.cleaned_data)
            send_templated_mail(request, _('Truffe :: Nouveau compte'), '*****@*****.**', [user.email], 'users/users/mail/newuser', {'username': user.username, 'psw': password, 'domain': get_current_site(request).name})

            return redirect('users-views-users_list')

    else:
        form = TruffeCreateUserForm()
    return render(request, 'users/users/create_external.html', {'form': form})
Ejemplo n.º 2
0
def users_create_external(request):
    """Create a new external user"""

    if not TruffeUser.static_rights_can('CREATE', request.user):
        raise Http404

    if request.method == 'POST':
        form = TruffeCreateUserForm(request.POST, request.FILES)

        if form.is_valid():
            password = TruffeUser.objects.make_random_password()

            # Automatically generate username based on firstname and lastname
            firstname = ''.join((char for char in form.cleaned_data['first_name'].lower() if char.isalpha()))
            lastname = ''.join((char for char in form.cleaned_data['last_name'].lower() if char.isalpha()))

            trial = '{}{}'.format(firstname[0], lastname[:8])
            int_trial = ''
            while TruffeUser.objects.filter(username='******'.format(trial, int_trial)).count():
                if int_trial:
                    int_trial += 1
                else:
                    int_trial = 1

            user = TruffeUser.objects.create_user('{}{}'.format(trial, int_trial), password=password, **form.cleaned_data)
            send_templated_mail(request, _('Truffe :: Nouveau compte'), '*****@*****.**', [user.email], 'users/users/mail/newuser', {'username': user.username, 'psw': password, 'domain': get_current_site(request).name})

            return redirect('users.views.users_list')

    else:
        form = TruffeCreateUserForm()
    return render(request, 'users/users/create_external.html', {'form': form})
Ejemplo n.º 3
0
    def handle(self, *args, **options):

        for user in NotificationEmail.objects.values('user').distinct():
            user = TruffeUser.objects.get(pk=user['user'])

            if settings.DEBUG or not NotificationEmail.objects.filter(user=user, date__gt=(now()- datetime.timedelta(minutes=settings.NOTIFS_MINIMUM_BLANK))).exists() or NotificationEmail.objects.filter(user=user, date__lt=(now()- datetime.timedelta(minutes=settings.NOTIFS_MAXIMUM_WAIT))).exists():  # Si une notification plus veille que 15/NOTIFS_MAXIMUM_WAIT minutes OU pas de notification depuis 5/NOTIFS_MINIMUM_BLANK minutes

                notifications = list(NotificationEmail.objects.filter(user=user))

                if len(notifications) == 1:

                    context = {
                        'notification': notifications[0].notification,
                    }

                    send_templated_mail(None, _(u'Truffe :: Notification :: {}'.format(notifications[0].notification.key)), '*****@*****.**', [user.email], 'notifications/mails/new_notif', context)

                else:

                    keys = []

                    for notif in notifications:
                        if notif.notification.key not in keys:
                            keys.append(notif.notification.key)

                    context = {
                        'notifications': map(lambda n: n.notification, notifications),
                    }

                    send_templated_mail(None, _(u'Truffe :: Notifications ({}) :: {}'.format(len(notifications), ', '.join(keys))), '*****@*****.**', [user.email], 'notifications/mails/new_notifs', context)

                for notification in notifications:
                    notification.delete()
Ejemplo n.º 4
0
def users_create_external(request):
    """Create a new external user"""

    if not TruffeUser.static_rights_can("CREATE", request.user):
        raise Http404

    if request.method == "POST":
        form = TruffeCreateUserForm(request.POST, request.FILES)

        if form.is_valid():
            password = TruffeUser.objects.make_random_password()

            # Automatically generate username based on firstname and lastname
            firstname = "".join((char for char in form.cleaned_data["first_name"].lower() if char.isalpha()))
            lastname = "".join((char for char in form.cleaned_data["last_name"].lower() if char.isalpha()))

            trial = "{}{}".format(firstname[0], lastname[:8])
            int_trial = ""
            while TruffeUser.objects.filter(username="******".format(trial, int_trial)).count():
                if int_trial:
                    int_trial += 1
                else:
                    int_trial = 1

            user = TruffeUser.objects.create_user(
                "{}{}".format(trial, int_trial), password=password, **form.cleaned_data
            )
            send_templated_mail(
                request,
                _("Truffe :: Nouveau compte"),
                "*****@*****.**",
                [user.email],
                "users/users/mail/newuser",
                {"username": user.username, "psw": password, "domain": get_current_site(request).name},
            )

            return redirect("users.views.users_list")

    else:
        form = TruffeCreateUserForm()
    return render(request, "users/users/create_external.html", {"form": form})
Ejemplo n.º 5
0
    def handle(self, *args, **options):

        for user in NotificationEmail.objects.values('user').distinct():
            user = TruffeUser.objects.get(pk=user['user'])

            if settings.DEBUG or not NotificationEmail.objects.filter(
                    user=user,
                    date__gt=(now() - datetime.timedelta(
                        minutes=settings.NOTIFS_MINIMUM_BLANK))
            ).exists() or NotificationEmail.objects.filter(
                    user=user,
                    date__lt=(now() - datetime.timedelta(
                        minutes=settings.NOTIFS_MAXIMUM_WAIT))
            ).exists(
            ):  # Si une notification plus veille que 15/NOTIFS_MAXIMUM_WAIT minutes OU pas de notification depuis 5/NOTIFS_MINIMUM_BLANK minutes

                notifications = list(
                    NotificationEmail.objects.filter(user=user))

                groups_notifications = []
                alone_notifications = []

                for notification in notifications:
                    if notification.no_email_group:
                        alone_notifications.append(notification)
                    else:
                        groups_notifications.append(notification)

                if len(groups_notifications) == 1:
                    alone_notifications.append(groups_notifications.pop())

                for notification in alone_notifications:

                    context = {
                        'notification': notification.notification,
                    }
                    send_templated_mail(
                        None,
                        _(u'Truffe :: Notification :: {}'.format(
                            notification.notification.key)),
                        '*****@*****.**', [user.email],
                        'notifications/mails/new_notif', context)

                if groups_notifications:

                    keys = []

                    for notif in groups_notifications:
                        if notif.notification.key not in keys:
                            keys.append(notif.notification.key)

                    context = {
                        'notifications':
                        map(lambda n: n.notification, groups_notifications),
                    }
                    send_templated_mail(
                        None,
                        _(u'Truffe :: Notifications ({}) :: {}'.format(
                            len(groups_notifications), ', '.join(keys))),
                        '*****@*****.**', [user.email],
                        'notifications/mails/new_notifs', context)

                for notification in notifications:
                    notification.delete()