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


Python TASClient.request_password_reset方法代码示例

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


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

示例1: reset_user_password

# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import request_password_reset [as 别名]
    def reset_user_password(self, request, selected_users, form_url=''):

        # The user has already confirmed the action.
        # Trigger password reset notifications
        if request.POST.get('post'):
            tas = TASClient()
            for user in selected_users:
                try:
                    resp = tas.request_password_reset(user.username, source='Chameleon')
                    self.message_user(request, _('Password Reset notification sent to: %s') % user.username)
                except:
                    logger.exception( 'Failed password reset request' )
                    self.message_user(request, _('Unable to reset password for: %s') % user.username, level=messages.ERROR)

            return None

        context = {
            'title': _('Send Password Reset Notification'),
            'opts': self.model._meta,
            'selected_users': selected_users,
            'form_url': form_url,
            'action_checkbox_name':helpers.ACTION_CHECKBOX_NAME
        }
        context.update(admin.site.each_context())

        return TemplateResponse(request,
            'admin/tas/reset_user_password.html',
            context, current_app=self.admin_site.name)
开发者ID:,项目名称:,代码行数:30,代码来源:

示例2: _process_password_reset_request

# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import request_password_reset [as 别名]
def _process_password_reset_request(request, form):
    if form.is_valid():
        # always show success to prevent data leaks
        messages.success(request, 'Your request has been received. If an account matching the username you provided is found, you will receive an email with further instructions to complete the password reset process.')

        username = form.cleaned_data['username']
        logger.info('Password reset request for username: "%s"', username)
        try:
            tas = TASClient()
            user = tas.get_user(username=username)
            resp = tas.request_password_reset(user['username'], source='Chameleon')
            logger.debug(resp)
        except:
            logger.exception('Failed password reset request')

        return True
    else:
        return False
开发者ID:,项目名称:,代码行数:20,代码来源:

示例3: tas_manage

# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import request_password_reset [as 别名]
    def tas_manage(self, request, id, form_url=''):
        if not self.has_change_permission(request):
            raise PermissionDenied
        user = self.get_object(request, unquote(id))

        if user is None:
            raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {
                'name': force_text(self.model._meta.verbose_name),
                'key': escape(id),
            })

        tas = TASClient()
        tas_user = tas.get_user(username=user.username)

        if request.method == 'POST':
            logger.debug(request.POST)
            form = TasUserProfileAdminForm(request.POST)
            if form.is_valid():
                redirect = False
                user.first_name = tas_user['firstName'] = form.cleaned_data['firstName']
                user.last_name = tas_user['lastName'] = form.cleaned_data['lastName']
                user.email = tas_user['email'] = form.cleaned_data['email']
                tas_user['piEligibility'] = form.cleaned_data['piEligibility']
                try:
                    tas.save_user(tas_user['id'], tas_user) # Update remote TAS record
                    user.save() # Update local Django record
                    self.message_user(request, _('Successfully updated profile for user: %s') % user.username)
                    redirect = True
                except:
                    logger.exception('Error saving user %s' % user.username)
                    self.message_user(request, _('Error saving profile for user: %s') % user.username, level=messages.ERROR)
                    redirect = False

                if form.cleaned_data['reset_password']:
                    # trigger password reset
                    try:
                        resp = tas.request_password_reset( user.username, source='Chameleon' )
                        logger.debug( 'Administrator triggered password reset for user %s. Reset token: %s' % (user.username, resp) )
                        self.message_user(request, _('Sent password reset to user: %s') % user.username)
                        redirect = True
                    except:
                        logger.exception( 'Failed password reset request' )
                        self.message_user(request, _('Password reset failed for user: %s') % user.username, level=messages.ERROR)
                        redirect = False

                if redirect:
                    return HttpResponseRedirect(
                        reverse(
                            '%s:auth_%s_change' % (
                                self.admin_site.name,
                                user._meta.model_name,
                            ),
                            args=(user.pk,),
                        )
                    )

        else:
            form = TasUserProfileAdminForm(initial=tas_user)

        fieldsets = [(None, {'fields': list(form.base_fields)})]
        adminForm = admin.helpers.AdminForm(form, fieldsets, {})

        context = {
            'title': _('Manage TAS User: %s') % user.username,
            'adminform': adminForm,
            'form_url': form_url,
            'form': form,
            'opts': self.model._meta,
            'original': user,
        }
        context.update(admin.site.each_context())

        return TemplateResponse(request,
            'admin/tas/tas_manage.html',
            context, current_app=self.admin_site.name)
开发者ID:,项目名称:,代码行数:77,代码来源:


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