예제 #1
0
 def post(self, request):
     register_form = RegisterForm(request.POST)
     if register_form.is_valid():
         email = request.POST.get("email", '')
         if UserProfile.objects.filter(email=email):
             return render(request, 'register.html', {
                 'register_form': register_form,
                 'msg': '用户已存在'
             })
         pass_word = request.POST.get("password", '')
         user_name = request.POST.get("username", '')
         if UserProfile.objects.filter(username=user_name):
             return render(request, 'register.html', {'msg': '此用户名已被使用'})
         user_profile = UserProfile()
         user_profile.username = user_name
         user_profile.email = email
         user_profile.is_active = False
         user_profile.password = make_password(pass_word)
         user_profile.save()
         send_email_register(email, 'register')
         return render(request, 'login_user.html',
                       {'msg': "发送邮件成功,请注意查收..."})
     else:
         email = request.POST.get("email", '')
         return render(request, 'register.html', {
             'email': email,
             'register_form': register_form
         })
예제 #2
0
def sendemil_code(request):
    '''发送邮箱验证码'''
    if request.method == "GET":

        email = request.GET.get("email", "")
        if UserProfile.objects.filter(email=email):
            return HttpResponse('{"email":"此邮箱已注册"}',
                                content_type="application/json")
        send_email_register(email, "update_email")
        return HttpResponse('{"status":"success"}',
                            content_type="application/json")
예제 #3
0
def user_register(request):
    if request.method == "GET":
        register_form = RegisterForm(request.POST)
        course_banner = Couse.objects.filter(is_banner=True)[:3]
        return render(request, 'register.html', {
            "register_form": register_form,
            "course_banner": course_banner
        })
    elif request.method == "POST":
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():

            username = email = request.POST.get("email", "")

            password = request.POST.get("password", "")
            try:
                user_profile = UserProfile.objects.get(
                    Q(username=username) | Q(email=username))

            except Exception as e:
                user_profile = None
            if user_profile:
                if user_profile.is_active:

                    return render(request, 'login.html', {
                        "register_form": register_form,
                        "message": "用戶已存在"
                    })
                else:
                    return render(
                        request, 'login.html', {
                            "message": "用戶已注册,但未激活,请进入邮箱激活",
                            "register_form": register_form
                        })

            user_profile = UserProfile()
            user_profile.username = username
            user_profile.is_active = False
            user_profile.email = email
            user_profile.password = make_password(password)
            user_profile.save()
            #添加欢迎信息
            # user_message = UserMessage(user=request.user)
            #
            # user_message.message = "欢迎注册木叶忍术教育,先告诉你一个真理,那就是:志颖美如画志颖美如画志颖美如画志颖美如画志颖美如画志颖美如画"
            # user_message.save()
            send_email_register(email, "register")
            return render(request, "login.html")
            print("f**k you")
        else:
            print("f**k")
            return render(request, "register.html",
                          {"register_form": register_form})
예제 #4
0
def user_forgetpwd(request):
    if request.method == "GET":
        froget_form = forgetForm()
        return render(request, 'forgetpwd.html', {"forget_form": froget_form})
    if request.method == "POST":
        froget_form = forgetForm(request.POST)
        if froget_form.is_valid():
            email = request.POST.get("email", '')
            send_email_register(email, "forget")
            return render(request, "send_success.html",
                          {"message_email": "邮件发送成功,请注意查收"})
        else:
            return render(request, "send_success.html",
                          {"message_email": "邮件发送失败,请稍后重试"})
예제 #5
0
def upload_password(request):
    '''个人中心里修改密码'''
    if request.method == "GET":
        # froget_form = forgetForm(request.POST)

        email = request.GET.get("email", '')
        status = send_email_register(email, "forget")
        if status:
            return ajax_ok_data(message="邮件发送成功,请注意查收")
        else:
            return ajax_fail_data(message="邮件发送成功,请注意查收")

    if request.method == "POST":
        repwd_form = resetpwdForm(request.POST)
        if repwd_form.is_valid():
            email = request.POST.get("email", '')
            code = request.POST.get("code", "")
            password1 = request.POST.get("password1", '')
            password2 = request.POST.get("password2", '')
            token = request.COOKIES.get("token")
            o = EmailVerifyRecord.objects.get(email=email,
                                              code=code,
                                              send_type="forget")
            if password1 == password2 and o:
                user = UserProfile.objects.get(token=token)
                user.password = make_password(password1)
                user.save()

                return ajax_ok_data(message="修改成功")
            else:
                return ajax_fail_data(message="兩次輸入的密碼不一致")
        data = repwd_form.errors
        return ajax_ok_data(data)
예제 #6
0
 def post(self, request):
     forget_form = ForgetPwdForm(request.POST)
     if forget_form.is_valid():
         email = request.POST.get('email', '')
         user = UserProfile.objects.filter(email=email)
         if user:
             send_email_register(email, 'forget')
             return render(request, 'login_user.html',
                           {'msg': "邮件发送成功,请查收..."})
         else:
             return render(request, 'forgetpwd.html', {
                 'forget_form': forget_form,
                 'msg': '邮箱错误'
             })
     else:
         return render(request, 'forgetpwd.html',
                       {'forget_form': forget_form})
예제 #7
0
def reset(request):
    """找回密码发送验证码"""
    if request.method == "POST":
        email = request.POST.get("email", "")
        status = send_email_register(email, "forget")
        if status:
            return ajax_ok_data(message="邮件发送成功")
        else:
            return ajax_fail_data(message="邮件发送失败")
예제 #8
0
def send_regieser_code(request):
    """注册获取验证码"""
    if request.method == "POST":
        email = request.POST.get("email", '')
        status = send_email_register(email, "register")
        if status:
            return ajax_ok_data(message="邮件发送成功,请注意查收")
        else:
            return ajax_ok_data(message="邮件发送失败")
예제 #9
0
def sendemil_code(request):
    '''更换邮箱时发送邮箱验证码'''
    if request.method == "POST":

        email = request.GET.get("email", "")
        if UserProfile.objects.filter(email=email):

            return ajax_ok_data(message="此邮箱已经注册")
        status = send_email_register(email, "update_email")
        if status:
            return ajax_ok_data(message="邮件发送成功")
        else:
            return ajax_fail_data(message="邮件发送失败")