def post(self, request, *args, **kwargs): register_form = RegisterForm(request.POST) # print(request.POST.get("username",""),'\n') # print(request.POST.get("password",""),'\n') if register_form.is_valid(): user_name = request.POST.get("username", "") if UserProfile.objects.filter(email=user_name): msg = "邮箱已被注册!" register_form._errors["msg"] = register_form.error_class([msg]) return render(request, "register.html", {"register_form": register_form}) password = request.POST.get("password", "") user_profile = UserProfile() user_profile.username = user_name user_profile.email = user_name user_profile.is_active = False user_profile.password = make_password(password) user_profile.save() if send_email(user_name, "register"): return render(request, "send_success.html") else: return render(request, "send_fail.html") else: messages.info(request, "邮箱地址非法!") print(2333) return render(request, "register.html", {"register_form": register_form})
def register(request): if request.method == 'POST': registration = RegisterForm(request.POST) if registration.is_valid(): print(registration.cleaned_data.get('confirm_password')) new_user = User.objects.create( name = registration.cleaned_data.get('name'), alias = registration.cleaned_data.get('alias'), email = registration.cleaned_data.get('email'), password = registration.cleaned_data.get('confirm_password') ) messages.success(request, 'Registration Success') return HttpResponseRedirect( reverse('users:index') ) else: print(registration.errors) return HttpResponseRedirect( reverse('users:index') ) else: print('not allowed!') messages.error(request, 'You are not allowed here.') return HttpResponseRedirect( reverse('users:index'))
def post(self, request): print(1) register_form = RegisterForm(request.POST) if register_form.is_valid(): print(2) user_name = request.POST.get('email') # 如果用户已存在,则提示错误信息 capt_cha = request.POST.get('captcha') if UserProfile.objects.filter(email=user_name): return render(request, 'register.html', { 'register_form': register_form, 'msg': '用户已存在' }) print(3) pass_word = request.POST.get('password') # 实例化一个user_profile对象 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_eamil(user_name, 'register') return render(request, 'login.html') else: return render(request, 'register.html', { 'register_form': register_form, 'msg': '验证码错误' })
def post(self, request): register_form = RegisterForm(request.POST) if register_form.is_valid(): user_name = request.POST.get("email", "") pass_word = request.POST.get("password", "") exist_user = UserProfile.objects.filter( Q(username=user_name) | Q(email=user_name)) if exist_user: return render(request, "forgetpwd.html", {'msg': "用户已经存在,若是本人忘记密码,请找回密码"}) # 实例化一个user_profile对象,将前台值存入 user_profile = UserProfile() user_profile.username = user_name user_profile.email = user_name user_profile.is_active = False # 加密password进行保存 user_profile.password = make_password(pass_word) user_profile.save() send_register_email(user_name, 'register') # 给用户发送消息 user_msg = UserMessage(user=user_profile.id) user_msg.message = '欢迎注册孟哥个网站' user_msg.save() return render(request, "login.html", {'msg': "激活连接已发送,注意查收"}) else: return render(request, "register.html", {"register_form": register_form})
def post(self, request): register_form = RegisterForm(request.POST) if register_form.is_valid(): user_name = request.POST.get('email', None) # 如果用户已存在,则提示错误 if UserProfile.objects.filter(email=user_name): return render(request, 'register.html', { 'register_form': register_form, 'msg': "用户已存在" }) pass_word = request.POST.get('password', None) # 实例化一个用户对象 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_eamil(user_name, 'register') return render(request, 'login.html') else: return render(request, 'register.html', {'register_form': register_form})
def post(self, request): register_form = RegisterForm(request.POST) if register_form.is_valid(): email = request.POST.get('email', '') pass_word = request.POST.get('password', '') if UserProfile.objects.filter(email=email): return render(request, 'register.html', { 'msg': '用户已经存在', 'register_form': register_form }) user_profile = UserProfile() user_profile.username = email user_profile.email = email user_profile.password = make_password(pass_word) user_profile.is_active = False user_profile.save() # 写入欢迎注册消息 user_message = UserMessage() user_message.user = user_profile.id user_message.message = '欢迎注册慕学在线网' user_message.save() send_register_email(email, 'register') return render(request, 'login.html') else: return render(request, 'register.html', {'register_form': register_form})
def post(self, request): register_form = RegisterForm(request.POST) if register_form.is_valid(): user_name = request.POST.get('email') pass_word = request.POST.get('password', '') user_profile = UserProfile() user_profile.username = user_name user_profile.email = user_name 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_form, })
def post(self, request): register_form = RegisterForm(request.POST) banners = Banner.objects.filter(type=3).order_by("index") if register_form.is_valid(): user_name = request.POST.get('email', None) # 如果用户已存在,则提示错误信息 user_exist = UserProfile.objects.filter(email=user_name) if user_exist: if user_exist.first().is_active == False: all_records = EmailVerifyRecord.objects.filter( email=user_name) if all_records: for record in all_records: record.delete() send_register_eamil(user_name, 'register') return render( request, 'register.html', { 'register_form': register_form, 'msg': '用户未激活,邮件已重发,请前往邮箱激活', "banners": banners }) return render( request, 'register.html', { 'register_form': register_form, 'msg': '用户已存在', "banners": banners }) pass_word = request.POST.get('password', None) # 实例化一个user_profile对象 user_profile = UserProfile() user_profile.username = user_name user_profile.email = user_name user_profile.is_active = False # 对保存到数据库的密码加密 user_profile.set_password(pass_word) user_profile.save() send_register_eamil(user_name, 'register') return render( request, 'register.html', { 'register_form': register_form, 'msg': '邮件已发送,请前往邮箱激活', "banners": banners }) else: return render(request, 'register.html', {'register_form': register_form})
def post(self, request): register_form = RegisterForm(request.POST) if register_form.is_valid(): user_name = request.POST.get('email', '') if PingUser.objects.filter(email=user_name): return render(request, 'register.html', {"register_form": register_form, "msg": "用户已经存在"}) pass_word = request.POST.get('password', '') user_profile = PingUser() 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_form})
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', { 'msg': '用户以注册', 'register_form': register_form }) pass_word = 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(pass_word) user_profile.save() send_register_email(email, 'register') return render(request, 'login.html', {}) else: return render(request, 'register.html', {'register_form': register_form})
def post(self, request): register_form = RegisterForm(request.POST) if register_form.is_valid(): username = request.POST.get('email', '') if UserProfile.objects.filter(email=username): return render(request, 'register.html', { 'register_form': register_form, 'msg': '用户已经存在' }) password = request.POST.get('password', '') user_profile = UserProfile(is_staff=True, username=username, email=username, password=make_password(password), is_active=False) user_profile.save() send_register_email(username, 'register') return render(request, 'login.html') return render(request, 'register.html', {'register_form': register_form})
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, 'register.html', { 'register_form': register_form, 'msg': '用户已存在' }) pass_word = request.POST.get("password", "") 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_form})