コード例 #1
0
ファイル: views.py プロジェクト: Daiech/Actarium
def changePassword(request):
    '''
        Opcion para cambiar password
    '''
    saveViewsLog(request, "apps.account.views.savePassword")
    passUpdate = False
    if request.method == "POST":
        passUpdate = False
        passForm = PasswordChangeForm(data=request.POST, user=request.user)
        if passForm.is_valid():
            passForm.save()
            saveActionLog(request.user, "CHG_PASS", "Password changed",
                          request.META['REMOTE_ADDR']
                          )  # Guarda datos de usuarios antes de modificarse
            passUpdate = True
    else:
        passForm = PasswordChangeForm(user=request.user)
        passUpdate = False
    ctx = {
        "passForm": passForm,
        "dataUpdate": False,
        "passwordUpdate": passUpdate,
        "error_email": False
    }
    return render_to_response('account/password.html',
                              ctx,
                              context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: Daiech/Actarium
def newUser(request):
    '''crea un nuevo usuario usando un formulario propio'''
    saveViewsLog(request, "apps.account.views.newUser")
    if not request.user.is_anonymous():
        return HttpResponseRedirect(reverse("personal_data"))
    if not request.method == "POST":
        formulario = RegisterForm()
    else:
        formulario = RegisterForm(request.POST)
        if formulario.is_valid():
            email_user = formulario.cleaned_data.get('email')
            name_newuser = formulario.cleaned_data.get('username')
            new_user = formulario.save()
            new_user.is_active = False
            new_user.username = new_user.username.replace(" ", "-")
            new_user.save()
            ak = activation_keys.objects.create_key_to_user(new_user)
            data = u"username: {}, email: {}".format(name_newuser, email_user)
            saveActionLog(new_user, "SIGN_IN", data,
                          request.META['REMOTE_ADDR']
                          )  # Guarda datos de usuarios antes de modificarse
            if ak:
                try:
                    sendEmailHtml(
                        1, {
                            'username': name_newuser,
                            'activation_key': ak.activation_key
                        }, [str(email_user)
                            ])  # Envio de correo con clave de activacion
                except Exception, e:
                    print e
                    return HttpResponseRedirect('/#Error-al-enviar-correo')
            return render(request, 'account/registered.html', locals())
コード例 #3
0
def newGeneralGroup(request):
    saveViewsLog(request, "apps.groups_app.views_groups.newGeneralGroup")
    orgs = None
    sel_org = request.GET.get('org')
    if request.method == "POST":  # selecciona los datos para crear un nuevo grupo
        form = newGroupForm(request.POST)
        if form.is_valid():
            resp = create_group(request, form)
            if resp:
                saveActionLog(
                    request.user, 'NEW_GROUP',
                    "id_group: %s, group_name: %s, admin: %s" %
                    (resp.pk, resp.name, request.user.username),
                    request.META['REMOTE_ADDR'])
                return HttpResponseRedirect("/groups/" + str(resp.slug) +
                                            "?saved=1")
            else:
                pass  ## No se pudo crear
    else:
        form = newGroupForm()
    orgs = request.user.organizationsuser_user.get_orgs_by_role_code(
        "is_admin")
    ctx = {
        "newGroupForm": form,
        "organizations": orgs,
        "sel_org": sel_org,
        "full_path": request.get_full_path(),
    }
    return render(request, 'groups/templates/new_group.html', ctx)
コード例 #4
0
ファイル: views.py プロジェクト: Daiech/Actarium
def personalData(request):
    '''
        Control para usuarios logueados.
        se consultan los datos y se los envia al template para imprimirlos
    '''
    saveViewsLog(request, "apps.account.views.personalData")
    last_data = "last=> username: %s, name: %s, last_name: %s, email %s" % (
        request.user.username, request.user.first_name, request.user.last_name,
        request.user.email)
    if request.method == "POST":
        form = UserForm(request.POST, instance=request.user)

        if form.is_valid():
            _email = form.cleaned_data['email']
            try:
                _user = User.objects.get(email=_email)
                if request.user == _user:
                    saveActionLog(
                        request.user, "CHG_USDATA", last_data,
                        request.META['REMOTE_ADDR']
                    )  # Guarda datos de usuarios antes de modificarse
                    form.save()
                    update = True
                    error_email = None
                else:
                    error_email = True
                    update = False
            except User.DoesNotExist:
                saveActionLog(
                    request.user, "CHG_USDATA", last_data,
                    request.META['REMOTE_ADDR']
                )  # Guarda datos de usuarios antes de modificarse
                form.save()
                update = True
                error_email = None
            except User.MultipleObjectsReturned:
                error_email = True
                update = False
            except:
                print "Error desconocido"
                error_email = True
                update = False
        else:
            update = False
            error_email = None
    else:
        form = UserForm(instance=request.user)
        update = False
        error_email = None
    print "update: ", update
    ctx = {
        "formUser": form,
        "dataUpdate": update,
        "passwordUpdate": False,
        "error_email": error_email
    }
    return render_to_response('account/personal_data.html',
                              ctx,
                              context_instance=RequestContext(request))
コード例 #5
0
def delete_member_org(request, slug_org):
    """uname comes in POST method."""
    if request.is_ajax():
        if request.method == "POST":
            org = request.user.organizationsuser_user.get_org(slug=slug_org)
            if org and org.has_user_role(request.user, "is_admin"):
                uname = request.POST.get("uname")
                if uname:
                    _user = User.objects.get_or_none(username=str(uname))
                    if _user and org.has_user_role(_user, "is_member"):
                        #Eliminar de las comisiones aprobatorias
                        minutes_full_signed = org.delete_from_all_approvers_list(
                            _user
                        )  # Retorna un listado de actas que se aprobaron al
                        for m in minutes_full_signed:  ## enviar correo notificando que se aprobo un acta
                            send_email_full_signed(m)
                        # eliminar grupos
                        org.delete_from_all_groups(_user)
                        # Eliminar de organizacion (Habilitar cupo)
                        org.delete_role(
                            _user, is_member=True
                        )  ## el True se ignora, solo es para pasar como **kwarg
                        org.delete_role(
                            _user, is_admin=True
                        )  ## el True se ignora, solo es para pasar como **kwarg

                        message = {
                            "changed":
                            True,
                            "msj":
                            "@" + _user.username + " " +
                            _(u"ya no podrá acceder a la organización."),
                            "num_members":
                            org.get_num_members()
                        }
                        saveActionLog(request.user, 'DEL_USER_ORG',
                                      "name: %s" % (org.name),
                                      request.META['REMOTE_ADDR'])
                    else:
                        message = {
                            "error":
                            _(u"Este usuario no pertenece a la organización")
                        }
                else:
                    message = {
                        "error":
                        _(u"Faltan variables para realizar la operación, por favor recargue la página e intente de nuevo."
                          )
                    }
            else:
                message = {
                    "forbbiden":
                    _(u"No tienes permiso para eliminar miembros.")
                }
            return HttpResponse(json.dumps(message),
                                mimetype="application/json")
    raise Http404
コード例 #6
0
ファイル: views.py プロジェクト: Daiech/Actarium
def activate_account(request, activation_key):
    saveViewsLog(request, "apps.account.views.activate_account")
    if activate_account_now(request, activation_key):
        is_invited = request.GET.get('is_invited')
        data = u"username: {}, email: {}".format(request.user.username,
                                                 request.user.email)
        saveActionLog(request.user, "ACCOUNT_ACTIVATED", data,
                      request.META['REMOTE_ADDR'])
        return render(request, 'account/account_actived.html',
                      {"invited": is_invited})
    else:
        return render(request, 'account/invalid_link.html', {})
コード例 #7
0
ファイル: views.py プロジェクト: Daiech/Actarium
def deleteOrg(request, slug_org):
    org = request.user.organizationsuser_user.get_org(slug=slug_org)
    if org and org.has_user_role(request.user, "is_creator"):
        if request.method == "POST" and "archive" in request.POST:
            org.is_archived = True
            org.save()
            saveActionLog(request.user, 'DEL_ORG', "name: %s" % (org.name),
                          request.META['REMOTE_ADDR'])
            return HttpResponseRedirect(reverse("home") + "?org_archived=1")
        return render(request, "organizations/delete_org.html", locals())
    else:
        raise Http404
コード例 #8
0
ファイル: views.py プロジェクト: Daiech/Actarium
def log_out(request):
    '''
        Finaliza una sesion activa
    '''
    saveViewsLog(request, "apps.account.views.log_out")
    try:
        _user = request.user
        saveActionLog(
            _user, "LOG_OUT", "username: %s" % (_user.username),
            request.META['REMOTE_ADDR'])  # Guarda la accion de cerrar sesion
        logout(request)
    except Exception, e:
        print e
コード例 #9
0
ファイル: views.py プロジェクト: Daiech/Actarium
def settingsOrg(request, slug_org):
    org = request.user.organizationsuser_user.get_org(slug=slug_org)
    user_is_admin = org.has_user_role(request.user, "is_admin")
    if org and ('edit' in request.GET) and user_is_admin:
        update = True
        if request.method == "POST":
            form = OrganizationForm(request.POST, request.FILES, instance=org)
            if form.is_valid() and form.is_multipart():
                form.save()
                updated = saveActionLog(
                    request.user, 'EDIT_ORG',
                    "name: %s" % (form.cleaned_data['name']),
                    request.META['REMOTE_ADDR'])
                return HttpResponseRedirect(
                    reverse("profile_org", args=(org.slug, )))
        else:
            form = OrganizationForm(instance=org)
    elif org and org.has_user_role(request.user, "is_member"):
        update = False
        current_members = org.get_num_members()
        max_members = org.organizationservices_organization.get_max_num_members(
        )
        total = int(current_members) * 100 / int(max_members)
    else:
        raise Http404
    return render(request, "organizations/profile_org.html", locals())
コード例 #10
0
ファイル: views.py プロジェクト: Daiech/Actarium
def userLogin(request, user_name, password):
    '''Autentica a un usuario con los parametros recibidos
        actualmente solo se loguea con username, se espera autenticar con mail'''
    saveViewsLog(request, "apps.account.views.userLogin")
    next = request.GET.get('next') if 'next' in request.GET else None
    if not next:
        next = request.POST.get('next') if 'next' in request.POST else '/'
    user = authenticate(username=user_name, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            saveActionLog(user, "LOG_IN", "username: %s" % (user_name),
                          request.META['REMOTE_ADDR']
                          )  # Guarda la accion de inicar sesion
            return HttpResponseRedirect(next)
        else:
            return render_to_response('account/noactivo.html',
                                      context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/account/login?next=' + next)
コード例 #11
0
ファイル: views.py プロジェクト: Daiech/Actarium
def createOrg(request):
    from actarium_apps.core.forms import PackagesForm
    from actarium_apps.core.models import Packages

    saveViewsLog(request, "apps.groups_app.views_groups.createOrg")
    ref = request.GET.get('ref') if 'ref' in request.GET else ""
    if request.method == "POST":

        package_form = PackagesForm(1, request.POST)
        form = OrganizationForm(request.POST, request.FILES)

        if form.is_valid() and form.is_multipart():
            org = form.save()
            org.set_role(request.user,
                         is_admin=True,
                         is_member=True,
                         is_creator=True)

            is_created, response = create_default_service(request.user, org)
            saveActionLog(request.user, 'NEW_ORG', "name: %s" % (org.name),
                          request.META['REMOTE_ADDR'])

            if package_form.is_valid():

                pf = package_form.cleaned_data['packages']
                if pf.code == "5":
                    return HttpResponseRedirect(org.get_absolute_url())
                else:
                    return HttpResponseRedirect(
                        reverse("services:read_pricing", args=(org.slug, )) +
                        "?id_package=" + str(pf.id))
    else:
        id_package = request.GET.get("id_package")
        form = OrganizationForm()
        package_form = PackagesForm(1, initial={'packages': id_package})
    TRIAL_MEMBERS = getGlobalVar("TRIAL_MEMBERS")
    TRIAL_MONTH = getGlobalVar("TRIAL_MONTH")
    return render(request, "organizations/create_org.html", locals())