Example #1
0
def edit_user(request):
    roles = AccountRoles.ALL
    form = forms.UserForm(roles, request.POST)
    if form.is_valid():
        auth_manager = request.auth_manager
        user = User.objects.get(id=form.cleaned_data['id'],
                                account=auth_manager.account_id)

        user.name = form.cleaned_data['name']
        user.nick = form.cleaned_data['username']
        user.email = form.cleaned_data['email']
        user.save()

        user.roles.clear()
        role_code = form.cleaned_data['role']
        role = Role.objects.get(code=role_code)
        user.roles.add(role)

        response = {
            'status': 'ok',
            'messages': [ugettext('APP-USER-UPDATEDSUCCESSFULLY-TEXT')]
        }
        return HttpResponse(json.dumps(response),
                            content_type='application/json')
    else:
        errors = generate_ajax_form_errors(form)
        response = {'status': 'error', 'messages': errors}
        return HttpResponse(json.dumps(response),
                            content_type='application/json',
                            status=400)
Example #2
0
def index_users(request):
    auth_manager = request.auth_manager
    preferences = auth_manager.get_account().get_preferences()
    roles = AccountRoles.ALL
    form = forms.UserForm(roles)
    users = User.objects.values('id', 'name', 'nick', 'last_visit', 'email',
                                'roles__name', 'roles__code').filter(
                                    account=auth_manager.account_id,
                                    roles__code__in=roles).all()
    users = [user for user in users if user['roles__code'] in roles]
    return render_to_response('admin_manager/users.html', locals())
Example #3
0
def create_user(request):
    logger = logging.getLogger(__name__)
    roles = AccountRoles.ALL
    form = forms.UserForm(roles, request.POST)
    if form.is_valid():
        auth_manager = request.auth_manager

        user = User.objects.create(account_id=auth_manager.account_id,
                                   name=form.cleaned_data['name'],
                                   nick=form.cleaned_data['username'],
                                   email=form.cleaned_data['email'],
                                   language=auth_manager.language)

        role_code = form.cleaned_data['role']
        role = Role.objects.get(code=role_code)
        user.roles.add(role)

        # to activate the user
        user_pass_ticket = UserPassTickets.objects.create(
            uuid=unicode(uuid4()),
            user=user,
            type=TicketChoices.USER_ACTIVATION)

        account = auth_manager.get_account()
        preferences = account.get_preferences()

        company = preferences['account_name']
        domain = settings.WORKSPACE_URI

        link = domain + reverse('accounts.activate') + '?' + urllib.urlencode(
            {'ticket': user_pass_ticket.uuid})
        language = auth_manager.language

        logger.debug('[list_subscribe] %s', user)
        country = preferences['account.contact.person.country']
        extradata = {'country': country, 'company': company}

        # Suscribirlo a la lista de usuarios del workspace (si tiene servicio)
        if mail.mail_service:
            if settings.SUBSCRIBE_NEW_USERS_TO_MAIL_LIST:
                mail.mail_service.list_subscribe(user, language, extradata)

            # Enviarle el email de bienvenida
            mail.mail_service.send_welcome_mail(user, link, company)
        else:  # necesita el codigo de activacion al menos, lo redirijo alli
            response = {
                'status':
                'ok',
                'messages': [
                    ugettext('APP-USER-CREATEDSUCCESSFULLY-TEXT'),
                    'Activar en %s' % link
                ],
                'redirect':
                link
            }
            return HttpResponse(json.dumps(response),
                                content_type='application/json')

        response = {
            'status': 'ok',
            'messages': [ugettext('APP-USER-CREATEDSUCCESSFULLY-TEXT')]
        }
        return HttpResponse(json.dumps(response),
                            content_type='application/json')
    else:
        errors = generate_ajax_form_errors(form)
        response = {'status': 'error', 'messages': errors}
        return HttpResponse(json.dumps(response),
                            content_type='application/json',
                            status=400)