コード例 #1
0
ファイル: forgot_pass_view.py プロジェクト: ijami/sepas_iran
def forgot_pass(request):
    errors = []
    if request.user.is_authenticated():
        return redirect(reverse('home'))

    if request.method == 'POST':
        email = request.POST.get('email')
        captcha = request.POST.get('captcha')

        try:
            user = User.objects.get(email=email)
        except:
            errors.extend("کاربری با این پست التکرونیک ثبت نشده")
            return render(request, 'base/forgot_pass.html', {'errors': errors})

        else:
            if captcha == '19':
                new_pass = pass_generator()
                user.set_password(new_pass)
                user.save()
                send_mail('تغییر رمز عبور', '*****@*****.**', [user.email], 'base/mail_new_pass.txt',
                          'base/mail_new_pass.html', {'user': user, 'new_pass': new_pass}, True)
                response = redirect(reverse('login'))
                response['Location'] += '?pass_changed=true'
                return response
            else:
                errors.extend("کد کپچای وارد شده نادرست است")
                return render(request, 'base/forgot_pass.html', {'errors': errors})

    return render(request, 'base/forgot_pass.html')
コード例 #2
0
    def do(self):
        # users = User.objects.all()
        tourists = Tourist.objects.all()

        for tourist in tourists:
            # print(tourist.birth_day.day ==)
            # print(str(datetime.now().day)+"/"+str(datetime.now().month)+"  "+str(tourist.birth_day.day)+"/"+str(tourist.birth_day.mounth))
            if (datetime.now().day==tourist.birth_day.day)and(datetime.now().month==tourist.birth_day.month):
                send_mail('تبریک تولد', '*****@*****.**', [tourist.primary_user.email], 'tourist/mail_birthday.txt',
                        'tourist/mail_birthday.html', {'user': tourist}, True)
コード例 #3
0
 def do(self):
     tourists = Tourist.objects.all()
     for tourist in tourists:
         recommendations = send_recommended_mail(tourist.primary_user.id)
         recommendations.sort(key=lambda x: x.sold_number)
         times = {}
         for i, recommendation in enumerate(recommendations):
             times.update(
                 {i: jdatetime.date.fromgregorian(date=recommendation.get_date()).strftime("%Y/%m/%d")})
         send_mail('پیشنهادات سپاس ایران', '*****@*****.**', [tourist.primary_user.email],
                   'tourist/mail_birthday.txt',
                   'tourist/recommendation.html',
                   {'recommendations': recommendations, 'tourist': tourist, 'times': times}, True)