Exemple #1
0
 def post(self, request):
     forget_form = ForgetForm(request.POST)
     if forget_form.is_valid():
         email = request.POST.get("email", "")
         # 检查用户是否存在
         user_query = UserProfile.objects.filter(
             Q(email=email) | Q(mobile_phone=email))
         if not user_query:
             return render(request, "forget_password.html", {
                 "forget_form": forget_form,
                 "msg": u"用户不存在"
             })
         user = user_query.get()
         if user.email == email:
             send_register_email_async.delay(email, "forget",
                                             get_base_url(request))
             return render(request, "send_success.html")
         elif user.mobile_phone == email:
             # 发送短消息来重置密码
             c = AliyunSms()
             c.send_sms(str(email), AliyunSms.MSG_TYPE_FORGET)
             return render(request, "verify_sms.html", {"mobile": email})
     else:
         return render(request, "forget_password.html",
                       {"forget_form": forget_form})
Exemple #2
0
 def post(self, request):
     forget_form = ForgetForm(request.POST)
     if forget_form.is_valid():
         email = request.POST.get("email", "")
         # 检查用户是否存在
         user_query = UserProfile.objects.filter(
             Q(email=email) | Q(mobile_phone=email))
         if not user_query:
             return render(request, "forget_password.html", {
                 "forget_form": forget_form,
                 "msg": u"用户不存在"
             })
         user = user_query.get()
         if user.email == email:
             send_register_email_async.delay(email, "forget",
                                             request.get_host())
             return render(request, "send_success.html")
         elif user.mobile_phone == email:
             # 发送短消息来重置密码
             c = SmsClient(settings.WILDDOG_APP_ID,
                           settings.WILDDOG_API_KEY)
             c.send_code(str(email), "100000", None)
             return render(request, "verify_sms.html", {"mobile": email})
     else:
         return render(request, "forget_password.html",
                       {"forget_form": forget_form})
Exemple #3
0
 def post(self, request):
     form = AjaxGetEmailVerificationForm(request.POST)
     if form.is_valid():
         if form.data["email"] == request.user.email:
             return JsonResponse({"status": "fail", "error": "邮箱根本没变,别耍我。"})
         else:
             if UserProfile.objects.filter(
                     email=form.data["email"]).count():
                 return JsonResponse({
                     "status": "fail",
                     "error": "邮箱已经被别人使用。请使用别的邮箱。"
                 })
             else:
                 send_register_email_async.delay(form.data["email"],
                                                 send_type="update_email",
                                                 host=request.get_host())
                 return JsonResponse({"status": "success"})
     else:
         return JsonResponse({"status": "fail", "error": "邮箱格式不正确"})
Exemple #4
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, "user_register.html", {
                        "register_form": register_form,
                        "msg": "用户{0}已经存在".format(user_name),
                        "method": "email"
                    })
            pass_word = request.POST.get("password", "")
            user_profile = UserProfile()
            user_profile.nick_name = register_form.data["nickname"]
            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.to_user = user_profile.id
            user_message.from_user = user_profile
            user_message.title = "欢迎注册"
            user_message.message = "欢迎来到Nova背单词。你可以先看看有没有感兴趣的单词书,或者去找到感兴趣的班级。"
            user_message.save()

            send_register_email_async.delay(user_name, "register",
                                            get_base_url(request))
            return render(request, "user_login.html",
                          {"login_title": u"注册成功,请检查你的邮箱中的确认邮件。账号激活之后就可以登录了。"})
        else:
            return render(request, "user_register.html", {
                "register_form": register_form,
                "method": "email"
            })