Esempio n. 1
0
    def post(self, request):

        register_from = RegisterForm(request.POST)

        if register_from.is_valid():
            user_name = request.POST['email']
            if UserProfile.objects.filter(email=user_name):
                return render(request, "register.html", {
                    "register_form": register_from,
                    "msg": "用户已经存在"
                })
            pass_word = request.POST['password']
            pass_word2 = request.POST['password2']

            if str(pass_word) != str(pass_word2):
                return render(request, "register.html", {
                    "register_form": register_from,
                    "msg": "密码不一致"
                })

            user_profile = UserProfile()
            user_profile.username = user_name
            user_profile.email = user_name
            # 调用加密函数
            user_profile.is_active = False
            user_profile.password = make_password(pass_word)
            user_profile.save()

            send_register_email(user_name, "register")

            return render(request, "login.html")
        else:
            return render(request, "register.html",
                          {"register_form": register_from})
Esempio n. 2
0
    def post(self, request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            user_name = request.POST.get("email", "")
            if User.objects.filter(email=user_name):
                if User.objects.filter(is_active=True):
                    return render(request, "register.html", {"register_form": register_form, "msg": '用户已存在'})
                elif User.objects.filter(is_active=False):
                    return render(request, "register.html",
                                  {"register_form": register_form, "msg": '用户已存在但未激活,请查收邮件验证后再登录'})
            else:
                pass_word = request.POST.get("password", "")
                user_profile = User()
                user_profile.username = user_name
                user_profile.email = user_name
                user_profile.is_active = False
                user_profile.password = make_password(pass_word)
                user_profile.save()
                # 写入欢迎注册消息
                user_message = UserMessage()
                user_message.user = User.objects.get(email=user_name)
                user_message.message = '欢迎注册AssetManage'
                user_message.save()
                #未读计数
                #unread_num = User.objects.filter(email=user_name)
                #unread_num.un

                send_register_email(user_name, "register")
                return render(request, 'login.html')
        else:
            return render(request, 'register.html', {'register_form': register_form})
Esempio n. 3
0
    def post(self, request):
        form = forgetCaptcha(request.POST)
        if form.is_valid():
            email = request.POST['email']

            send_register_email(email, 'forget')
        return render(request, 'login.html', {})
Esempio n. 4
0
    def post(self, request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            email = request.POST.get("email", "")
            try:
                if UserProfile.objects.get(email=email):
                    return render(request, "register.html", {
                        "register_form": register_form,
                        "msg": "邮箱已经存在!"
                    })
            except UserProfile.DoesNotExist:
                pass
            password = request.POST.get("password", "")
            user_profile = UserProfile()
            user_profile.username = email
            user_profile.email = email
            user_profile.is_active = False
            user_profile.password = make_password(password)
            user_profile.save()

            send_status = send_register_email(email, "register")
            if send_status:
                return render(request, "login.html", {"msg": "请先去邮箱激活!!"})
            else:
                return render(request, "register.html", {
                    "register_form": register_form,
                    "msg": "邮件发送失败"
                })
        else:
            return render(request, "register.html",
                          {"register_form": register_form})
Esempio n. 5
0
    def post(self, request):

        forget_form = ForgetForm(request.POST)
        if forget_form.is_valid():
            email = request.POST["email"]

            validata_email = UserProfile.objects.filter(email=email)

            if validata_email:
                send_register_email(email, "forget")
                return render(request, "send_success.html")

            return render(request, "forgetpwd.html", {'msg': "邮箱不存在"})

        else:
            return render(request, "forgetpwd.html",
                          {"forget_form": forget_form})
Esempio n. 6
0
 def post(self, request):
     form = CaptchaTestModelForm(request.POST)
     if form.is_valid():
         email = request.POST['email']
         if UserProfile.objects.filter(email=email):
             return render(request, 'register.html', {
                 'form_message': form,
                 'message': "用户已经存在"
             })
         password = request.POST['password']
         user = UserProfile()
         #django后台的密码为has加密密码,我们要在这里对他进行加密
         user.password = make_password(password)
         user.email = email
         user.username = email
         user.is_active = False  #表明未激活,需要从邮箱中去激活
         user.save()
         send_register_email(email, 'register')
         return render(request, 'index.html')
     else:
         return render(request, 'register.html', {'form_message': form})