コード例 #1
0
 def post(self, request):
     forget_form = ForgetForm(request.POST)
     all_banners = LoginBanner.objects.all().order_by('index')[:5]
     if forget_form.is_valid():
         email = request.POST.get("email", "")
         if UserProfile.objects.filter(email=email):
             user = UserProfile.objects.get(email=email)
             if user.is_active:
                 send_register_email(email, 'forget')  # 发邮件
                 return render(
                     request, 'login.html', {
                         'username': email,
                         'msg': '密码重置链接已经已发送,请前往邮箱查收',
                         'all_banners': all_banners
                     })
             else:
                 send_register_email(email, 'register')
                 return render(
                     request, 'login.html', {
                         'username': email,
                         'msg': '邮箱未验证,已重新发送激活链接',
                         'all_banners': all_banners
                     })
         else:
             return render(
                 request, 'forgetpwd.html', {
                     "forget_from": forget_form,
                     'msg': '未找到该账户',
                     'all_banners': all_banners
                 })
     else:
         return render(request, "forgetpwd.html", {
             "forget_from": forget_form,
             'all_banners': all_banners
         })
コード例 #2
0
 def post(self, request):
     forget_form = ForgetForm(request.POST)
     if forget_form.is_valid():
         email = request.POST.get('email', '')
         if UserProfile.objects.filter(email=email):
             send_register_email(email=email, send_type='forget')
             return render(request, 'send_success.html')
         else:
             return render(request, 'forget_pwd.html', {'msg': '账号不存在!', 'forget_form': forget_form})
     else:
         return render(request, 'forget_pwd.html', {'forget_form': forget_form})
コード例 #3
0
    def get(self, request):
        # 取出需要发送的邮件
        email = request.GET.get("email", "")
        # 不能是已注册的邮箱
        if UserProfile.objects.filter(email=email):
            return HttpResponse('{"email":"邮箱已经存在"}',
                                content_type='application/json')
        send_register_email(email, 'update_email')

        return HttpResponse('{"status":"success"}',
                            content_type='application/json')
コード例 #4
0
    def post(self, request):
        register_form = RegisterForm(request.POST)
        all_banners = LoginBanner.objects.all().order_by('index')[:5]
        if register_form.is_valid():
            user_name = request.POST.get("email", "")
            if UserProfile.objects.filter(email=user_name):
                return render(
                    request, "register.html", {
                        'msg': '邮箱已被注册',
                        'register_form': register_form,
                        'all_banners': all_banners
                    })
            else:
                pass_word1 = request.POST.get("password1", "")
                pass_word2 = request.POST.get("password2", "")
                if pass_word1 == pass_word2:
                    user_profile = UserProfile()
                    user_profile.is_active = False
                    user_profile.username = user_name
                    user_profile.email = user_name
                    user_profile.password = make_password(pass_word2)
                    user_profile.save()  #保存至数据库
                    send_register_email(user_name, 'register')  #发邮件

                    # # 写入欢迎消息
                    user_message = UserMessage()
                    user_message.user = user_profile.id
                    user_message.message = "欢迎注册iLearn!!"
                    user_message.save()
                    return render(
                        request, 'login.html', {
                            'username': user_name,
                            'msg': '激活链接已经已发送,前往邮箱请激活',
                            'all_banners': all_banners
                        })
                else:
                    return render(
                        request, "register.html", {
                            'msg': '密码不一致,请重新输入',
                            'register_form': register_form,
                            'all_banners': all_banners
                        })
        else:
            return render(request, "register.html", {
                'register_form': register_form,
                'all_banners': all_banners
            })
コード例 #5
0
    def post(self, request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            user_name = request.POST.get('email', '')
            if UserProfile.objects.filter(email=user_name):
                return render(request, 'register.html', {'msg': '用户已经存在!', 'register_form': register_form})
            else:
                pass_word = request.POST.get('password', '')
                user = UserProfile()
                user.username = user_name
                user.email = user_name
                user.is_active = False
                user.password = make_password(pass_word)
                user.save()

                send_register_email(user_name, 'register')
                return render(request, 'login.html')
        else:
            return render(request, 'register.html', {'register_form': register_form})
コード例 #6
0
 def post(self, request):
     login_form = LoginForm(request.POST)  #传入字典参数
     all_banners = LoginBanner.objects.all().order_by('index')[:5]
     if login_form.is_valid():
         user_name = request.POST.get("username", "")
         pass_word = request.POST.get("password", "")
         user = authenticate(username=user_name, password=pass_word)
         if user is not None:
             if user.is_active:
                 login(request, user)
                 return HttpResponseRedirect(reverse("index"))
             else:
                 all_records = UserProfile.objects.filter(
                     username=user_name)
                 for record in all_records:
                     email = record.email
                     if UserProfile.objects.filter(email=email):
                         send_register_email(email, 'register')  # 发邮件
                         return render(
                             request, 'login.html', {
                                 'login_form': login_form,
                                 'msg': '账户未激活,已重新发送激活链接至您的邮箱',
                                 'all_banners': all_banners
                             })
                     else:
                         return render(
                             request, 'login.html', {
                                 'login_form': login_form,
                                 'msg': '账户未激活',
                                 'all_banners': all_banners
                             })  #添加手机验证
         else:
             return render(
                 request, 'login.html', {
                     'login_form': login_form,
                     'msg': '用户名或密码错误',
                     'all_banners': all_banners
                 })
     else:
         return render(request, 'login.html', {
             'login_form': login_form,
             'all_banners': all_banners
         })