def register(request): if request.session.get('is_login', None): return redirect('/index/') if request.method == 'POST': register_form = RegisterForm(request.POST) message = "请检查填写内容" if register_form.is_valid(): username = register_form.cleaned_data['username'] password1 = register_form.cleaned_data['password1'] password2 = register_form.cleaned_data['password2'] email = register_form.cleaned_data['email'] sex = register_form.cleaned_data['sex'] if password1 != password2: message = "两次输入的密码不相同" return render(request, 'register.html', locals()) else: same_name_user = User.objects.filter(user_name=username) if same_name_user: message = "用户已经存在,请重新输入" return render(request, 'register.html', locals()) same_email_user = User.objects.filter(email=email) if same_email_user: message = "该邮箱已经被注册,请使用其他邮箱" return render(request, 'register.html', locals()) new_user = User.objects.create() new_user.user_name = username new_user.password = password1 new_user.email = email new_user.sex = sex new_user.save() return redirect('/index/') register_form = RegisterForm() return render(request, 'register.html', locals())
def register(request): if request.session.get('is_login', None): return redirect('/index/') if request.method == 'POST': register_form = RegisterForm(request.POST) message = "请检查填写内容" if register_form.is_valid(): username = register_form.cleaned_data['username'] password1 = register_form.cleaned_data['password1'] password2 = register_form.cleaned_data['password2'] email = register_form.cleaned_data['email'] sex = register_form.cleaned_data['sex'] if password1 != password2: message = '两次输入的密码不同!' return render(request, 'login/register.html', locals()) else: same_name_user = models.User.objects.filter(name=username) if same_name_user: message = '用户名已存在,请重新注册!' return render(request, 'login/register.html', locals()) same_email_user = models.User.objects.filter(email=email) if same_email_user: message = '该邮箱已被注册,请选择其他邮箱注册!' return render(request, 'login/register.html', locals()) new_user = models.User.objects.create() new_user.name = username new_user.password = hash_maker(password1) new_user.email = email new_user.sex = sex new_user.save() return redirect('/login/') register_form = RegisterForm() return render(request, 'login/register.html', locals())
def post(self, request): json_data = request.POST if not json_data: return to_json_data(errno=Code.PARAMERR, errmsg="参数为空,请重新输入") if not request.POST.get('aggree'): return to_json_data(errno=Code.AGGREE, errmsg=error_map[Code.AGGREE]) use_key = ['username', "password", "password_repeat", "email"] dict_data = {} for i in use_key: dict_data[i] = request.POST.get(i) form = RegisterForm(data=dict_data) if form.is_valid(): username = form.cleaned_data.get('username') password = form.cleaned_data.get('password') email = form.cleaned_data.get('email') user = User.objects.create(username=username, password=password, email=email) user.save() return render(request, 'login/index.html') else: # 定义一个错误信息列表 err_msg_list = [] for item in form.errors.get_json_data().values(): err_msg_list.append(item[0].get('message')) err_msg_str = '/'.join(err_msg_list) return to_json_data(errno=Code.PARAMERR, errmsg=err_msg_str)
def success_register(request): if request.method == "POST": myregisterform = RegisterForm(request.POST) if myregisterform.is_valid(): username = myregisterform.cleaned_data['username'] email = myregisterform.cleaned_data["email"] password = myregisterform.cleaned_data['password'] gender = myregisterform.cleaned_data['gender'] try: user = Member.objects.get(email=email) except: user = None if user: return render(request, "login/register.html", {"email_is_exist": "email is exist"}) else: mymembar = Member(username=username, email=email, password=password, gender=gender) mymembar.save() return render(request, "login/login.html") return HttpResponse("error in valid") return HttpResponse("error in register")
def register(request): if request.method == "POST": register_form = RegisterForm(request.POST) message = "请检查填写的内容!" if register_form.is_valid(): # 获取数据 username = register_form.cleaned_data['username'] password1 = register_form.cleaned_data['password1'] password2 = register_form.cleaned_data['password2'] email = register_form.cleaned_data['email'] sex = register_form.cleaned_data['sex'] if password1 != password2: # 判断两次密码是否相同 message = "两次输入的密码不同!" return render(request, 'register.html', locals()) else: same_name_user = User.objects.filter(name=username) if same_name_user: # 用户名唯一 message = '用户已经存在,请重新选择用户名!' return render(request, 'register.html', locals()) same_email_user = User.objects.filter(email=email) if same_email_user: # 邮箱地址唯一 message = '该邮箱地址已被注册,请使用别的邮箱!' return render(request, 'register.html', locals()) # 当一切都OK的情况下,创建新用户 new_user = User.objects.create() new_user.name = username new_user.password = password1 new_user.email = email new_user.sex = sex new_user.save() return redirect('/login/') # 自动跳转到登录页面 register_form = RegisterForm() return render(request, 'register.html', locals())
def register(request): if request.session.get('is_login', None): return redirect('/index/') if request.method == 'POST': register_form = RegisterForm(request.POST) message = '请检查输入的内容' if register_form.is_valid(): username = register_form.cleaned_data['username'] password1 = register_form.cleaned_data['password1'] password2 = register_form.cleaned_data['password2'] email = register_form.cleaned_data['email'] sex = register_form.cleaned_data['sex'] if password1 != password2: message = "两次输入的密码不正确!" return render(request, 'login/register.html', locals()) else: same_name = models.User.objects.filter(name=username) if same_name: message = "用户名已经被注册,请重新输入!" return render(request, 'login/register.html', locals()) same_email = models.User.objects.filter(email=email) if same_email: message = "邮箱已经被注册,请重新输入!" return render(request, 'login/register.html', locals()) new_user = models.User.objects.create( name=username, password=hash_code(password1), email=email, sex=sex) code = make_confirm_string(new_user) send_mail(email, code) return redirect('login/') return render(request, 'login/register.html', locals()) register_form = RegisterForm() return render(request, 'login/register.html', locals())
def signup(): form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): user = User(email=form.email.data, username=form.username.data, password=form.password.data) user.add_user() return redirect(url_for('app.login')) return render_template('signup.html', form=form)
def post(self, request, *args, **kwargs): self.object = None form_class = self.get_form_class() user_form = self.get_form(form_class) regstr_form = RegisterForm(self.request.POST, self.request.FILES) if (user_form.is_valid() and regstr_form.is_valid()): return self.form_valid(user_form, regstr_form) else: return self.form_invalid(user_form, regstr_form)
def employer_register(request): if request.method == 'POST': user_form = RegisterForm(request.POST) profile_form = EmployerRegisterForm(request.POST) print("Employer Register Request") if user_form.is_valid() and profile_form.is_valid(): user = user_form.save(commit=False) user.set_password(user_form.cleaned_data['password']) if not user_form.cleaned_data[ 'password'] == user_form.cleaned_data['password2']: return render(request, 'my-account-employer.html', {'errors': { 'user': '******' }}) user.is_employer = True user.save() employer = EmployerProfile.objects.create( user=user, company_name=profile_form.cleaned_data['company_name'], company_disc=profile_form.cleaned_data['company_disc'], company_type=profile_form.cleaned_data['company_type']) user.employer_profile.company_name = profile_form.cleaned_data[ 'company_name'] user.employer_profile.company_type = profile_form.cleaned_data[ 'company_type'] user.employer_profile.company_disc = profile_form.cleaned_data[ 'company_disc'] login(request, user) print("Employer Signed In:") print("Username: "******"Password: "******"company_name: ", user.employer_profile.company_name) print("company_type: ", user.employer_profile.company_type) print("company_disc: ", user.employer_profile.company_disc) return redirect('home') else: context = { 'errors': { 'user': user_form.errors, 'profile': profile_form.errors } } return render(request, 'my-account-employer.html', context) else: if request.user.is_authenticated: return redirect('home') else: register_form = RegisterForm employer_register_form = EmployerRegisterForm context = { 'register_form': register_form, 'employer_register_form': employer_register_form } return render(request, 'my-account-employer.html', context)
def register(request): if request.method == 'GET': return render(request, 'register.html') form = RegisterForm(request.POST) if form.is_valid(): User.objects.create_user(form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password']) return redirect(reverse('login:do_login')) else: return render(request, 'register.html', {'form': form})
def register(request): if request.method == 'POST': form = RegisterForm(request.POST) data = request.POST.copy() if form.is_valid(): new_user = form.save(data) logoid(new_user) return redirect('homepage') else: form = RegisterForm() return render_to_response('register.html', {'form' : form}, context_instance=RequestContext(request))
def register_accept(request): username = "******" email = "e" password = "******" gender = "m" if request.method == "POST": myregisterform = RegisterForm(request.POST) if myregisterform.is_valid(): username = myregisterform.cleaned_data['username'] email = myregisterform.cleaned_data['email'] password = myregisterform.cleaned_data['password'] gender = myregisterform.cleaned_data['gender'] # myobject = Member.objects.get(email = email) try: myobject = Member.objects.get(email=email) except Member.DoesNotExist: myobject = None if (myobject): return render(request, 'sign/register.html', {'email_is_exist': "email_is_exist"}) else: mymember = Member( username=username, email=email, password=password, gender=gender, status="off", ) mymember.save() return render(request, 'sign/login.html', {'login_success': "login_success"}) else: # ?? myregisterform = RegisterForm() # ?? return render(request, 'sign/myerror.html', { "username": username, "form": myregisterform })
def post(self, request): register_form = RegisterForm(request.POST) message = '请检查填写的内容' if register_form.is_valid(): username = register_form.cleaned_data.get('username') password1 = register_form.cleaned_data.get('password1') password2 = register_form.cleaned_data.get('password2') email = register_form.cleaned_data.get('email') gender = register_form.cleaned_data.get('gender') if password1 != password2: massage = '两次密码不同!' return render(request, 'login/register.html', locals()) else: same_name_user = UserInfo.objects.filter(username=username) if same_name_user: message = '用户名已经存在!' return render(request, 'login/register.html', locals()) same_email_user = UserInfo.objects.filter(email=email) if same_email_user: massage = '邮箱已注册' return render(request, 'login/register.html', locals()) new_user = UserInfo() new_user.username = username new_user.password = hash_code(password1) new_user.email = email new_user.gender = gender new_user.save() #发送激活邮件 serializer = Serializer(settings.SECRET_KEY, 3600) info = {'confirm': new_user.id} token = serializer.dumps(info) # bytes token = token.decode('utf8') #发邮件 # subject = '欢迎注册信息' # msage = '' # sendr = settings.EMAIL_FROM # receiver = [email] # html_msage = '<h1>{},欢迎您注册成为我们的会员</h1>请点击下面链接激活您的账户</br><a herf="http://127.0.0.1:8000/active/{}">http://127.0.0.1:8000/active/{}</a>'.format(username, token, token) # send_mail(subject, msage, sendr, receiver, html_message=html_msage) # 使用celery异步发送邮件 send_register_email.delay.delay(email, username, token) return redirect('/login') else: return render(request, 'login/register.html', locals())
def job_seeker_register(request): if request.method == 'POST': user_form = RegisterForm(request.POST) # profile_form = JobSeekerRegisterForm(request.POST, request.FILES) if user_form.is_valid(): user = user_form.save(commit=False) user.set_password(user_form.cleaned_data['password']) if not user_form.cleaned_data[ 'password'] == user_form.cleaned_data['password2']: return render(request, 'my-account-job-seeker.html', {'errors': { 'user': '******' }}) if user_form.cleaned_data[ 'first_name'] == "" or user_form.cleaned_data[ 'last_name'] is None: return render(request, 'my-account-job-seeker.html', {'errors': { 'user': '******' }}) if user_form.cleaned_data[ 'last_name'] == "" or user_form.cleaned_data[ 'last_name'] is None: return render(request, 'my-account-job-seeker.html', {'errors': { 'user': '******' }}) user.is_jobseeker = True user.save() job_seeker = JobSeekerProfile.objects.create(user=user) # user.jobseekerprofile.bio = profile_form.cleaned_data['bio'] # user.jobseekerprofile.cv = profile_form.cleaned_data['cv'] login(request, user) return redirect('home') else: context = { 'errors': { 'user': user_form.errors, } } return render(request, 'my-account-job-seeker.html', context) else: if request.user.is_authenticated: return redirect('home') else: register_form = RegisterForm context = {'register_form': register_form} return render(request, 'my-account-job-seeker.html', context)
def register(request): form = RegisterForm(request.POST) if form.is_valid(): name=form.cleaned_data['name'] password=form.cleaned_data['password'] confirm=form.cleaned_data['confirm'] if passwords_match(password, confirm): user = User(name=name, password=password) user.save() return HttpResponseRedirect(reverse('logged-in:logged-blogger-list', kwargs={'userid':user.id})) else: #make new view that says the passwords didn't match print 'password and confirm must match' return render(request, 'login/register-error.html', {'form':form}) return render(request, 'login/register.html', {'form': form})
def get(self, request, *args, **kwargs): self.object = None form_class = self.get_form_class() user_form = self.get_form(form_class) regstr_form = RegisterForm() return self.render_to_response( self.get_context_data(form1=user_form, form2=regstr_form))
def register(request): message = None if request.method == 'POST': form = RegisterForm(request.POST) data = request.POST.copy() if form.is_valid(): new_user = form.save(data) logoin(new_user) return redirect('homepage') else: message = "Datos incorrectos, campos vacios o invalidos" else: form = RegisterForm() return render_to_response('register.html', {'form' : form , 'message' : message}, context_instance=RequestContext(request))
def register(request): if request.method == 'GET': user_register_form = RegisterForm() return render(request, 'register.html', {"register_form": user_register_form}) elif request.method == 'POST': user_register_form = RegisterForm(request.POST) if user_register_form.is_valid(): username = user_register_form.cleaned_data.get("username") password = user_register_form.cleaned_data.get("password") telephone = user_register_form.cleaned_data.get("telephone") email = user_register_form.cleaned_data.get("email") User.objects.create_user(username=username, password=password, email=email, telephone=telephone) return redirect("/login/") else: # import pdb # pdb.set_trace() return render(request, "register.html", {"register_form": user_register_form})
def register(request): if request.session.get('is_login', None): # 登录状态不允许注册。你可以修改这条原则! return redirect("/") if request.method == "POST": register_form = RegisterForm(request.POST) message = "请检查填写的内容!" if register_form.is_valid(): # 获取数据 username = register_form.cleaned_data['username'] password1 = register_form.cleaned_data['password1'] password2 = register_form.cleaned_data['password2'] email = register_form.cleaned_data['email'] sex = register_form.cleaned_data['sex'] if password1 != password2: # 判断两次密码是否相同 message = "两次输入的密码不同!" return render(request, 'register.html', locals()) else: password = make_password(password1, None, 'pbkdf2_sha1') same_name_user = User.objects.filter(name=username) if same_name_user: # 用户名唯一 message = '用户已经存在,请重新选择用户名!' return render(request, 'register.html', locals()) same_email_user = User.objects.filter(email=email) if same_email_user: # 邮箱地址唯一 message = '该邮箱地址已被注册,请使用别的邮箱!' return render(request, 'register.html', locals()) # 当一切都OK的情况下,创建新用户 new_user = User() new_user.name = username new_user.password = password new_user.email = email new_user.sex = sex new_user.save() code = make_confirm_string(new_user) send_email(email, code) message = '请前往注册邮箱,进行邮件确认!' return render(request, 'confirm.html', locals()) # 跳转到等待邮件确认页面。 register_form = RegisterForm() return render(request, 'register.html', locals())
def register(request): if request.session.get('is_login', None): #登录正态下不允许注册 return redirect(reverse('index')) if request.method == 'POST': register_form = RegisterForm(request.POST) if register_form.is_valid(): username = register_form.cleaned_data['username'] password1 = register_form.cleaned_data['password1'] password2 = register_form.cleaned_data['password2'] email = register_form.cleaned_data['email'] sex = register_form.cleaned_data['sex'] if password1 != password2: message = '两次密码不一致!' return render(request, 'login/register.html', locals()) else: same_name_user = User.objects.filter(name=username) if same_name_user: message = '用户已存在,请重新选择用户!' return render(request, 'login/register.html', locals()) same_email_user = User.objects.filter(email=email) if same_email_user: # 邮箱地址唯一 message = '该邮箱地址已被注册,请使用别的邮箱!' return render(request, 'login/register.html', locals()) message = "注册成功!" # 当一切都OK的情况下,创建新用户 # 创建用户信息//有问题:放在创建用户表后面会出现DJANGO pymysql.err.IntegrityError: # (1062, "Duplicate entry '' for key 'user_name'") # 创建用户表 new_user = User.objects.create() new_user.name = username new_user.password = password1 new_user.email = email new_user.sex = sex new_user.save() return redirect(reverse('login')) register_form = RegisterForm() return render(request, 'login/register.html', locals())
def register(request): def hash_code(s, salt='mysite_login'): h = hashlib.sha256() s += salt h.update(s.encode()) # update方法只接收bytes类型 return h.hexdigest() if request.session.get('is_login', None): return redirect('index') if request.method == "POST": register_form = RegisterForm(request.POST) message = "请检查填写的内容!" if register_form.is_valid(): # 获取数据 username = register_form.cleaned_data['username'] password1 = register_form.cleaned_data['password1'] password2 = register_form.cleaned_data['password2'] email = register_form.cleaned_data['email'] sex = register_form.cleaned_data['sex'] if password1 != password2: # 判断两次密码是否相同 message = "两次输入的密码不同!" return render(request, 'login/register.html', locals()) else: same_name_user = User.objects.filter(name=username) if same_name_user: # 用户名唯一 message = '用户已经存在,请重新选择用户名!' return render(request, 'login/register.html', locals()) same_email_user = User.objects.filter(email=email) if same_email_user: # 邮箱地址唯一 message = '该邮箱地址已被注册,请使用别的邮箱!' return render(request, 'login/register.html', locals()) # 当一切都OK的情况下,创建新用户 new_user = User.objects.create() new_user.name = username new_user.password = hash_code(password1) # 使用加密密码 new_user.email = email new_user.sex = sex new_user.save() return redirect('index') # 自动跳转到登录页面 register_form = RegisterForm() return render(request, 'login/register.html', locals())
def register(request): if request.session.get('is_login', None): # 登录状态不允许注册。你可以修改这条原则! return redirect(reverse('user:index')) if request.method == "POST": register_form = RegisterForm(request.POST) message = "请检查填写的内容!" if register_form.is_valid(): # 获取数据 username = register_form.cleaned_data['username'] password1 = register_form.cleaned_data['password1'] password2 = register_form.cleaned_data['password2'] email = register_form.cleaned_data['email'] sex = register_form.cleaned_data['sex'] if password1 != password2: # 判断两次密码是否相同 message = "两次输入的密码不同!" return render(request, 'login/register.html', locals()) else: same_name_user = User.objects.filter(name=username) if same_name_user: # 用户名唯一 message = '用户已经存在,请重新选择用户名!' return render(request, 'login/register.html', locals()) same_email_user = User.objects.filter(email=email) if same_email_user: # 邮箱地址唯一 message = '该邮箱地址已被注册,请使用别的邮箱!' return render(request, 'login/register.html', locals()) # 当一切都OK的情况下,创建新用户 new_user = User() new_user.name = username new_user.password = hash_code(password1) new_user.email = email new_user.sex = sex new_user.save() code = fonfirm_email_code(new_user) send_email(email, code) message = '请到你的邮箱中确认注册信息' return render(request, 'login/confirm.html', locals()) register_form = RegisterForm() return render(request, 'login/register.html', locals())
def register(request): if request.session.get('is_login', None): # 登录状态不允许注册。你可以修改这条原则! return redirect("/index/") if request.method == "POST": register_form = RegisterForm(request.POST) message = "请检查填写的内容!" if register_form.is_valid(): # 获取数据 username = register_form.cleaned_data['username'] password1 = register_form.cleaned_data['password1'] password2 = register_form.cleaned_data['password2'] email = register_form.cleaned_data['email'] sex = register_form.cleaned_data['sex'] age = register_form.cleaned_data['age'] if password1 != password2: # 判断两次密码是否相同 message = "两次输入的密码不同!" return render(request, 'login/register.html', locals()) else: same_name_user = User.objects.filter(name=username) if same_name_user: # 用户名唯一 message = '用户已经存在,请重新选择用户名!' return render(request, 'login/register.html', locals()) same_email_user = User.objects.filter(email=email) if same_email_user: # 邮箱地址唯一 message = '该邮箱地址已被注册,请使用别的邮箱!' return render(request, 'login/register.html', locals()) # 当一切都OK的情况下,创建新用户 new_user = User.objects.create(name=username, password=password1, email=email, sex = sex, age = age) # new_user.name = username # new_user.password = password1 # new_user.email = email # new_user.sex = sex # new_user.age = int(age) new_user.save() return redirect('/login/') # 自动跳转到登录页面 register_form = RegisterForm() return render(request, 'login/register.html', locals())
def register(request): if request.session.get('is_login', None): # 登录状态不允许注册。你可以修改这条原则! return redirect("/") if request.method == "POST": register_form = RegisterForm(request.POST) message = "It cannot be empty!" if register_form.is_valid(): # 获取数据 username = register_form.cleaned_data['username'] password1 = register_form.cleaned_data['password1'] password2 = register_form.cleaned_data['password2'] email = register_form.cleaned_data['email'] if password1 != password2: # 判断两次密码是否相同 message = "The password is not the same!" return render(request, 'login/register.html', locals()) else: same_name_user = models.User.objects.filter(name=username) if same_name_user: # 用户名唯一 message = 'User name is already exist!' return render(request, 'login/register.html', locals()) same_email_user = models.User.objects.filter(email=email) if same_email_user: # 邮箱地址唯一 message = 'Email has been registed!' return render(request, 'login/register.html', locals()) # 当一切都OK的情况下,创建新用户 new_user = models.User.objects.create() new_user.name = username new_user.password = hash_code(password1) new_user.email = email new_user.save() return redirect('/log/login/') # 自动跳转到登录页面 register_form = RegisterForm() return render(request, 'login/register.html', locals())
def register(request): if request.session.get("is_login", None): return redirect("/index/") if request.method == "POST": re_form = RegisterForm(request.POST) message = "需要填写完整" if re_form.is_valid(): username = re_form.cleaned_data["username"] password1 = re_form.cleaned_data['password1'] password2 = re_form.cleaned_data['password2'] phone = re_form.cleaned_data['phone'] sex = re_form.cleaned_data['sex'] check_num = re_form.cleaned_data["check_code"] if password1 != password2: message = "两次输入密码不一致" return render(request, 'login/register.html', locals()) else: same_name_user = User.objects.filter(name=username) if same_name_user: message = '用户已经存在,请重新选择用户名!' return render(request, 'login/register.html', locals()) same_email_user = User.objects.filter(phone_number=phone) if same_email_user: message = '该手机号已被注册,请使用别的手机号!' return render(request, 'login/register.html', locals()) phone_check = PhoneCheck.objects.filter(check_number=check_num, phone_number=phone) if not phone_check: return render(request, "login/register.html", {"message": "验证码不一致"}) new_user = User.objects.create() new_user.name = username new_user.password = password1 new_user.phone_number = phone new_user.sex = sex new_user.save() return redirect('/login/') re_form = RegisterForm() return render(request, 'login/register.html', locals())
def register(request): if request.session.get('is_login',None): # 登录状态不允许注册 return redirect("/login/index/") if request.method == "POST": register_form = RegisterForm(request.POST) message = "请检查填写的内容" if register_form.is_valid(): # 获取数据 username = register_form.cleaned_data['username'] password1 = register_form.cleaned_data['password1'] password2 = register_form.cleaned_data['password2'] email = register_form.cleaned_data['email'] sex = register_form.cleaned_data['sex'] if password1 != password2: # 判断两次密码是否相同 message = "两次输入的密码不同" return render(request, 'login/register.html', locals()) else: same_name_user = models.User.objects.filter(name=username) if same_name_user: # 用户名唯一 message = "用户名已存在,请重新选择用户名" return render(request, 'login/register.html', locals()) same_email_user = models.User.objects.filter(email=email) if same_email_user: # 邮箱地址唯一 message = "该邮箱地址已经被注册,请使用别的邮箱" return render(request, 'login/register.html', locals()) # 在一切都OK的情况下,创建新用户 new_user = models.User.objects.create() new_user.name = username new_user.password = hash_code(password1) # 使用加密密码 new_user.email = email new_user.sex = sex new_user.save() return redirect('/login/login/') # 自动跳转到登录页面 register_form = RegisterForm() return render(request, 'login/register.html', locals())
def register_page(request): register_form = RegisterForm() if request.method == 'POST': register_form = RegisterForm(request.POST) if register_form.is_valid(): register_form.save() return redirect('inicio') return render(request, 'users/register.html', {'register_form': register_form})
def register(response): if response.method == 'POST': form = RegisterForm(response.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') user = authenticate(username=username, password=raw_password) login(response, user) return redirect('store') else: form = RegisterForm() return render(response, 'registration/register.html', {'form': form})
def user_register(request): """ Vista que se encarga de registrar a un usuario :param request: objeto tipo diccionario que permite acceder a datos :return: objeto que se encarga de renderar register.html :rtype: render """ if request.method == "POST": form = RegisterForm(request.POST) if form.is_valid(): form.save() return redirect('login:login') else: form = RegisterForm() return render(request, 'login/register.html', {'form': form})
def signup(request): context = {} if request.method == 'POST': form = RegisterForm(request.POST) #render form if form.is_valid(): form.save() username = form.cleaned_data.get('username') password = form.cleaned_data.get('password1') user = auth.authenticate(username=username, password=password) auth.login(request, user) #log user in automatically after registration return redirect('overview:home') else: context['registerForm'] = form else: form = RegisterForm() context['registerForm'] = form return render(request, 'signup.html', context)
def register(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') messages.success(request, f"Novo usuario criado: {username}") user = authenticate(username=username, password=raw_password) login(request, user) return redirect('index') else: form = RegisterForm() for msg in form.error_messages: messages.error(request, f"{msg}: {form.error_messages[msg]}") return render(request, 'registration/register.html', {'form': form})
def get(self, request): if request.session.get('is_login', None): return redirect('/index') register_form = RegisterForm() return render(request, 'login/register.html', locals())