コード例 #1
0
ファイル: serializers.py プロジェクト: levon2111/docker
 def save_user(validated_data):
     invitation = InvitationToUserAndWarehouseAdmin.objects.filter(email=validated_data['email']).first()
     if invitation is not None:
         if invitation.accepted:
             user = User(email=validated_data['email'])
             user.set_password(validated_data['password'])
             user.first_name = invitation.first_name
             user.last_name = invitation.last_name
             user.is_staff = False
             user.is_active = True
             user.role = invitation.role
             user.email_confirmation_token = generate_unique_key(user.email)
             user.save()
             if user.role == 'general':
                 company_general_user = CompanyUser(user=user, company=invitation.company)
                 company_general_user.save()
             elif user.role == 'warehouse':
                 warehouse_admin = CompanyWarehouseAdmins(user=user, company=invitation.company)
                 warehouse_admin.save()
             msg = "%s %s (%s) accepted your invitation." % (
                 invitation.first_name, invitation.first_name, invitation.role)
             from_invited_user = User.objects.filter(pk=invitation.user).first()
             print(from_invited_user)
             if from_invited_user.role == 'warehouse':
                 notif = WarehouseAdminNotifications(user=from_invited_user.id, text=msg, seen=False)
                 notif.save()
             notification = CompanyAdminsNotification(company=invitation.company, text=msg)
             notification.save()
             InvitationToUserAndWarehouseAdmin.objects.filter(email=validated_data['email']).delete()
         else:
             raise serializers.ValidationError({'detail': 'Account not accepted.'})
     else:
         raise serializers.ValidationError({'detail': 'Invalid email'})
コード例 #2
0
 def save_user(validated_data):
     user = User(email=validated_data['email'])
     user.set_password(validated_data['password'])
     user.first_name = validated_data.get('first_name', None)
     user.last_name = validated_data.get('last_name', None)
     user.is_active = True
     user.save()
コード例 #3
0
    def handle(self, *args, **options):
        with transaction.atomic():
            sponsor = User.objects.first()
            sponsor.status = 'active'
            sponsor.wallet = '3KRGxJLyFH7mLJG3yvwymADnDoDFzfJ73D'
            sponsor.save()

            plan = Plans.objects.first()
            expiry_date = datetime.now() + timedelta(
                days=settings.PAGSIM_EXPIRY_DAYS)

            c = Charges()
            c.amount = plan.down
            c.expiry_date = expiry_date
            c.description = "{} PLAN PAYMENT BY {}".format(
                plan.name, sponsor.username)
            c.identifier = uuid.uuid4().hex
            c.return_url = 'http://*****:*****@example.com'.format(i)
                user.status = 'active'
                user.save()

                c = Charges()
                c.amount = plan.down
                c.expiry_date = expiry_date
                c.description = "{} PLAN PAYMENT BY {}".format(
                    plan.name, user.username)
                c.identifier = uuid.uuid4().hex
                c.return_url = 'http://localhost:8000{}'.format(
                    reverse('financial-payment-received'))
                c.plan = plan
                c.user = user
                c.request = json.dumps([1, 2, 3])
                c.response = json.dumps([1, 2, 3])
                c.wallet = '3KRGxJLyFH7mLJG3yvwymADnDoDFzfJ73D'
                c.transaction_status = 1
                c.status = 1
                c.save()

                print("Creating user Demo {}".format(i))
コード例 #4
0
 def save_user(validated_data):
     """
     Saving signed up user to db,
     Send email address confirmation email to user.
     """
     user = User(email=validated_data['email'])
     user.set_password(validated_data['password'])
     user.is_active = False
     user.first_name = validated_data['first_name']
     user.last_name = validated_data['last_name']
     user.is_active = False
     user.email_confirmation_token = generate_unique_key(user.email)
     user.save()
     send_email_job(
         user.email,
         'account_confirmation',
         {'token': user.email_confirmation_token},
         'Email Confirmation',
     )