Python django.contrib.auth.forms.UserCreationForm() Examples
The following are 23 code examples for showing how to use django.contrib.auth.forms.UserCreationForm(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
django.contrib.auth.forms
, or try the search function
.
Example 1
Project: SEMS Author: urankajtazaj File: views.py License: GNU General Public License v3.0 | 6 votes |
def user_add(request): if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): form.save() uid = Student.objects.latest('pk').pk return redirect('user_edit', pk=uid) else: form = UserCreationForm() print(form.errors) if request.user.is_authenticated and request.user.is_superuser: return render( request, 'user_add.html', {'form': form}, ) else: return redirect('login')
Example 2
Project: python-monitoring-talk Author: amitsaha File: views.py License: Apache License 2.0 | 6 votes |
def signup(request): if request.user.is_authenticated: return HttpResponseRedirect('/post/') if request.method == 'GET': form = UserCreationForm() return render(request, 'tilweb/signup.html', {'form': form}) if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): # https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/#the-save-method form.save() username = form.cleaned_data.get('username') password = form.cleaned_data.get('password1') user = authenticate(username=username, password=password) login(request, user) return HttpResponseRedirect('/post/') else: # If there were errors, we render the form with these # errors return render(request, 'tilweb/signup.html', {'form': form})
Example 3
Project: python-monitoring-talk Author: amitsaha File: views.py License: Apache License 2.0 | 6 votes |
def signup(request): if request.user.is_authenticated: return HttpResponseRedirect('/post/') if request.method == 'GET': form = UserCreationForm() return render(request, 'tilweb/signup.html', {'form': form}) if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): # https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/#the-save-method form.save() username = form.cleaned_data.get('username') password = form.cleaned_data.get('password1') user = authenticate(username=username, password=password) login(request, user) return HttpResponseRedirect('/post/') else: # If there were errors, we render the form with these # errors return render(request, 'tilweb/signup.html', {'form': form})
Example 4
Project: c3nav Author: c3nav File: account.py License: Apache License 2.0 | 6 votes |
def register_view(request): redirect_path = request.GET['r'] if request.GET.get('r', '').startswith('/editor/') else reverse('editor.index') if request.user.is_authenticated: return redirect(redirect_path) if request.method == 'POST': form = UserCreationForm(data=request.POST) if form.is_valid(): user = form.save() login(request, user) return redirect(redirect_path) else: form = UserCreationForm() form.fields['username'].max_length = 20 for field in form.fields.values(): field.help_text = None return render(request, 'editor/account_form.html', { 'title': _('Create new account'), 'back_url': reverse('site.login'), 'form': form })
Example 5
Project: Django-Bookworm Author: OmkarPathak File: views.py License: MIT License | 5 votes |
def signup(request): if request.method == 'POST': form = UserCreationForm(request.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(request, user) return redirect('books') else: form = UserCreationForm() return render(request, 'signup.html', {'form': form})
Example 6
Project: tramcar Author: tramcar File: forms.py License: MIT License | 5 votes |
def __init__(self, *args, **kwargs): super(CssUserCreationForm, self).__init__(*args, **kwargs) self.label_suffix = '' self.fields['username'].widget.attrs['class'] = 'form-control' self.fields['email'].widget.attrs['class'] = 'form-control' self.fields['password1'].widget.attrs['class'] = 'form-control' self.fields['password2'].widget.attrs['class'] = 'form-control' # UserCreationForm doesn't include email, so we add it and make it required
Example 7
Project: GetTogether Author: GetTogetherComm File: user.py License: BSD 2-Clause "Simplified" License | 5 votes |
def login(request): if request.user.is_authenticated: messages.add_message( request, messages.INFO, message=_("You are already logged in.") ) return redirect("home") context = {"login_form": AuthenticationForm(), "signup_form": UserCreationForm()} if request.method == "POST": if request.POST.get("action") == "login": login_form = AuthenticationForm(data=request.POST) if login_form.is_valid(): username = login_form.cleaned_data.get("username") raw_password = login_form.cleaned_data.get("password") user = authenticate(username=username, password=raw_password) login_user(request, user, backend=user.backend) return redirect("home") else: context["login_form"] = login_form context["action"] = "login" elif request.POST.get("action") == "signup": signup_form = UserCreationForm(data=request.POST) if signup_form.is_valid(): signup_form.save() username = signup_form.cleaned_data.get("username") raw_password = signup_form.cleaned_data.get("password1") user = authenticate(username=username, password=raw_password) login_user(request, user, backend=user.backend) return redirect("home") else: context["signup_form"] = signup_form context["action"] = "signup" return render(request, "get_together/users/login.html", context)
Example 8
Project: c3nav Author: c3nav File: views.py License: Apache License 2.0 | 5 votes |
def register_view(request): if not settings.USER_REGISTRATION: return HttpResponse(_('account creation is currently disabled.'), content_type='text/plain', status=403) if request.user.is_authenticated: return close_response(request) if request.method == 'POST': form = UserCreationForm(data=request.POST) if form.is_valid(): user = form.save() login(request, user) redeem_token_after_login(request) return close_response(request) else: form = UserCreationForm() form.fields['username'].max_length = 20 for field in form.fields.values(): field.help_text = None return render(request, 'site/account_form.html', { 'title': _('Create new account'), 'back_url': reverse('site.login'), 'form': form })
Example 9
Project: mysite Author: its-django File: views.py License: Apache License 2.0 | 5 votes |
def register(request): """new user register page :request: client request :returns: redirect to login page if success else register page """ if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() return HttpResponseRedirect('/accounts/login/') else: form = UserCreationForm() return render(request, 'register.html', locals())
Example 10
Project: callisto-core Author: project-callisto File: test_views.py License: GNU Affero General Public License v3.0 | 5 votes |
def test_displays_signup_form(self): response = self.client.get(self.signup_url) self.assertIsInstance(response.context["form"], UserCreationForm) self.assertContains(response, 'name="password2"')
Example 11
Project: django-example-channels Author: realpython File: views.py License: MIT License | 5 votes |
def sign_up(request): form = UserCreationForm() if request.method == 'POST': form = UserCreationForm(data=request.POST) if form.is_valid(): form.save() return redirect(reverse('example:log_in')) else: print(form.errors) return render(request, 'example/sign_up.html', {'form': form})
Example 12
Project: iguana Author: iguana-project File: forms.py License: Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def __init__(self, *args, **kwargs): super(UserCreationForm, self).__init__(*args, **kwargs) self.fields['username'].widget.attrs.pop('autofocus', None)
Example 13
Project: jeeves Author: jeanqasaur File: views.py License: MIT License | 5 votes |
def register_account(request): if request.user.is_authenticated(): return HttpResponseRedirect("index") if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() user.save() UserProfile.objects.create( username=user.username, name=request.POST.get('name',''), affiliation=request.POST.get('affiliation',''), level='normal', email=request.POST.get('email', ''), ) user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) return HttpResponseRedirect("index") else: form = UserCreationForm() return render_to_response("registration/account.html", RequestContext(request, { 'form' : form, 'which_page' : "register" }))
Example 14
Project: jeeves Author: jeanqasaur File: views.py License: MIT License | 5 votes |
def register_account(request): if request.user.is_authenticated(): return HttpResponseRedirect("index") if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() user.save() UserProfile.objects.create( username=user.username, email=request.POST.get('email', ''), ) user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) return HttpResponseRedirect("index") else: form = UserCreationForm() return render_to_response("registration/account.html" , RequestContext(request, {'form': form, 'which_page' : "register"}))
Example 15
Project: jeeves Author: jeanqasaur File: views.py License: MIT License | 5 votes |
def register_account(request): if request.user.is_authenticated(): return HttpResponseRedirect("index") if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() user.save() User.objects.create( username=user.username , email=request.POST.get('email', '') , name=request.POST.get('name', '') , role=request.POST.get('role', '') ) user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) return HttpResponseRedirect("index") else: form = UserCreationForm() return render_to_response("registration/account.html", RequestContext(request, { 'form' : form, 'which_page' : "register" }))
Example 16
Project: jeeves Author: jeanqasaur File: views.py License: MIT License | 5 votes |
def register_account(request): if request.user.is_authenticated(): return HttpResponseRedirect("index") if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() user.save() UserProfile.objects.create( username=user.username, email=request.POST.get('email', ''), ) user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) return HttpResponseRedirect("index") else: form = UserCreationForm() return render_to_response("registration/account.html", RequestContext(request, { 'form' : form, 'which_page' : "register" }))
Example 17
Project: jeeves Author: jeanqasaur File: views.py License: MIT License | 5 votes |
def register_account(request): JeevesLib.clear_viewer() if request.user.is_authenticated(): return HttpResponseRedirect("index") if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() user.save() UserProfile.objects.create( username=user.username, name=request.POST.get('name',''), affiliation=request.POST.get('affiliation',''), level='normal', email=request.POST.get('email', ''), ) user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) return HttpResponseRedirect("index") else: form = UserCreationForm() return render(request, 'registration/account.html', { 'form' : form, 'which_page' : 'register' })
Example 18
Project: jeeves Author: jeanqasaur File: views.py License: MIT License | 5 votes |
def register_account(request): if request.user.is_authenticated(): return HttpResponseRedirect("index") if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() user.save() UserProfile.objects.create( username=user.username, email=request.POST.get('email', ''), ) user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) return HttpResponseRedirect("index") else: form = UserCreationForm() return render_to_response("registration/account.html", RequestContext(request, { 'form' : form, 'which_page' : "register" }))
Example 19
Project: jeeves Author: jeanqasaur File: views.py License: MIT License | 5 votes |
def register_account(request): if request.user.is_authenticated(): return HttpResponseRedirect("index") if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() user.save() UserProfile.objects.create( username=user.username, email=request.POST.get('email', ''), ) user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) return HttpResponseRedirect("index") else: form = UserCreationForm() return render_to_response("registration/account.html", RequestContext(request, { 'form' : form, 'which_page' : "register" }))
Example 20
Project: jeeves Author: jeanqasaur File: views.py License: MIT License | 5 votes |
def register_account(request): if request.user.is_authenticated(): return HttpResponseRedirect("index") if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() user.save() UserProfile.objects.create( username=user.username, email=request.POST.get('email', ''), ) user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) return HttpResponseRedirect("index") else: form = UserCreationForm() return render_to_response("registration/account.html", RequestContext(request, { 'form' : form, 'which_page' : "register" }))
Example 21
Project: jeeves Author: jeanqasaur File: views.py License: MIT License | 5 votes |
def register_account(request): if request.user.is_authenticated(): return HttpResponseRedirect("index") if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() user.save() UserProfile.objects.create( username=user.username, email=request.POST.get('email', ''), ) user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) return HttpResponseRedirect("index") else: form = UserCreationForm() return render_to_response("registration/account.html", RequestContext(request, { 'form' : form, 'which_page' : "register" }))
Example 22
Project: jeeves Author: jeanqasaur File: views.py License: MIT License | 5 votes |
def register_account(request): """Account registration. """ if request.user.is_authenticated(): return HttpResponseRedirect("index") if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() print user.username print request.POST.get('email', '') print request.POST.get('name', '') user.save() profiletype = request.POST.get('profiletype', '') UserProfile.objects.create( username=user.username , email=request.POST.get('email', '') , name=request.POST.get('name', '') , profiletype=int(profiletype)) user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) return HttpResponseRedirect("index") else: form = UserCreationForm() return render_to_response("registration/account.html" , RequestContext(request, {'form' : form , 'which_page' : "register"}))
Example 23
Project: jeeves Author: jeanqasaur File: views.py License: MIT License | 5 votes |
def register_account(request): if request.user.is_authenticated(): return HttpResponseRedirect("index") if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() user.save() UserProfile.objects.create( username=user.username, name=request.POST.get('name',''), affiliation=request.POST.get('affiliation',''), level='normal', email=request.POST.get('email', ''), ) user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) return HttpResponseRedirect("index") else: form = UserCreationForm() return render_to_response("registration/account.html", RequestContext(request, { 'form' : form, 'which_page' : "register" }))