def register(request): """Present user registration form and handle registrations.""" request = _process_redirect(request) if request.method == 'POST': form = forms.RegisterForm(data=request.POST) if form.is_valid(): django_user = form.save(commit=False) user = create_profile(django_user) user.set_password(form.cleaned_data['password']) user.generate_confirmation_code() user.full_name = form.cleaned_data['full_name'] user.preflang = form.cleaned_data['preflang'] user.save() log.info(u"Registered new account for user (%s)", user) messages.success( request, _('Congratulations! Your user account ' 'was successfully created.')) path = reverse('users_confirm_registration', kwargs={ 'username': user.username, 'token': user.confirmation_code, }) url = request.build_absolute_uri(path) user.email_confirmation_code(url) msg = _('Thanks! We have sent an email to {0} with ' 'instructions for completing your ' 'registration.').format(user.email) messages.info(request, msg) response = login(request) request.session['send_registration_event'] = True return response else: messages.error( request, _('There are errors in this form. Please ' 'correct them and resubmit.')) else: form = forms.RegisterForm() redirect_field_value = request.session.get(REDIRECT_FIELD_NAME, reverse('dashboard')) return render_to_response( 'users/register.html', { 'form': form, 'domain': Site.objects.get_current().domain, 'redirect_field_name': REDIRECT_FIELD_NAME, 'redirect_field_value': urllib2.quote(redirect_field_value), }, context_instance=RequestContext(request))
def register(request): if request.session.get('is_login', None): return redirect('/index/') if request.method == 'POST': register_form = forms.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') if email.split('@')[-1] != settings.EMAIL_HOST_USER.split('@')[-1]: message = '请使用'+settings.COMPANY+'公司邮箱!' return render(request, 'register.html', locals()) 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()) new_user = User() new_user.name = username new_user.password = password1 new_user.email = email new_user.save() subject = settings.COMPANY+'VPN注册确认邮件' code = make_confirm_string(new_user) addr = settings.VPN_HOST+":"+settings.VPN_WEB_PORT html_content = ''' <p>欢迎注册{4}VPN账号!</p> <p>请点击站点链接完成注册确认!<a href="{0}/confirm/?code={1}" target=blank>{2}</a></p> <p>此链接有效期为{3}天!</p> '''.format(addr,code,addr, settings.CONFIRM_DAYS,settings.COMPANY) try: send_email(email, subject,html_content) except: message = "发送邮件失败,请联系管理员" message = '请前往邮箱进行确认!' return render(request, 'confirm.html', locals()) else: message = '输入格式有误,后台校验不通过!' return render(request, 'register.html', locals()) register_form = forms.RegisterForm() return render(request, 'register.html', locals())
def register(request): redirect_to = request.POST.get('next', request.GET.get('next', '')) if request.method=="POST": form=forms.RegisterForm(request.POST) if form.is_valid(): form.save() user=User.objects.get(username=request.POST['username'].strip()) info=models.info(user_id=user.id) info.save() if redirect_to: return redirect(redirect_to) else: return redirect('/') else: form=forms.RegisterForm() return render(request,'users/register.html',context={'form':form,'next': redirect_to})
def _form(self, name, email, password, agreement=True): return forms.RegisterForm({ 'display_name': name, 'email': email, 'registration_password': password, 'agreement': agreement })
def register(request): """Present user registration form and handle registrations.""" if REDIRECT_FIELD_NAME in request.GET: request = _clean_redirect_url(request) request.session[REDIRECT_FIELD_NAME] = request.GET[REDIRECT_FIELD_NAME] if request.method == 'POST': form = forms.RegisterForm(data=request.POST) if form.is_valid(): user = form.save(commit=False) user.set_password(form.cleaned_data['password']) user.generate_confirmation_code() user.save() user.create_django_user() log.info(u"Registered new account for user (%s)", user) messages.success( request, _('Congratulations! Your user account ' 'was successfully created.')) path = reverse('users_confirm_registration', kwargs={ 'username': user.username, 'token': user.confirmation_code, }) url = request.build_absolute_uri(path) user.email_confirmation_code(url) msg = _('Thanks! We have sent an email to {0} with ' 'instructions for completing your ' 'registration.').format(user.email) messages.info(request, msg) return http.HttpResponseRedirect(reverse('users_login')) else: messages.error( request, _('There are errors in this form. Please ' 'correct them and resubmit.')) else: form = forms.RegisterForm() return render_to_response('users/register.html', { 'form': form, }, context_instance=RequestContext(request))
def auth_forms(request): if not request.user.is_authenticated: return { 'auth_forms': { 'login_form': forms.LoginForm(), 'login_url': reverse_lazy('users:login'), 'register_form': forms.RegisterForm(), 'register_url': reverse_lazy('users:register'), } } else: return {}
def post(self, request): register_form = forms.RegisterForm(request.POST) if register_form.is_valid(): user_name = request.POST.get("username", "") if models.UserProfile.objects.filter(Q(username=user_name), Q(email=user_name)): return render(request, 'register.html', {"msg": "用户名已存在!"}) user_tel = request.POST.get("phone", "") user_pwd1 = request.POST.get("psw1", "") user_pwd2 = request.POST.get("psw2", "") if user_pwd1 != user_pwd2: return render(request, 'register.html', {"msg": "密码不一致!"}) user_profile = models.UserProfile() user_profile.username = user_name user_profile.mobile = user_tel user_profile.password = make_password(user_pwd1) user_profile.save() return HttpResponseRedirect(reverse("login")) return render(request, 'register.html', {'register_form': register_form})
def register(request): """Create a registration profile.""" form = forms.RegisterForm(request.POST or None) if request.method == 'POST' and form.is_valid(): # Create a registration profile, which also emails # activation details profile = RegisterProfile.objects.create_profile( form.cleaned_data['display_name'], form.cleaned_data['email'], form.cleaned_data['registration_password']) # Sign the user up for mailing lists if they wanted if form.cleaned_data['email_subscribe']: try: subscribe(form.cleaned_data['email'], settings.BASKET_NEWSLETTER, lang=get_language()) except Exception, err: log.warning(err) return jingo.render(request, 'users/register_done.html', {'profile': profile})