コード例 #1
0
    def reset_password(self, request):
        form = FormResetPassword(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email'].lower()
            try:
                user = User.objects.get(email=email)
            except:
                user = None
            if user is not None:
                if user.is_active:
                    new_password = generate_random_password(email)
                    user.set_password(new_password)
                    try:
                        user.save()
                        send_reset_password(new_password, email, user.username)
                        response_dict = BaseController.notify.success(
                            user,
                            ['username', 'email', 'first_name', 'last_name'])

                    except Exception as erro:
                        response_dict = BaseController.notify.error(
                            {'email': 'Falha ao gerar nova senha.'})
                else:
                    response_dict = BaseController.notify.error(
                        {'email': 'Usuário não autorizado!'})
            else:
                response_dict = BaseController.notify.error(
                    {'email': 'Usuário não cadastrado.'})
        else:
            response_dict = BaseController.get_exceptions(None, form)
        return self.response(response_dict)
コード例 #2
0
 def filter_users(self, request):
     return BaseController().filter(request,
                                    User,
                                    list_fields=[
                                        'email', 'username', 'is_active',
                                        'date_joined', 'first_name',
                                        'last_name', 'id', 'groups',
                                        'last_login'
                                    ],
                                    extra_fields=['get_full_name'],
                                    order_by='id')
コード例 #3
0
    def get_notifications(self, request):
        self.start_process(request)
        user_id = str(request.user.id)
        request_path = request.get_full_path()

        if 'latest' in request_path:
            response_dict = BaseController().filter(
                request,
                queryset=Notification.objects.filter(
                    related_users__icontains=user_id).order_by('-pk')[:10],
                model=Notification,
                extra_fields=[
                    'related_entity__nome_razao',
                    'last_view_by__get_full_name', 'was_readed'
                ],
                is_response=False)
        else:
            response_dict = BaseController().filter(
                request,
                queryset=Notification.objects.filter(
                    related_users__icontains=user_id).order_by('-pk'),
                model=Notification,
                extra_fields=[
                    'related_entity__nome_razao',
                    'last_view_by__get_full_name', 'was_readed'
                ],
                is_response=False)

        for item in response_dict['object']:
            if item['related_users_readed'] is not None:
                if str(request.user.id) in item['related_users_readed'].split(
                        ";"):
                    item['was_readed'] = True
                else:
                    item['was_readed'] = False
            else:
                item['was_readed'] = False

        return self.response(response_dict)
コード例 #4
0
 def load_operations(self, request):
     self.start_process(request)
     list = BaseController().filter(request,
                                    RestrictedOperation,
                                    extra_fields=['username'],
                                    is_response=False)
     print('SOU LIST', list)
     for operation in list['object']:
         try:
             user = User.objects.get(id=int(operation['user']))
             operation['username'] = user.get_full_name()
         except Exception as error:
             print('SOU ERRO', error)
     return self.response(list)
     #print("Vindo aqui")
     '''response_dict = {}
コード例 #5
0
 def load_backups(self, request):
     x = BaseController().filter(request, model=Backup)
     #print("VEJA O QUE TENHO QUE ENVIAR: ",x)
     return BaseController().filter(request, model=Backup, limit=12)
コード例 #6
0
 def load_operations(self, request):
     self.start_process(request)
     list = BaseController().filter(request,
                                    BaseOperation,
                                    extra_fields=['username'],
                                    is_response=False)