Exemple #1
0
    def save_model(self, request, obj, form, change):
        try:
            user = User.objects.filter(teamuser__organization=obj.organization,
                                       is_staff=True)[0]
            admin = TeamUser.objects.filter(user=user,
                                            organization=obj.organization)[0]
            if (obj.status == 'paid'):
                extra_context1 = {
                    'order_id': obj.order_id,
                    'licenses': obj.no_of_licence,
                }
                EmailThread(' Your Enpass order (%s) has been processed.' %
                            obj.order_id,
                            'orderinfo/order_grant.html', [admin],
                            extra_context=extra_context1).start()
            elif (obj.status == 'cancel'):
                extra_context1 = {
                    'order_id':
                    obj.order_id,
                    'licenses':
                    obj.no_of_licence,
                    'method':
                    payment_mathod(obj.payment_mathod),
                    'reason':
                    obj.reason,
                    'time':
                    OrderRequest.objects.get(order_id=obj.order_id).created_at
                }
                EmailThread('Cancellation of your Enpass order (%s).' %
                            obj.order_id,
                            'orderinfo/order_cancel.html', [admin],
                            extra_context=extra_context1).start()
            elif (obj.status == 'quote'):
                extra_context1 = {
                    'order_id': obj.order_id,
                    'licenses': obj.no_of_licence,
                    'method': payment_mathod(obj.payment_mathod),
                    'time':
                    OrderRequest.objects.get(order_id=obj.order_id).created_at,
                    'obj': obj
                }
                if 'invoice' in form.changed_data:
                    EmailThread('Quotation of your Enpass order ID %s.' %
                                obj.order_id,
                                'orderinfo/order_quote.html', [admin],
                                extra_context=extra_context1).start()
        except Exception as e:
            pass

        return super(OrderAdmin, self).save_model(request, obj, form, change)
Exemple #2
0
    def post(self,request,format=None):
        organization_id=request.data['organization_id']
        email=request.data['email']
        team=Team.objects.get(organizationId=organization_id)
        teamuser=TeamUser.objects.get(email=email,organization=team)
        if email=='*****@*****.**':
            return Response({'error':False,
                            'description':'Please verify using the OTP sent on %s.'%email
                    })
        
        '''expire the last OTP and re-generate it'''
        otps=Otp.objects.filter(teamuser=teamuser,expired=False)
        for otp in otps:
            otp.expired=True
            otp.save()

        obj=Otp.objects.create(teamuser=teamuser,one_time_password=''.join(random.choice('0123456789') for i in range(6)))
        EmailThread(
            subject='Your Enpass sign-in One-Time Password',
            template_path='team/otp_confirmation.html',
            recipient_list=[teamuser],
            extra_context={'otp':obj.one_time_password,'time':obj.created_at}
        ).start()

        return Response({'error':False,
        'description':'Please verify using the OTP sent on %s.'%email
        })
Exemple #3
0
 def make_deactive(self, request, queryset):
     owner_org = TeamUser.objects.get(user=request.user).organization
     deactivated_users = queryset.filter(active=True)
     for a in deactivated_users:
         a.active = False
         a.save()
         deleteToken(a)
     EmailThread('Enpass account deactivation for %s' % owner_org.name,
                 'team/team_deactivation.html', deactivated_users).start()
Exemple #4
0
    def save_model(self, request, obj, form, change):
        if change:
            if request.user.is_superuser:
                return super(TeamUserAdmin,
                             self).save_model(request, obj, form, change)

            owner_org = TeamUser.objects.get(user=request.user).organization
            '''check active field value change'''
            if 'active' in form.changed_data:
                if obj.active:
                    EmailThread('Your %s organization' % owner_org.name,
                                'team/team_granted.html', [obj]).start()
                else:
                    deleteToken(obj)
                    EmailThread(
                        'Enpass account deactivation for %s' % owner_org.name,
                        'team/team_deactivation.html', [obj]).start()

            return super(TeamUserAdmin,
                         self).save_model(request, obj, form, change)
        else:
            if request.user.is_superuser:
                obj.email = obj.user.email
                obj.save()
            else:
                try:
                    user = User.objects.get(email=obj.email)
                    obj.user = user
                except User.DoesNotExist:
                    user = User.objects.create_user(obj.email, obj.email,
                                                    randomPassword)
                owner_org = TeamUser.objects.get(
                    user=request.user).organization
                obj.user = user
                obj.organization = owner_org
                obj.save()

            if obj.active:
                EmailThread(
                    'Enpass account activation for %s' % owner_org.name,
                    'team/team_granted.html', [obj]).start()
            return super(TeamUserAdmin,
                         self).save_model(request, obj, form, change)
Exemple #5
0
    def save_model(self, request, obj, form, change):
        if not change:
            try:
                teamAdmin = TeamUser.objects.get(user=request.user)
                obj.organization = teamAdmin.organization
                obj.order_id = ''.join(
                    random.choice('0123456789') for i in range(15))
                obj.save()

                extra_context1 = {
                    'order_id': obj.order_id,
                    'licenses': obj.no_of_licence,
                    'method': payment_mathod(obj.preferred_payment_mathod),
                    'message': obj.message
                }

                EmailThread(
                    'Confirmation of your Enpass order (%s).' % obj.order_id,
                    'orderinfo/order_placement_confirmation.html', [teamAdmin],
                    extra_context=extra_context1).start()
                ''' An order confirmation mail to Sinew Software System '''
                superAdmin = TeamUser()
                # superAdmin.email='*****@*****.**'
                superAdmin.email = '*****@*****.**'
                superAdmin.membername = teamAdmin.email if not teamAdmin.membername else teamAdmin.membername
                superAdmin.organization = teamAdmin.organization

                EmailThread(
                    'New order request for Enpass Partner: Order ID %s ' %
                    obj.order_id,
                    'orderinfo/order_request.html', [superAdmin],
                    extra_context=extra_context1).start()

            except:
                pass
        return super(OrderRequestAdmin,
                     self).save_model(request, obj, form, change)
Exemple #6
0
    def make_active(self, request, queryset):
        owner_org = TeamUser.objects.get(user=request.user).organization
        activated_users = []

        if ((owner_org.no_of_active_users() +
             queryset.filter(active=False).count()) >
                owner_org.no_of_licences()):
            messages.error(request, "You do not have sufficient licenses.")
        else:
            for a in queryset.filter(active=False):
                a.active = True
                a.save()
                activated_users.append(a)
        EmailThread('Enpass account activation for %s' % owner_org.name,
                    'team/team_granted.html', activated_users).start()
Exemple #7
0
    def post(self,request,format=None):
        organization_id=request.data['organization_id']
        email=request.data['email']
        if not organization_id or not email:
            return Response({'error':True,'description':'Organization Id and Email are required.'})
        try:
            team=Team.objects.get(organizationId=organization_id)
            teamuser=TeamUser.objects.get(email=email,organization=team)

        except Team.DoesNotExist:
            return Response({'error':True,'description':'Invalid organization ID.'})
        except TeamUser.DoesNotExist:
            return Response({'error':True,
                             'description':'E-mail ID is not registered with organization. Please contact admin in your organization.'
                             })
        if teamuser.active==False:
            return Response({'error':True,
                             'description':'Partner license is not active for provided E-mail ID. Please contact admin in your organization.'
                             })
        elif not self.validate_device(teamuser):
            return Response({'error': True,
                             'description': 'you have reached a limit for maximum device used.'
                             })
        '''For demo'''
        if email=='*****@*****.**':
            return Response({'error':False,
        'description':'Please verify using the OTP sent on %s.'%email
        })
        
        '''expire the last OTP and re-generate it'''
        otps=Otp.objects.filter(teamuser=teamuser,expired=False)
        for otp in otps:
            otp.expired=True
            otp.save()

        obj=Otp.objects.create(teamuser=teamuser,one_time_password=''.join(random.choice('0123456789') for i in range(6)))
        EmailThread(
            subject='Your Enpass sign-in One-Time Password',
            template_path='team/otp_confirmation.html',
            recipient_list=[teamuser],
            extra_context={'otp':obj.one_time_password,'time':obj.created_at}
        ).start()
# TODO: remove otp from description
        return Response({'error':False,
        'description':'Please verify using the OTP sent on %s.' % email
        })