当前位置: 首页>>代码示例>>Python>>正文


Python AuthSession.get_user方法代码示例

本文整理汇总了Python中CadVlan.Auth.AuthSession.AuthSession.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python AuthSession.get_user方法的具体用法?Python AuthSession.get_user怎么用?Python AuthSession.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CadVlan.Auth.AuthSession.AuthSession的用法示例。


在下文中一共展示了AuthSession.get_user方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: change_password

# 需要导入模块: from CadVlan.Auth.AuthSession import AuthSession [as 别名]
# 或者: from CadVlan.Auth.AuthSession.AuthSession import get_user [as 别名]
def change_password(request):

    lists = dict()

    if request.method == 'GET':

        lists['change_pass_form'] = ChangePassForm()
        return render_to_response_ajax(AJAX_NEW_PASS, lists, context_instance=RequestContext(request))

    if request.method == 'POST':

        change_pass_form = ChangePassForm()

        try:

            change_pass_form = ChangePassForm(request.POST)

            if change_pass_form.is_valid():

                auth = AuthSession(request.session)
                client = auth.get_clientFactory()

                new_password = change_pass_form.cleaned_data['new_pass']
                user = auth.get_user()
                user_id = user.get_id()
                user_current_password = user.get_password()

                client.create_usuario().change_password(
                    user_id, user_current_password, new_password)
                user.set_password(new_password)

                messages.add_message(
                    request, messages.SUCCESS, auth_messages.get("pass_change_sucess"))

                # Returns HTML
                response = HttpResponse(loader.render_to_string(
                    AJAX_NEW_PASS, lists, context_instance=RequestContext(request)))
                # Send response status with error
                response.status_code = 200
                return response

            else:

                lists['change_pass_form'] = change_pass_form
                # Returns HTML
                response = HttpResponse(loader.render_to_string(
                    AJAX_NEW_PASS, lists, context_instance=RequestContext(request)))
                # Send response status with error
                response.status_code = 412
                return response

        except NetworkAPIClientError, e:
            logger.error(e)
            messages.add_message(request, messages.ERROR, e)

            lists['change_pass_form'] = change_pass_form
            return render_to_response_ajax(AJAX_NEW_PASS, lists, context_instance=RequestContext(request))
开发者ID:globocom,项目名称:GloboNetworkAPI-WebUI,代码行数:59,代码来源:views.py

示例2: render

# 需要导入模块: from CadVlan.Auth.AuthSession import AuthSession [as 别名]
# 或者: from CadVlan.Auth.AuthSession.AuthSession import get_user [as 别名]
    def render(self, context):
        auth = AuthSession(context['request'].session)
        user = auth.get_user()

        if self.write == "None":
            self.write = None

        if self.read == "None":
            self.read = None

        if user.has_perm(PERMISSIONS.get(self.permission), self.write, self.read):
            context["has_perm"] = True
        else:
            context["has_perm"] = False

        return u""
开发者ID:globocom,项目名称:GloboNetworkAPI-WebUI,代码行数:18,代码来源:models.py

示例3: edit

# 需要导入模块: from CadVlan.Auth.AuthSession import AuthSession [as 别名]
# 或者: from CadVlan.Auth.AuthSession.AuthSession import get_user [as 别名]
def edit(request, id_environment):
    try:
        lists = dict()

        # Get User
        auth = AuthSession(request.session)
        client = auth.get_clientFactory()

        # Get all needs from NetworkAPI
        env_logic = client.create_ambiente_logico().listar()
        division_dc = client.create_divisao_dc().listar()
        group_l3 = client.create_grupo_l3().listar()
        filters = client.create_filter().list_all()

        configurations_prefix = client.create_ambiente().configuration_list_all(
            id_environment)

        lists['configurations_prefix'] = configurations_prefix.get(
            'lists_configuration')

        try:
            templates = get_templates(auth.get_user(), True)
        except GITCommandError, e:
            logger.error(e)
            messages.add_message(request, messages.ERROR, e)
            templates = {
                'ipv4': list(),
                'ipv6': list()
            }

        ipv4 = templates.get("ipv4")
        ipv6 = templates.get("ipv6")

        envs = client.create_ambiente().listar().get('ambiente')
        vrfs = client.create_api_vrf().search()['vrfs']

        try:
            env = client.create_api_environment().get_environment(id_environment)
            env = env.get("environments")[0]
        except NetworkAPIClientError, e:
            logger.error(e)
            messages.add_message(request, messages.ERROR, e)
            return redirect('environment.list')
开发者ID:globocom,项目名称:GloboNetworkAPI-WebUI,代码行数:45,代码来源:views.py

示例4: _has_perm

# 需要导入模块: from CadVlan.Auth.AuthSession import AuthSession [as 别名]
# 或者: from CadVlan.Auth.AuthSession.AuthSession import get_user [as 别名]
        def _has_perm(request, *args, **kwargs):

            auth = AuthSession(request.session)

            if auth.is_authenticated():

                user = auth.get_user()

                for perm in permission:
                    write = perm.get("write")
                    read = perm.get("read")
                    if not user.has_perm(perm['permission'], write, read):
                        messages.add_message(
                            request, messages.ERROR, auth_messages.get('user_not_authorized'))
                        return HttpResponseRedirect(URL_HOME)

                return view_func(request, *args, **kwargs)

            else:
                return HttpResponseRedirect(URL_LOGIN)
开发者ID:globocom,项目名称:GloboNetworkAPI-WebUI,代码行数:22,代码来源:Decorators.py

示例5: user_name

# 需要导入模块: from CadVlan.Auth.AuthSession import AuthSession [as 别名]
# 或者: from CadVlan.Auth.AuthSession.AuthSession import get_user [as 别名]
def user_name(request):
    auth = AuthSession(request.session)
    return auth.get_user().get_name()
开发者ID:globocom,项目名称:GloboNetworkAPI-WebUI,代码行数:5,代码来源:util.py

示例6: insert_ambiente_logico

# 需要导入模块: from CadVlan.Auth.AuthSession import AuthSession [as 别名]
# 或者: from CadVlan.Auth.AuthSession.AuthSession import get_user [as 别名]
def insert_ambiente_logico(request):
    # If form was submited
    if request.method == 'POST':

        try:
            lists = dict()

            # Get User
            auth = AuthSession(request.session)
            client = auth.get_clientFactory()

            lists['ambientelogico_form'] = AmbienteLogicoForm()

            # Set data in form
            ambiente_logico_form = AmbienteLogicoForm(request.POST)

            id_env = request.POST['id_env']

            # Validate
            if ambiente_logico_form.is_valid():

                nome_ambiente_logico = ambiente_logico_form.cleaned_data[
                    'nome']

                # Business
                client.create_ambiente_logico().inserir(
                    nome_ambiente_logico.upper())
                messages.add_message(
                    request, messages.SUCCESS, environment_messages.get("ambiente_log_sucess"))

            else:
                # If invalid, send all error messages in fields
                lists['ambientelogico_form'] = ambiente_logico_form

        except NetworkAPIClientError, e:
            logger.error(e)
            lists['ambientelogico_form'] = ambiente_logico_form
            messages.add_message(request, messages.ERROR, e)

        try:
            # Get all needs from NetworkAPI
            env_logic = client.create_ambiente_logico().listar()
            division_dc = client.create_divisao_dc().listar()
            group_l3 = client.create_grupo_l3().listar()
            filters = client.create_filter().list_all()
            try:
                templates = get_templates(auth.get_user(), True)
            except GITCommandError, e:
                logger.error(e)
                messages.add_message(request, messages.ERROR, e)
                templates = {
                    'ipv4': list(),
                    'ipv6': list()
                }

            ipv4 = templates.get("ipv4")
            ipv6 = templates.get("ipv6")
            envs = client.create_ambiente().listar().get('ambiente')
            vrfs = client.create_api_vrf().search()['vrfs']

            # Forms
            env_form = AmbienteForm(
                env_logic, division_dc, group_l3, filters, ipv4, ipv6, envs, vrfs)
            div_form = DivisaoDCForm()
            gro_form = Grupol3Form()
            action = reverse("environment.form")

            # If id_env is set, still in edit
            if id_env:
                env = client.create_ambiente().buscar_por_id(id_env)
                env = env.get("ambiente")

                # Set Environment data
                initial = {"id_env": env.get("id"), "divisao": env.get("id_divisao"),
                           "ambiente_logico": env.get("id_ambiente_logico"),
                           "grupol3": env.get("id_grupo_l3"),
                           "filter": env.get("id_filter"),
                           "link": env.get("link")}
                env_form = AmbienteForm(
                    env_logic, division_dc, group_l3, filters, ipv4, ipv6, envs, vrfs, initial=initial)
                div_form = DivisaoDCForm(initial={"id_env": id_env})
                gro_form = Grupol3Form(initial={"id_env": id_env})
                action = reverse("environment.edit", args=[id_env])

            lists['ambiente'] = env_form
            lists['divisaodc_form'] = div_form
            lists['grupol3_form'] = gro_form
            lists['action'] = action

            return render_to_response(ENVIRONMENT_FORM, lists, context_instance=RequestContext(request))
开发者ID:globocom,项目名称:GloboNetworkAPI-WebUI,代码行数:92,代码来源:views.py

示例7: insert_ambiente

# 需要导入模块: from CadVlan.Auth.AuthSession import AuthSession [as 别名]
# 或者: from CadVlan.Auth.AuthSession.AuthSession import get_user [as 别名]
def insert_ambiente(request):
    try:
        lists = dict()
        config_forms = list()

        # Get User
        auth = AuthSession(request.session)
        client = auth.get_clientFactory()

        # Get all needs from NetworkAPI
        env_logic = client.create_ambiente_logico().listar()
        division_dc = client.create_divisao_dc().listar()
        group_l3 = client.create_grupo_l3().listar()
        filters = client.create_filter().list_all()
        try:
            templates = get_templates(auth.get_user(), True)
        except GITCommandError, e:
            logger.error(e)
            messages.add_message(request, messages.ERROR, e)
            templates = {
                'ipv4': list(),
                'ipv6': list()
            }

        ipv4 = templates.get("ipv4")
        ipv6 = templates.get("ipv6")
        envs = client.create_ambiente().listar().get('ambiente')
        vrfs = client.create_api_vrf().search()['vrfs']
        # Forms
        lists['ambiente'] = AmbienteForm(
            env_logic, division_dc, group_l3, filters, ipv4, ipv6, envs, vrfs)
        lists['divisaodc_form'] = DivisaoDCForm()
        lists['grupol3_form'] = Grupol3Form()
        lists['ambientelogico_form'] = AmbienteLogicoForm()

        lists['action'] = reverse("environment.form")

        # If form was submited
        if request.method == 'POST':

            # Set data in form
            ambiente_form = AmbienteForm(
                env_logic, division_dc, group_l3, filters, ipv4, ipv6, envs, vrfs, request.POST)

            # Return data to form in case of error
            lists['ambiente'] = ambiente_form

            # Validate
            if ambiente_form.is_valid():

                divisao_dc = ambiente_form.cleaned_data['divisao']
                ambiente_logico = ambiente_form.cleaned_data['ambiente_logico']
                grupo_l3 = ambiente_form.cleaned_data['grupol3']
                filter_ = ambiente_form.cleaned_data['filter']
                link = ambiente_form.cleaned_data['link']
                acl_path = ambiente_form.cleaned_data['acl_path']
                vrf = ambiente_form.cleaned_data['vrf']
                if str(vrf) == str(None):
                    vrf = None
                father_environment = ambiente_form.cleaned_data['father_environment']

                ipv4_template = ambiente_form.cleaned_data.get(
                    'ipv4_template', None)
                ipv6_template = ambiente_form.cleaned_data.get(
                    'ipv6_template', None)

                min_num_vlan_1 = ambiente_form.cleaned_data.get(
                    'min_num_vlan_1', None)
                max_num_vlan_1 = ambiente_form.cleaned_data.get(
                    'max_num_vlan_1', None)
                min_num_vlan_2 = ambiente_form.cleaned_data.get(
                    'min_num_vlan_2', None)
                max_num_vlan_2 = ambiente_form.cleaned_data.get(
                    'max_num_vlan_2', None)

                vrf_internal = dict(ambiente_form.fields['vrf'].choices)[int(vrf)]

                # Business
                dict_env = {
                    "id": None,
                    "grupo_l3": int(grupo_l3),
                    "ambiente_logico": int(ambiente_logico),
                    "divisao_dc": int(divisao_dc),
                    "filter": int(filter_) if filter_ else None,
                    "acl_path": acl_path,
                    "ipv4_template": ipv4_template,
                    "ipv6_template": ipv6_template,
                    "link": link,
                    "min_num_vlan_1": min_num_vlan_1,
                    "max_num_vlan_1": max_num_vlan_1,
                    "min_num_vlan_2": min_num_vlan_2,
                    "max_num_vlan_2": max_num_vlan_2,
                    "default_vrf": int(vrf),
                    "father_environment": int(father_environment) if father_environment else None,
                    'vrf': vrf_internal
                }
                client.create_api_environment().create_environment(dict_env)
                messages.add_message(
                    request, messages.SUCCESS, environment_messages.get("success_insert"))

#.........这里部分代码省略.........
开发者ID:globocom,项目名称:GloboNetworkAPI-WebUI,代码行数:103,代码来源:views.py

示例8: ajax_list_vips

# 需要导入模块: from CadVlan.Auth.AuthSession import AuthSession [as 别名]
# 或者: from CadVlan.Auth.AuthSession.AuthSession import get_user [as 别名]
def ajax_list_vips(request):
    '''
        Return list of vip request by search field
    '''

    try:

        # If form was submited
        if request.method == "GET":

            # Get user auth
            auth = AuthSession(request.session)
            client = auth.get_clientFactory()

            search_form = forms.SearchVipRequestForm(request.GET)

            if search_form.is_valid():

                id_vip = search_form.cleaned_data['id_request']
                ipv4 = search_form.cleaned_data["ipv4"]
                ipv6 = search_form.cleaned_data["ipv6"]
                vip_created = search_form.cleaned_data["vip_created"]
                vip_with_onwer = search_form.cleaned_data["vip_with_onwer"]
                hostname = search_form.cleaned_data["hostname"]

                extends_search = dict()
                if hostname:
                    extends_search.update(prepare_hostname(hostname))
                elif len(ipv4) > 0:
                    if request.GET["oct1"]:
                        extends_search.update({'ipv4__oct1': request.GET["oct1"]})
                    if request.GET["oct2"]:
                        extends_search.update({'ipv4__oct2': request.GET["oct2"]})
                    if request.GET["oct3"]:
                        extends_search.update({'ipv4__oct3': request.GET["oct3"]})
                    if request.GET["oct4"]:
                        extends_search.update({'ipv4__oct4': request.GET["oct4"]})
                elif len(ipv6) > 0:
                    if request.GET["oct1"]:
                        extends_search.update({'ipv6__block1__iexact': request.GET["oct1"]})
                    if request.GET["oct2"]:
                        extends_search.update({'ipv6__block2__iexact': request.GET["oct2"]})
                    if request.GET["oct3"]:
                        extends_search.update({'ipv6__block3__iexact': request.GET["oct3"]})
                    if request.GET["oct4"]:
                        extends_search.update({'ipv6__block4__iexact': request.GET["oct4"]})
                    if request.GET["oct5"]:
                        extends_search.update({'ipv6__block5__iexact': request.GET["oct5"]})
                    if request.GET["oct6"]:
                        extends_search.update({'ipv6__block6__iexact': request.GET["oct6"]})
                    if request.GET["oct7"]:
                        extends_search.update({'ipv6__block7__iexact': request.GET["oct7"]})
                    if request.GET["oct8"]:
                        extends_search.update({'ipv6__block8__iexact': request.GET["oct8"]})

                if vip_created:
                    extends_search.update({'created': vip_created})
                if id_vip:
                    extends_search.update({"id": id_vip})
                if vip_with_onwer:
                    user = auth.get_user().get_id()
                    extends_search.update({'viprequestgrouppermission__user_group__usuario': user})

                # Pagination
                column_index_name_map = {
                    0: '',
                    1: 'id',
                    2: 'ipv4',
                    4: 'description',
                    3: 'ipv6',
                    5: 'description',
                    6: 'equipamento',
                    7: 'ambiente',
                    8: 'criado',
                    9: ''}
                dtp = DataTablePaginator(request, column_index_name_map)

                # Make params
                dtp.build_server_side_list()

                # Set params in simple Pagination class
                pagination = Pagination(
                    dtp.start_record,
                    dtp.end_record,
                    dtp.asorting_cols,
                    dtp.searchable_columns,
                    dtp.custom_search)

                # Call API passing all params
                # vips = client.create_vip().list_vip_requests(
                #     id_vip, ip, pag, vip_create)

                data = dict()
                data["start_record"] = pagination.start_record
                data["end_record"] = pagination.end_record
                data["asorting_cols"] = pagination.asorting_cols
                data["searchable_columns"] = pagination.searchable_columns
                data["custom_search"] = pagination.custom_search or ""
                data["extends_search"] = [extends_search] if extends_search else []

#.........这里部分代码省略.........
开发者ID:globocom,项目名称:GloboNetworkAPI-WebUI,代码行数:103,代码来源:views.py


注:本文中的CadVlan.Auth.AuthSession.AuthSession.get_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。