def register(request): username = request.POST.get("username") passwd = request.POST.get("password") confirm_passwd = request.POST.get("confirm_password") email= request.POST.get("email") if passwd==confirm_passwd and len(passwd) >= 8: user = UserInfo() passwd = gen_sec_passwd(passwd) confirm_passwd = gen_sec_passwd(confirm_passwd) user.username = username user.passwd = passwd user.confirm_passwd = confirm_passwd user.email = email user.save() print("加密后的密码是:%s"%passwd) return HttpResponse("注册成功") print("*"*50) print(username, passwd, confirm_passwd, email) return HttpResponse("密码输入不符合规范")
def post(self, request): register_form = RegisterForm(request.POST) if register_form.is_valid(): email = request.POST.get('email', '') if UserInfo.objects.filter(email=email): return render(request, 'register.html', { 'register_form': register_form, 'message': '用户已经存在!' }) pass_word = request.POST.get('password', '') user_profile = UserInfo() user_profile.username = email user_profile.email = email user_profile.is_active = False user_profile.password = make_password(pass_word) user_profile.save() # 发送邮箱,这里会生成一个16位随机数并存储到EmailVerify中 send_register_email(email, 'register') return HttpResponseRedirect(reverse('user:login')) else: return render(request, 'register.html', {'register_form': register_form})