def post(self, request): register_form = RegisterForm(request.POST) if register_form.is_valid(): email = request.POST.get('email', '') password = request.POST.get('password', '') if UserProfile.objects.filter(email=email): # 判断邮箱是否已经注册过了 return render(request, 'register.html', { 'register_form': register_form, 'msg': '用户已经存在!' }) else: user_profile = UserProfile() user_profile.username = email user_profile.email = email user_profile.password = make_password(password) user_profile.is_active = False user_profile.save() try: send_link_email(email) # 发送激活邮件 except AttributeError: return render(request, 'register.html', {'msg': '邮箱错误'}) return render(request, "email_send_success.html", { 'email': email, 'msg': '请前往查收并尽快激活账户' }) else: return render(request, 'register.html', {'register_form': register_form})
def post(self, request): register_form = UserRegisterForm(request.POST) if register_form.is_valid(): user_email = request.POST.get('email', '') user_password = request.POST.get('password', '') test_exist = UserProfile.objects.filter(email=user_email) if test_exist and test_exist[0].is_active: return render(request, 'register.html', { 'register_form': register_form, 'exist': u'邮箱已注册' }) user = UserProfile() user.username = user_email user.email = user_email user.password = make_password(user_password) user.is_active = False send_status = send_link_email(user_email, send_type='register') if send_status: user.save() return render( request, 'login.html', { 'error_msg': '已发送激活链接至邮件,请激活后登陆', 'user_name': user_email, 'pass_word': user_password, }) else: return render(request, 'register.html', { 'register_form': register_form, 'exist': '邮件发送失败' }) else: return render(request, 'register.html', {'register_form': register_form})
def get(self, request): email = request.GET.get('email', '') res = dict() # res['status'] = 'success' if not email: res['status'] = 'failure' return HttpResponse(json.dumps(res), content_type='application/json') try: send_link_email(email, send_type='update_email') # 发送邮箱验证码 res['status'] = 'success' return HttpResponse(json.dumps(res), content_type='application/json') except BaseException as e: res['status'] = 'failure' return HttpResponse(json.dumps(res), content_type='application/json')
def get(self, request): mail = request.GET.get('email', '') if UserProfile.objects.filter(email=mail): return HttpResponse('{"email":"邮箱已注册"}', content_type='application/json') send_status = send_link_email(email=mail, send_type='modify') if send_status: return HttpResponse('{"status":"success"}', content_type='application/json') else: return HttpResponse('{"status":"failure"}', content_type='application/json')
def post(self, request): """获取邮箱并发送重置密码链接""" forgetpwd_form = ForgetpwdForm(request.POST) if forgetpwd_form.is_valid(): email = request.POST.get('email', '') if UserProfile.objects.filter(email=email): try: send_link_email(email, send_type='forget') # 发送重置密码链接 except AttributeError: return render(request, 'forgetpwd.html', {'msg': '邮箱错误'}) return render(request, "email_send_success.html", { 'email': email, 'msg': '请前往查收并点击链接重置密码' }) else: return render(request, 'forgetpwd.html', { 'forgetpwd_form': forgetpwd_form, 'msg': '该邮箱未注册' }) else: return render(request, 'forgetpwd.html', {'forgetpwd_form': forgetpwd_form})
def post(self, request): forget_from = ForgetPasswordForm(request.POST) if forget_from.is_valid(): email = request.POST.get('email') user = UserProfile.objects.filter(email=email) if user: send_status = send_link_email(email, send_type='forget') if send_status: pass return render(request, 'forgetpwd.html', { 'forget_form': forget_from, 'no_exist': '邮件已发送' }) else: return render(request, 'forgetpwd.html', { 'forget_form': forget_from, 'no_exist': '用户不存在' }) else: return render(request, 'forgetpwd.html', {'forget_form': forget_from})