def user_enroll(request): if request.method == 'POST': print("post") # 获取提交的表单类 form = UserForm(request.POST) if form.is_valid(): print("a") # 获取电话号码 p = request.POST.get('phone') # 随机生成验证码 a = str() for i in range(5): num = str(random.randint(0, 9)) a = a + num # 向用户发送验证码 # send_sms(p, {'number': a}) # 将验证码写入session request.session['yzm'] = a request.session['phone'] = p f = request.session.get('yzm') print(f) # 设置过期时间 request.session.set_expiry(maxage) b = 1 return render(request, 'app/enroll.html', {'a': b, 'phone': p}) return render(request, 'app/enroll.html', {'form': form}) return render(request, 'app/enroll.html')
def register(request): if request.method == "POST": new_form = UserForm(request.POST) if new_form.is_valid(): username = new_form.cleaned_data['username'] firstname = new_form.cleaned_data['first_name'] lastname = new_form.cleaned_data['last_name'] email = new_form.cleaned_data['email'] password = new_form.cleaned_data['password'] confirmpassword = new_form.cleaned_data['confirm_password'] if password == confirmpassword: User.objects.create_user(username=username, first_name=firstname, last_name=lastname, email=email, password=password) messages.success(request, "User Registration Successfully !!") usr = auth.authenticate(username=username, password=password) auth.login(request, usr) return render(request, 'welcome.html') else: messages.error( request, "Password and Confirm Password does not match !!") return HttpResponseRedirect('/register/') else: new_form = UserForm() return render(request, 'register.html', {"new_form": new_form})
def register(request): user = UserForm() if request.method == "POST": user_input = UserForm(request.POST) user_input.save(commit=True) else: return render(request, 'register.html', {'user': user})
def register_phone(request): yz = 0 cf = 0 if request.method == 'POST': form1 = UserForm(request.POST) if form1.is_valid(): tel = request.POST.get('tel') yzm = request.POST.get('yzm') password = request.POST.get('password') birthday = request.POST.get('birthday') user = User.objects.filter(tel=tel).first() if not user: if yzm == request.session['yzm_num2']: b_password = hashlib.sha1( password.encode('utf-8')).hexdigest() User.objects.create(tel=tel, password=b_password, birth=birthday, hwid='hw_' + tel) return redirect(reverse('app:login')) else: yz = -1 return render(request, 'common/register_phone.html', { 'form': form1, 'yz': yz, 'cf': cf }) else: cf = -1 return render(request, 'common/register_phone.html', { 'form': form1, 'yz': yz, 'cf': cf }) else: return render(request, 'common/register_phone.html', { 'form': form1, 'yz': yz, 'cf': cf }) else: form1 = UserForm() return render(request, 'common/register_phone.html', {'form': form1})
def register(request): if request.method == "GET": form = UserForm() return render(request, "register.html", context={"form": form}) else: form = UserForm(request.POST) if form.is_valid(): code = form.cleaned_data.get("code") print("=====") scode = request.session.get('code') print(code, scode) if code.lower() != scode.lower(): return render(request, "register.html", context={ "form": form, "msg": "验证码输入有误" }) else: del form.cleaned_data['recpassword'] value = form.cleaned_data['password'] print(value) form.cleaned_data["password"] = hashlib.sha1( value.encode("utf8")).hexdigest() print(form.cleaned_data) del form.cleaned_data['code'] User.objects.create(**form.cleaned_data) return render(request, 'login.html') return render(request, "register.html", context={"form": form})
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'profile_pic' in request.FILES: profile.profile_pic = request.FILES['profile_pic'] profile.save() registered = True else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileInfoForm() return render( request, 'register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def register_email(request): yz = 0 cf = 0 if request.method == 'POST': print('66666666') form1 = UserForm2(request.POST) if form1.is_valid(): print('5555555') email = request.POST.get('email') yzm = request.POST.get('yzm') password = request.POST.get('password') birthday = request.POST.get('birthday') user = User.objects.filter(email=email).first() if not user: print('1111111111111') if yzm == request.session['yzm_num3']: print('22222222222222') b_password = hashlib.sha1( password.encode('utf-8')).hexdigest() User.objects.create(email=email, password=b_password, birth=birthday, hwid='hw_' + email) return redirect(reverse('app:login')) else: print('3333333333') yz = -1 return render(request, 'common/email_register.html', { 'form': form1, 'yz': yz, 'cf': cf }) else: print('444444444444444') cf = -1 return render(request, 'common/email_register.html', { 'form': form1, 'yz': yz, 'cf': cf }) else: print('77777') return render(request, 'common/email_register.html', { 'form': form1, 'yz': yz, 'cf': cf }) else: form1 = UserForm() return render(request, 'common/email_register.html', {'form': form1})
def register(request): context = RequestContext(request) registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.username=user.email user.is_active = False user.save() profile = profile_form.save(commit=False) profile.user = user profile.save() subject = "Gracias por Registarse a nustra red social cristiana DITAM te ama" var1 = str(user.email)+str(user.pk)+"ditam" var1 = var1.encode('utf-8') var2 = hashlib.md5(var1) var2 = var2.hexdigest() message = "Para confirmar su cuenta con la red DITAM haga click en el siguiente enlace: http://192.168.1.102:8000/confirmacion?hash="+str(var2)+"&token="+str(user.pk)+"" from_email = settings.EMAIL_HOST_USER to_list = [user.email, settings.EMAIL_HOST_USER] send_mail(subject,message,from_email,to_list,fail_silently=False); registered = True return render(request,'registroCompleto.html',{}) else: pass else: user_form = UserForm() profile_form = UserProfileForm() return render_to_response( 'register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, context)