def post(self, request): form = self.form(request.POST) if form.is_valid(): form.save() mailer = Mailer() mailer.send_support_message(form.cleaned_data['username']) messages.success( request, 'Message Received! We\'ll get back to you as soon as possible.' ) return render(request, 'support.html', {'form': form})
def post(self, request): message = request.POST['message'] user_name = request.POST['name'] user_email = request.POST['email'] if not message or len(message) < 1: messages.warning(request, 'Please enter your message.') if not user_name or not user_email: messages.warning(request, 'Request could not be validated please reload and try again.') mailer = Mailer() mailer.admin_response(message, user_email, user_name) messages.success(request, 'Message Sent!') return redirect(f'/admin/support')
def send_birthday_msg(self): all_users = User.objects.all() for user in all_users: if user.birthday != '' and user.birthday_msg_sent == False: today = str(timezone.now().date()) birthday = str(user.birthday) if birthday[5:] == today[5:]: Mailer().send_bd_msg(user.username, user.email) user.birthday_msg_sent = True user.save()
def post(self, request): users = User.objects.filter(is_staff=False, is_moderator=False, is_active=True).order_by('-id') emails = request.POST.getlist('emails') if not len(emails): messages.warning(request, 'Please select at least one email address') else: message = request.POST['message'] title = request.POST['message_title'] if len(message) and len(title): for email in emails: mailer = Mailer() mailer.admin_message(message, email, title) messages.success(request, 'Message Sent!') else: messages.warning(request, 'Please select at least one email address') return render(request, 'site_admin/message/index.html', {'users': users})
from django.utils import timezone from account.models import Wallet from core.models import GameSetting from referral.models import Referral from utilities.helper import Mailer, Helper from utilities.mailing import Mailer from utilities.referral_gen import ReferralTokenGenerator from utilities.site_details import get_site_details from .models import User jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER jwt_decode_handler = api_settings.JWT_DECODE_HANDLER helpers = Mailer() helper_func = Helper() class UserProfileCreationSerializer(serializers.ModelSerializer): retype_password = serializers.CharField(required=False, allow_blank=False) referral_code = serializers.CharField(required=False, allow_blank=True) print('inside userprofilecreation') class Meta(object): model = User exclude = ('calling_code',) def validate(self, cleaned_data): password = cleaned_data.get('password').lower() retype_password = cleaned_data.get('retype_password').lower() referral_code = cleaned_data.get('referral_code').lower()
def post(self, request): if not request.data.get('bank_code'): return Response( data={'response': 'Request could not be validated please reload and try again.'}, status=status.HTTP_400_BAD_REQUEST) if not request.data.get('bank_name') or len(request.data.get('bank_name')) < 1: return Response( data={'response': 'Please enter bank name.'}, status=status.HTTP_400_BAD_REQUEST) if not request.data.get('account_name') or len(request.data.get('account_name')) < 1: return Response( data={'response': 'Please enter account holder name.'}, status=status.HTTP_400_BAD_REQUEST) if not request.data.get('account_number'): return Response( data={'response': 'Please enter your account number.'}, status=status.HTTP_400_BAD_REQUEST) try: amount = float(request.data.get('amount')) except ValueError: return Response( data={'response': 'Please enter valid amount.'}, status=status.HTTP_400_BAD_REQUEST) if amount < 1: return Response( data={'response': 'Please enter amount.'}, status=status.HTTP_400_BAD_REQUEST) amount = amount * 100 charge = 0 koboless_amount = amount / 100 wallet = Wallet.objects.get(user=request.user.pk) amount_check = koboless_amount previous_withdrawals = Withdrawal.objects.filter(request_at__date=timezone.now().date(), wallet=wallet.pk).aggregate(Sum('amount')) if previous_withdrawals['amount__sum'] is not None: amount_check = float(previous_withdrawals['amount__sum']) + koboless_amount if amount_check > 50000: return Response( data={'response': 'Maximum withdrawal per day is NGN 50,000.'}, status=status.HTTP_400_BAD_REQUEST) if koboless_amount < 1000: charge = 50 koboless_amount = amount / 100 amount -= (charge * 100) if wallet.balance >= koboless_amount: balance = Misc().balance()[3][0]['balance'] if balance > amount: withdraw = Transfer() create_recipient = withdraw.create_transfer_recipient(name=request.data.get('account_name'), account_number=request.data.get('account_number'), bank_code=request.data.get('bank_code'), currency='NGN') if create_recipient[1]: wallet.bank_name = request.data.get('bank_name') wallet.bank_code = request.data.get('bank_code') wallet.bank_account_name = request.data.get('account_name') wallet.bank_account_number = request.data.get('account_number') wallet.save(update_fields=('bank_name', 'bank_code', 'bank_account_name', 'bank_account_number',)) response = withdraw.initiate(source='balance', amount=amount, currency='NGN', recipient=create_recipient[3]['recipient_code']) # print(response) if response[1]: withdrawal = Withdrawal.objects.create(wallet=wallet, amount=koboless_amount, bank_name=request.data.get('bank_name'), bank_account_name=request.data.get('account_name'), bank_account_number=request.data.get('account_number'), transaction_uid=response[3]['transfer_code']) if response[3]['status'] == 'success': withdrawal.transaction_status = 1 withdrawal.is_confirmed = True wallet.balance = F('balance') - koboless_amount wallet.save() elif response[3]['status'] == 'pending': withdrawal.transaction_status = 0 wallet.balance = F('balance') - koboless_amount wallet.save() elif response[3]['status'] == 'failed': withdrawal.transaction_status = 2 withdrawal.is_confirmed = False withdrawal.save() return Response( data={'response': 'Withdrawal request sent.'}, status=status.HTTP_200_OK) else: return Response( data={'response': 'Request could not be validated please reload and try again.'}, status=status.HTTP_400_BAD_REQUEST) return Response( data={'response': create_recipient[2]}, status=status.HTTP_400_BAD_REQUEST) mailer = Mailer() mailer.notify_balance(amount, request.user.username) return Response( data={'response': 'Request could not be validated please reload and try again.'}, status=status.HTTP_400_BAD_REQUEST) return Response( data={'response': 'You cannot withdraw more than what you have in your balance.'}, status=status.HTTP_400_BAD_REQUEST)
def post(self, request): game_amount = request.data.get('games_amount') selected_matches = request.data.get('games') try: game_check = ActiveGame.objects.get( pk=selected_matches[0]['game_date']) except (ActiveGame.DoesNotExist, TypeError): return Response(data={ 'response': 'Request could not be completed at this time.' }, status=status.HTTP_400_BAD_REQUEST) if game_check.is_active: return Response(data={'response': 'Game already in session.'}, status=status.HTTP_400_BAD_REQUEST) try: wallet = Wallet.objects.get(user=request.user.pk) except Wallet.DoesNotExist: return Response(data={ 'response': 'Request could not be completed at this time.' }, status=status.HTTP_400_BAD_REQUEST) balance_amount = wallet.balance bonus_enough = False if int(request.data.get('use_bonus')) == 1: if wallet.bonus_balance < game_amount: balance_amount = wallet.bonus_balance + wallet.balance else: bonus_enough = True balance_amount = wallet.bonus_balance if balance_amount >= game_amount: # one_match_record = Match.objects.get(pk=selected_matches[0]['id']) # game_self = ActiveGame.objects.get(pk=one_match_record.game_date.pk) slip_token = SlipTokenGenerator().token time = timezone.now() new_slip = Slip.objects.create(today=game_check, user=request.user, stake=game_amount, played_at=time, slip_token=slip_token) if int(request.data.get('use_bonus')) is 0: wallet.balance = F('balance') - game_amount else: if bonus_enough: wallet.bonus_balance = F('bonus_balance') - game_amount else: neg_sum = wallet.bonus_balance - game_amount amount_left = game_amount + neg_sum if amount_left == 0: amount_left = -(neg_sum) wallet.bonus_balance = 0 wallet.balance = F('balance') - amount_left wallet.save() if request.user.referred: referral = Referral.objects.get(user=request.user.pk) if not referral.is_settled: referral.is_settled = True referral.save(update_fields=('is_settled', )) referrer_wallet = Wallet.objects.get( user=referral.referrer.pk) referrer_wallet.bonus_balance = F('bonus_balance') + 100 referrer_wallet.save(update_fields=('bonus_balance', )) mailing = Mailer() mailing.send_referrer_winner(referral.referrer, request.user.username) for match in selected_matches: match_record = Match.objects.get(pk=match['id'], role=match['role']) Game.objects.create( slip=new_slip, match=match_record, home_team_win=match['home_team_selected'], away_team_win=match['away_team_selected'], both_even=match['even_selected'], under_two_five=match['under_two_five_selected'], over_two_five=match['over_two_five_selected']) else: return Response(data={ 'response': 'You do not have enough fund for your selection. Please fund your account and continue.' }, status=status.HTTP_400_BAD_REQUEST) return Response(data={}, status=status.HTTP_200_OK)
def alter_slip(self): if self.today_game(): total_amount = 40000 amount_per_winner = 2000 game_setting = GameSetting.objects.filter()[0] if self.today_game().decision == False: if self.today_game().game_over and self.today_game().amount_available == total_amount and self.today_game().space == 20 and self.today_game().decision is False: slips = Slip.objects.filter(today=self.today_game().pk, game_fate=0) \ .values('id', 'user', 'slip_token', 'score', 'game_fate', 'amount_won').order_by('-score') sotter = WinnersSort() map = [] if slips.count(): for slip in slips: search_record = sotter.search( slip['score'], map, 'score') if search_record and search_record[0]: map[search_record[1]].append(slip) else: map.append([slip]) space_available = int(self.today_game().space) amount_available = self.today_game().amount_available no_winners = self.today_game().winners amount_used = 0 for group in map: amount_to_receive_in_tense = sotter.amount_to_tens( len(group)) * 200 # if game_setting: # if timezone.now().date() <= game_setting.trial_ending: # amount_to_receive_in_tense = sotter.amount_to_tens( # len(group)) * 200 mailer = Mailer() if space_available >= len( group) and space_available > 0 and amount_available >= amount_to_receive_in_tense: # print("SPACE ONE: {}".format(group[0]['score'])) # print("GROUP: {}".format(len(group))) # print("SPACE: {}".format(space_available)) # (amount_available * amount_to_receive_in_tense) // 100 amount_payable = amount_per_winner space_available -= len(group) amount_won = amount_payable # / len(group) amount_available -= (amount_payable * len(group)) no_winners = no_winners + len(group) # print("GROUP MEMBERS SCORE: {}".format(group[0]['score'])) for slip in group: amount_used += amount_won user_slip = Slip.objects.get(pk=slip['id']) user_slip.amount_won = amount_won user_slip.game_fate = 1 user_slip.save(update_fields=( 'amount_won', 'game_fate',)) if not user_slip.is_special: user_wallet = Wallet.objects.get( user=user_slip.user.pk) user_wallet.balance = F( 'balance') + user_slip.amount_won user_wallet.save( update_fields=('balance',)) print('users were paid') # mailer.send_winning_msg(user_slip.user) elif space_available > 0 and len(group) > space_available and amount_available > 1: # print("SPACE TWO: {}".format(group[0]['score'])) # print("GROUP: {}".format(len(group))) # print("SPACE: {}".format(space_available)) amount_payable = amount_available / len(group) space_available = 0 # (amount_payable * len(group)) amount_available = 0 amount_won = amount_payable no_winners += len(group) for slip in group: amount_used += amount_won user_slip = Slip.objects.get(pk=slip['id']) user_slip.amount_won = amount_won user_slip.game_fate = 1 user_slip.save(update_fields=( 'amount_won', 'game_fate',)) if not user_slip.is_special: user_wallet = Wallet.objects.get( user=user_slip.user.pk) user_wallet.balance = F( 'balance') + user_slip.amount_won user_wallet.save( update_fields=('balance',)) print('below users were paid') #mail here # mailer.send_winning_msg(user_slip.user) # mailer = Mailer() # # mailer.send_my_mail(amount_used) active_game = ActiveGame.objects.get( pk=self.today_game().pk) active_game.space = space_available active_game.amount_available = amount_available active_game.winners = F('winners') + no_winners active_game.decision = True active_game.save(update_fields=( 'space', 'amount_available', 'winners', 'decision',)) elif self.today_game().game_over and self.today_game().decision: Slip.objects.filter(today=self.today_game().pk, game_fate=0).update(game_fate=2) elif self.today_game().game_over and self.today_game().decision: Slip.objects.filter(today=self.today_game().pk, game_fate=0).update(game_fate=2)
def end_raffle_draw(self): week_day = timezone.now().weekday() # if week_day is 6: # print(week_day) if week_day == 6: if timezone.make_aware( timezone.datetime( timezone.now().year, timezone.now().month, timezone.now().day, 19, 58, 0, 0)) <= timezone.now() < timezone.make_aware( timezone.datetime(timezone.now().year, timezone.now().month, timezone.now().day, 19, 59, 50, 0)): try: raffle = WeekEndRaffle.objects.get(is_active=True) except WeekEndRaffle.DoesNotExist: return False # players = RafflePlayer.objects.filter(raffle_id=raffle.pk, should_win=False) players = RafflePlayer.objects.filter(raffle=raffle.pk) Slip.objects.filter(jackpot_check=False).update( jackpot_check=True) # if players.count(): try: game_setting = GameSetting.objects.get() except GameSetting.DoesNotExist: return False winners_limit = 20 topplay_limit = game_setting.num_jackpot_winners selections = [] mod_users = User.objects.filter( is_moderator=True, is_active=True)[:(topplay_limit + 1)] moderators = [] for mod_user in mod_users: raffle_id = RaffleIdGenerator().token player = RafflePlayer.objects.create(user=mod_user, raffle_hash=raffle_id, raffle=raffle) moderators.append(player) if len(moderators) < topplay_limit: topplay_limit = len(moderators) selected_mods = [] for mod in moderators: if len(selected_mods) < topplay_limit: random_user_id = randint(0, (topplay_limit - 1)) if moderators[random_user_id] not in selected_mods: selected_mods.append(moderators[random_user_id]) else: break if len(selected_mods) > 0: for mod in selected_mods: selections.append(mod) if len(selections) < winners_limit: for player in players: if len(selections) < winners_limit: random_user_id = randint(0, (winners_limit - 1)) if players[random_user_id] not in selections: selections.append(players[random_user_id]) else: break for selection in selections: RaffleWinners.objects.create(user=selection) if not selection.user.is_moderator: user = User.objects.get(selection.user.pk) mailer = Mailer() # mailer.send_raffle_winner(user) user_wallet = Wallet.objects.get(user=user.pk) user_wallet.balance = F('balance') + 1000 user_wallet.save(update_fields=('balance', )) raffle.is_active = False raffle.ended = True raffle.ended_at = timezone.now().date() raffle.live = False raffle.save(update_fields=( 'is_active', 'ended', 'ended_at', 'live', ))
def add_raffle_members(self): today = timezone.now() day_tosix = today.weekday() + 6 # add 6 to day of the week date_difference = day_tosix - 5 # minus by 5 to get sunday's day # get the most recent sundays date sunday_date = timezone.now() - timezone.timedelta(days=date_difference) sunday_date = timezone.make_aware( timezone.datetime(sunday_date.year, sunday_date.month, sunday_date.day, 20, 5, 0, 0)) if today.weekday() == 6: if timezone.make_aware( timezone.datetime( today.year, today.month, today.day, 19, 57, 0, 0)) <= today < timezone.make_aware( timezone.datetime(today.year, today.month, today.day, 20, 5, 0, 0)): return False slips = Slip.objects.filter(played_at__gte=sunday_date, is_special=False, jackpot_check=False).values( 'id', 'user', 'slip_token', 'score', 'game_fate', 'amount_won') sotter = WinnersSort() map = [] if slips.count(): for slip in slips: # check if there is any raffle for this week or start one if none try: raffle = WeekEndRaffle.objects.get(is_active=True) except WeekEndRaffle.DoesNotExist: raffle = WeekEndRaffle.objects.create(is_active=True) if not RafflePlayer.objects.filter(user=slip['user'], raffle=raffle.pk).count(): # check if the user has played upto 5 games that week if slips.filter(user=slip['user']).count() >= 5: search_record = sotter.search(slip['user'], map, 'user') if search_record and search_record[0]: map[search_record[1]].append(slip) else: map.append([slip]) # print("MAP RECORD: {}".format(map)) selections = [] for group in map: selections.append(group[0]) # print("SELECTIONS: {}".format(selections)) for selection in selections: raffle_id = RaffleIdGenerator().token user = User.objects.get(pk=selection['user']) raffle_check = RafflePlayer.objects.filter( user=user, raffle=raffle.pk) # check_slip_won = Slip.objects.filter(played_at__gte=sunday_date, user=user.pk, game_fate=1) if not raffle_check: user_raffle = RafflePlayer.objects.create( user=user, raffle_hash=raffle_id, raffle=raffle) if not user.is_moderator: wallet = Wallet.objects.get(user=user.pk) wallet.bonus_balance = F( 'bonus_balance') + 200 wallet.save() mailer = Mailer() mailer.send_raffle_player(user, raffle_id)