Esempio n. 1
0
def user_add(request, *args, **kwargs):
    context = {'page': 'users'}

    if request.method == 'POST':
        form = PartnerForm(request.POST, instance=None)
        if form.is_valid():
            with transaction.atomic():
                user = User.objects.create(
                    username=form.cleaned_data.get('username'),
                    first_name=form.cleaned_data.get('first_name'),
                    last_name=form.cleaned_data.get('last_name'),
                    email=form.cleaned_data.get('email'),
                    is_active=form.cleaned_data.get('is_active'),
                    is_staff=form.cleaned_data.get('is_staff'),
                    is_superuser=form.cleaned_data.get('is_staff'))
                passwd = random_password(True)
                user.set_password(passwd)
                user.save()

                partner = Partner.objects.create(
                    user=user,
                    organization=form.cleaned_data.get('organization'),
                    can_upload=form.cleaned_data.get('can_upload'),
                    upload_location=form.cleaned_data.get('upload_location'),
                    can_validate=form.cleaned_data.get('can_validate'),
                    validation_location=form.cleaned_data.get(
                        'validation_location'))

            messages.success(
                request,
                _("New User account “{name}” created with "
                  "login `{username}` and password `{password}`").format(
                      name=partner, username=partner.username,
                      password=passwd))

            email_sent, x = send_new_account_email(partner=partner,
                                                   password=passwd,
                                                   creator=Partner.from_user(
                                                       request.user))
            if email_sent:
                messages.info(
                    request,
                    _("The password has been sent to {email}").format(
                        email=partner.email))

            return redirect('users')
        else:
            # django form validation errors
            logger.debug("django form errors")
            pass
    else:
        form = PartnerForm()

    context.update({'form': form})
    return render(request, kwargs.get('template_name', 'user_add.html'),
                  context)
Esempio n. 2
0
File: admin.py Progetto: yeleman/dmd
def user_add(request, *args, **kwargs):
    context = {'page': 'users'}

    if request.method == 'POST':
        form = PartnerForm(request.POST, instance=None)
        if form.is_valid():
            with transaction.atomic():
                user = User.objects.create(
                    username=form.cleaned_data.get('username'),
                    first_name=form.cleaned_data.get('first_name'),
                    last_name=form.cleaned_data.get('last_name'),
                    email=form.cleaned_data.get('email'),
                    is_active=form.cleaned_data.get('is_active'),
                    is_staff=form.cleaned_data.get('is_staff'),
                    is_superuser=form.cleaned_data.get('is_staff'))
                passwd = random_password(True)
                user.set_password(passwd)
                user.save()

                partner = Partner.objects.create(
                    user=user,
                    organization=form.cleaned_data.get('organization'),
                    can_upload=form.cleaned_data.get('can_upload'),
                    upload_location=form.cleaned_data.get('upload_location'),
                    can_validate=form.cleaned_data.get('can_validate'),
                    validation_location=form.cleaned_data.get(
                        'validation_location')
                    )

            messages.success(request,
                             _("New User account “{name}” created with "
                               "login `{username}` and password `{password}`")
                             .format(name=partner, username=partner.username,
                                     password=passwd))

            email_sent, x = send_new_account_email(
                partner=partner, password=passwd,
                creator=Partner.from_user(request.user))
            if email_sent:
                messages.info(request,
                              _("The password has been sent to {email}")
                              .format(email=partner.email))

            return redirect('users')
        else:
            # django form validation errors
            logger.debug("django form errors")
            pass
    else:
        form = PartnerForm()

    context.update({'form': form})
    return render(request,
                  kwargs.get('template_name', 'user_add.html'),
                  context)
Esempio n. 3
0
File: admin.py Progetto: yeleman/dmd
def user_passwd_reset(request, username, *args, **kwargs):
    partner = Partner.get_or_none(username)
    passwd = random_password(True)
    partner.user.set_password(passwd)
    partner.user.save()
    messages.success(request,
                     _("Password for User account “{name}” "
                       "(login `{username}`) has been reseted to `{password}`")
                     .format(name=partner, username=partner.username,
                             password=passwd))
    email_sent, x = send_reset_password_email(
        partner=partner, password=passwd,
        creator=Partner.from_user(request.user))
    if email_sent:
        messages.info(request,
                      _("The password has been sent to {email}")
                      .format(email=partner.email))

    return redirect('users')
Esempio n. 4
0
def user_passwd_reset(request, username, *args, **kwargs):
    partner = Partner.get_or_none(username)
    passwd = random_password(True)
    partner.user.set_password(passwd)
    partner.user.save()
    messages.success(
        request,
        _("Password for User account “{name}” "
          "(login `{username}`) has been reseted to `{password}`").format(
              name=partner, username=partner.username, password=passwd))
    email_sent, x = send_reset_password_email(partner=partner,
                                              password=passwd,
                                              creator=Partner.from_user(
                                                  request.user))
    if email_sent:
        messages.info(
            request,
            _("The password has been sent to {email}").format(
                email=partner.email))

    return redirect('users')