def check_numbers(self, win_numbers): ''' Checks if this ticket has the same numbers as in the win_numbers list. If it does then it will send email to the user. It will also update itself for checked and win attributes. Note: all number should be integers, no strings allowed. ''' self.checked = True self.win = 0 win_count = 0 for i in range(6): # getting n1, n2, etc. attribute of self n = getattr(self, 'n%d' % (i+1)) if n in win_numbers: win_count += 1 if win_count < 3: self.save() return False self.win = win_count self.save() if self.user.email: try: mail.send(self.user.email, 'Lottogewinn!', 'Ihr Lottoschein #%d (Ziehung: %s) hat gewonnen!' % \ (self.id, self.date)) except: pass return True
def register(request): # if already logged in just redirect to the main page if request.user.is_authenticated(): return HttpResponseRedirect(reverse('lotto:index')) if request.method == 'POST': form = UserCreateForm(request.POST) if form.is_valid(): form.save() # creates new records in the DB # authenticating user username = request.POST['username'] password = request.POST['password1'] user = authenticate(username=username, password=password) login(request, user) messages.add_message(request, messages.SUCCESS, 'Successful regisration.') if user.email: # can be some error that we don't what to handle # (like email is not an email) try: mail.send(user.email, 'Registrierung bei Lottochecker.', 'Sie wurden bei Lottochecker registriert..') except: pass return HttpResponseRedirect(reverse('lotto:index')) else: form = UserCreateForm() return render(request, 'form-page.html', { 'form': form, 'form_title': 'Register', })
def check_numbers(self, win_numbers): ''' Checks if this ticket has the same numbers as in the win_numbers list. If it does then it will send email to the user. It will also update itself for checked and win attributes. Note: all number should be integers, no strings allowed. ''' self.checked = True self.win = 0 win_count = 0 for i in range(6): # getting n1, n2, etc. attribute of self n = getattr(self, 'n%d' % (i + 1)) if n in win_numbers: win_count += 1 if win_count < 3: self.save() return False self.win = win_count self.save() if self.user.email: try: mail.send(self.user.email, 'Lottogewinn!', 'Ihr Lottoschein #%d (Ziehung: %s) hat gewonnen!' % \ (self.id, self.date)) except: pass return True
def user_login(request): # if already logged in just redirect to the main page if request.user.is_authenticated(): return HttpResponseRedirect(reverse('lotto:index')) if request.method == 'POST': form = AuthenticationForm(None, request.POST) # if login and password are correct if form.is_valid(): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) login(request, user) if user.email: # can be some error that we don't what to handle # (like email is not an email) try: mail.send(user.email, 'Anmeldung bei Lottochecker.', 'Ein Login wurde bei Lottochecker mit Ihrem' 'Konto durchgefuehrt.') except: pass messages.add_message(request, messages.SUCCESS, 'Angemeldet') return HttpResponseRedirect(reverse('lotto:ticket_list_upcoming')) else: pass #messages.add_message(request, messages.ERROR, # 'Authentication failure.') else: form = AuthenticationForm() return render(request, 'form-page.html', { 'form': form, 'form_title': 'Anmeldung', })
def user_login(request): # if already logged in just redirect to the main page if request.user.is_authenticated(): return HttpResponseRedirect(reverse('lotto:index')) if request.method == 'POST': form = AuthenticationForm(None, request.POST) # if login and password are correct if form.is_valid(): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) login(request, user) if user.email: # can be some error that we don't what to handle # (like email is not an email) try: mail.send( user.email, 'Anmeldung bei Lottochecker.', 'Ein Login wurde bei Lottochecker mit Ihrem' 'Konto durchgefuehrt.') except: pass messages.add_message(request, messages.SUCCESS, 'Angemeldet') return HttpResponseRedirect(reverse('lotto:ticket_list_upcoming')) else: pass #messages.add_message(request, messages.ERROR, # 'Authentication failure.') else: form = AuthenticationForm() return render(request, 'form-page.html', { 'form': form, 'form_title': 'Anmeldung', })