Python django.contrib.auth.forms.UserCreationForm() Examples

The following are code examples for showing how to use django.contrib.auth.forms.UserCreationForm(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: ewe_ebooks   Author: jaymcgrath   File: views.py    MIT License 7 votes vote down vote up
def update_profile(request):
    if request.method == 'POST':
        user_form = UserCreationForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST, instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request, 'Your profile was successfully updated!')
            return redirect('settings:profile')
        else:
            messages.error(request, 'Please correct the error below.')
    else:
        user_form = UserCreationForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    return render(request, 'profiles/profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    }) 
Example 2
Project: ewe_ebooks   Author: jaymcgrath   File: views.py    MIT License 7 votes vote down vote up
def create_profile(request):
    if request.method == 'POST':
        user_form = UserCreationForm(data=request.POST)
        profile_form = ProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()

            messages.success(request, 'Your profile was successfully created!')
            return redirect('/dashboard/')
        else:
            messages.error(request, 'Please correct the error below.')
    else:
        # GET request.. return the form
        user_form = UserCreationForm()
        profile_form = ProfileForm()

    return render(request, 'people/create_profile.html', {'user_form': user_form, 'profile_form': profile_form}) 
Example 3
Project: scope   Author: CCA-Public   File: forms.py    GNU Affero General Public License v3.0 6 votes vote down vote up
def save(self):
        # Call ModelForm save directly to avoid setting the
        # user password allways in UserCreationForm save.
        user = super(UserCreationForm, self).save(commit=False)
        # Only set the password when it's populated. It's required on creation.
        password = self.cleaned_data.get("password1", "")
        if password != "":
            user.set_password(password)
        user.save()
        # Process user groups. Groups from the form is a
        # list of strings but the existing groups is a
        # list of integers, therefore some conversion is
        # needed in the if conditions bellow.
        if "groups" in self.cleaned_data:
            for group_id in self.cleaned_data["groups"]:
                # Do not add already added groups
                if int(group_id) not in self.initial_groups:
                    group = Group.objects.get(id=group_id)
                    user.groups.add(group)
            # Remove groups not present in new_groups
            for group_id in self.initial_groups:
                if str(group_id) not in self.cleaned_data["groups"]:
                    group = Group.objects.get(id=group_id)
                    user.groups.remove(group)
        return user 
Example 4
Project: Bookmark   Author: AnkurRyder   File: views.py    MIT License 6 votes vote down vote up
def signup(request):

    if request.user.is_authenticated():
         return redirect('dashboard')
    else:

        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('dashboard')

        else:
            form = UserCreationForm()
        return render(request, 'bookmark/signuppl.html', {'form': form}) 
Example 5
Project: Bookmark   Author: AnkurRyder   File: viewsworking.py    MIT License 6 votes vote down vote up
def signup(request):

    if request.user.is_authenticated():
         return redirect('index')
    else:

        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('index')

        else:
            form = UserCreationForm()
        return render(request, 'bookmark/signuppl.html', {'form': form}) 
Example 6
Project: EmailSA   Author: django-africa   File: views.py    GNU General Public License v3.0 6 votes vote down vote up
def signup(request):
    if not request.user.is_authenticated:
        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('user')
        else:
            form = UserCreationForm()
        return render(request, 'signup.html', {'form': form})
    else:
        return render(request, 'nosignup.html') 
Example 7
Project: SEMS   Author: urankajtazaj   File: views.py    GNU General Public License v3.0 6 votes vote down vote up
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 8
Project: aimmo.defunct   Author: jishi9   File: views.py    GNU Affero General Public License v3.0 6 votes vote down vote up
def register(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()

            with open("simulation/avatar_examples/dumb_avatar.py") as initial_code_file:
                initial_code = initial_code_file.read()

            Player(user=user, code=initial_code).save()
            authenticated_user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1'])
            login(request, authenticated_user)
            return redirect('program')
    else:
        form = UserCreationForm()
    return render(request, 'accounts/register.html', {'form': form}) 
Example 9
Project: python-monitoring-talk   Author: amitsaha   File: views.py    Apache License 2.0 6 votes vote down vote up
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 10
Project: python-monitoring-talk   Author: amitsaha   File: views.py    Apache License 2.0 6 votes vote down vote up
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 11
Project: fabl-writer   Author: lyk2018-python   File: views.py    MIT License 6 votes vote down vote up
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('home')
        else:
            form = UserCreationForm()
            return render(request, 'registration/signup.html', {'form': form})
    else:
        form = UserCreationForm()
        return render(request, 'registration/signup.html', {'form': form}) 
Example 12
Project: nrp   Author: django-rea   File: views.py    GNU Affero General Public License v3.0 6 votes vote down vote up
def create_user(request, agent_id):
    if not request.user.is_staff:
        return render_to_response('valueaccounting/no_permission.html')
    agent = get_object_or_404(EconomicAgent, id=agent_id)
    if request.method == "POST":
        user_form = UserCreationForm(data=request.POST)
        #import pdb; pdb.set_trace()
        if user_form.is_valid():
            user = user_form.save(commit=False)
            user.email = agent.email
            is_staff = request.POST.get("is_staff")
            if is_staff == 'on':
                user.is_staff = True
            #user.last_login = datetime.datetime.now()
            user.save()
            au = AgentUser(
                agent = agent,
                user = user)
            au.save()
            if use_faircoins:
                agent.request_faircoin_address()
    return HttpResponseRedirect('/%s/%s/'
        % ('accounting/agent', agent.id)) 
Example 13
Project: calendar-application-tutorial   Author: TheDumbfounds   File: views.py    MIT License 6 votes vote down vote up
def signup(request):

    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect('/calendar')

    else:
        form = UserCreationForm()

    return render(request, 'registration/signup.html', {'form': form}) 
Example 14
Project: Python   Author: Puakiz   File: views.py    MIT License 6 votes vote down vote up
def register(request):
    """Register a new user."""
    if request.method != 'POST':
        # Display blank registration form.   
        form = UserCreationForm()
    else:
        # Process completed form.
        form = UserCreationForm(data=request.POST)
        
        if form.is_valid():
            new_user = form.save()
            # Log the user in, and then redirect to home page.
            authenticated_user = authenticate(username=new_user.username,
                password=request.POST['password1'])
            login(request, authenticated_user)
            return HttpResponseRedirect(reverse('learning_logs:index'))

    context = {'form': form}
    return render(request, 'users/register.html', context) 
Example 15
Project: Python   Author: Puakiz   File: views.py    MIT License 6 votes vote down vote up
def register(request):
    """Register a new user."""
    if request.method != 'POST':
        # Display blank registration form.   
        form = UserCreationForm()
    else:
        # Process completed form.
        form = UserCreationForm(data=request.POST)
        
        if form.is_valid():
            new_user = form.save()
            # Log the user in, and then redirect to home page.
            authenticated_user = authenticate(username=new_user.username,
                password=request.POST['password1'])
            login(request, authenticated_user)
            return HttpResponseRedirect(reverse('learning_logs:index'))

    context = {'form': form}
    return render(request, 'users/register.html', context) 
Example 16
Project: lingwars-games   Author: Lingwars   File: views.py    GNU General Public License v2.0 6 votes vote down vote up
def register(request):
    if request.method == 'POST':
        form = UserCreationForm(data=request.POST)
        if form.is_valid():
            new_user = form.save()
            new_user = authenticate(username=request.POST['username'],
                                    password=request.POST['password1'])
            auth_login(request, new_user)
            next = request.POST.get('next', '/')
            return HttpResponseRedirect(next)
    else:
        form = UserCreationForm()

    next = request.GET.get('next', '/')
    context = {'form': form, 'next': next}
    return TemplateResponse(request, 'users/register.html', context) 
Example 17
Project: c3nav   Author: c3nav   File: account.py    Apache License 2.0 6 votes vote down vote up
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 18
Project: SPBU-DBMS-Project   Author: Betekhtin   File: views.py    MIT License 6 votes vote down vote up
def register(request):
    username = auth.get_user(request).username
    if not (username):
        args={}
        args.update(csrf(request))
        args['form']=UserCreationForm()
        if request.POST:
            newuser_form=UserCreationForm(request.POST)
            if newuser_form.is_valid():
                newuser_form.save()
                newuser = auth.authenticate(username=newuser_form.cleaned_data['username'],password=newuser_form.cleaned_data['password2'])
                auth.login(request, newuser)
                return redirect('/')
            else:
                args['errors'] = format_html('<div class="main-error alert alert-error">Ошибка при регистрации</div>')
                args['form'] = newuser_form
        return render_to_response('register.html',args)
    else:
        return redirect('/') 
Example 19
Project: SunshineCTF-2019-Public   Author: HackUCF   File: views.py    MIT License 5 votes vote down vote up
def register(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')
            # need to get this to auth and redirect
            #user = authenticate(username=username, password=raw_password)
            #login(user)
            return redirect('index')
    else:
        form = UserCreationForm()
    return render(request, 'registration/register.html', {'form': form}) 
Example 20
Project: Django-Bookworm   Author: OmkarPathak   File: views.py    MIT License 5 votes vote down vote up
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 21
Project: Anonymous-Blog   Author: prinzpiuz   File: views.py    GNU General Public License v3.0 5 votes vote down vote up
def get(self, request):
        form = UserCreationForm()
        return render(request, 'homepage/register.html', {'form': form}) 
Example 22
Project: Anonymous-Blog   Author: prinzpiuz   File: views.py    GNU General Public License v3.0 5 votes vote down vote up
def post(self, request):
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect('homepage:login')
        return render(request, 'homepage/register.html', {'form': form}) 
Example 23
Project: dockerizeme   Author: dockerizeme   File: snippet.py    Apache License 2.0 5 votes vote down vote up
def save(self, commit=True):
        user = super(UserCreationForm, self).save(commit=False)
        user.email = self.cleaned_data["email"]
        if commit:
            user.save()
        return user 
Example 24
Project: qctf-starter-2016   Author: HackerDom   File: views.py    MIT License 5 votes vote down vote up
def register(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.save()
            user.team.name = user.username
            user.team.region = Region.objects.get(
                pk=settings.DEFAULT_REGION_ID)
            user.team.save()
            return HttpResponseRedirect('/')
    else:
        form = UserCreationForm()
    return render(request, 'cabinet/register.html', {'form': form}) 
Example 25
Project: GymManagement   Author: ahmadreza-smdi   File: views.py    MIT License 5 votes vote down vote up
def register(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)
            logg.loging(username,request,'register')

        return HttpResponseRedirect('/login/')
    else:
        form = UserCreationForm()
    return render(request,'Signup.html',{'form':form}) 
Example 26
Project: WebServerAndClient   Author: EMSTrack   File: forms.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def save(self, commit=True):
        # UserCreationForm calls ModelForm.save() with commit = False, which prevents groups from being saved.
        # Calling save_m2m() afterwards should fix that
        instance = super().save(commit)
        if commit:
            self.save_m2m()

        return instance 
Example 27
Project: ewe_ebooks   Author: jaymcgrath   File: views.py    MIT License 5 votes vote down vote up
def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        context['member_form'] = context.get('form')
        user_form = UserCreationForm()
        context.update({'user_form': user_form})
        return context 
Example 28
Project: site   Author: alphageek-xyz   File: forms.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def save(self, commit=True):
        user = super(UserCreationForm, self).save(commit=False)
        user.email = self.cleaned_data['email']
        if commit:
            user.save()
            user.groups.add(Group.objects.get_or_create(name='basic_user')[0])
            user.save()
        return user 
Example 29
Project: backend   Author: chronoscio   File: views.py    GNU General Public License v3.0 5 votes vote down vote up
def signup(request):
    if request.method == "POST":
        form = UserCreationForm(request.POST)
        if form.is_valid():
            new_user = form.save(commit=False)
            new_user.is_staff = True
            new_user.save()
            try:
                new_user.groups.add(Group.objects.get(name="mapper"))
            except Group.DoesNotExist:
                pass

            username = form.cleaned_data.get("username")
            raw_password = form.cleaned_data.get("password1")
            user = authenticate(username=username, password=raw_password)

            login(request, user)
            return HttpResponseRedirect("/admin")
    else:
        form = UserCreationForm()
    return render(request, "signup.html", {"form": form}) 
Example 30
Project: sdn   Author: ray6   File: views.py    MIT License 5 votes vote down vote up
def register(request):
	s = "%12x" % uuid.getnode()
	mac = ":".join(x+y for x, y in zip(s[::2], s[1::2]))

	if request.method == 'POST':
		form = UserCreationForm(request.POST)
		
		if form.is_valid():
			user = form.save()
			Usertable.objects.create(name=user,address=mac)
			return HttpResponseRedirect('/accounts/login/')
	else:
		form = UserCreationForm()
	return render_to_response('register.html',RequestContext(request,locals())) 
Example 31
Project: jLearn   Author: gjergjk71   File: views.py    GNU General Public License v3.0 5 votes vote down vote up
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)
			return render(request, 'auth/signup.html', {'form': form,"successfully":True})
		else:
			return render(request, 'auth/signup.html', {'form': form})
	else:
		form = UserCreationForm()
		return render(request, 'auth/signup.html', {'form': form}) 
Example 32
Project: combining-forms-dynamically   Author: dhavalmanjaria   File: forms.py    GNU General Public License v2.0 5 votes vote down vote up
def save(self, commit=True):
        user = super(UserCreationForm, self).save(commit=False)

        LOG.debug("user_type from form:" + self.cleaned_data['user_type'])
        if commit:
            user.save()  # First save the created user,
            user.basicinfo.user_type = self.cleaned_data['user_type']
            user.save()  # save the basic info

        return user 
Example 33
Project: django_email   Author: hansjhoffman   File: forms.py    MIT License 5 votes vote down vote up
def save(self, commit=True):
        user = super(UserCreationForm, self).save(commit=False)
        user.set_password(self.cleaned_data['password1'])

        if commit:
            user.save()

        return user 
Example 34
Project: xlsx_over_web   Author: sunnywalden   File: view.py    Apache License 2.0 5 votes vote down vote up
def registry(request):
    return render(request, "login/register.html")
#    else:
#        return render_to_response("login/register.html")
    # if request.method == 'POST':
    #     form = UserCreationForm(request.POST)
    #     if form.is_valid():
    #         new_user = form.save()
    #         return HttpResponseRedirect("login/login.html")
    # else:
    #     form = UserCreationForm()
    # return render_to_response("login/register.html", {
    #     'form': form,
    # }) 
Example 35
Project: DjangoGoat   Author: red-and-black   File: views.py    MIT License 5 votes vote down vote up
def sign_up(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            UserProfile.objects.create(user=new_user)
            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('profile', pk=user.pk)
    else:
        form = UserCreationForm()

    return render(request, 'sign_up.html', {'form': form}) 
Example 36
Project: mysite-django18   Author: its-django   File: views.py    Apache License 2.0 5 votes vote down vote up
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 37
Project: InstagramClone   Author: genevag   File: forms.py    Apache License 2.0 5 votes vote down vote up
def save(self, commit=True):
        user = super(UserCreationForm, self).save(commit=False)
        user.email = self.cleaned_data["email"]
        if commit:
            user.save()

        return user 
Example 38
Project: nrp   Author: django-rea   File: views.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def create_user_and_agent(request):
    #import pdb; pdb.set_trace()
    if not request.user.is_superuser:
        return render_to_response('valueaccounting/no_permission.html')
    agent_selection_form = AgentSelectionForm(data=request.POST or None)
    agent_form = CreateAgentForm(data=request.POST or None)
    user_form = UserCreationForm(data=request.POST or None)
    if request.method == "POST":
        #import pdb; pdb.set_trace()
        selected_agent = None
        if agent_selection_form.is_valid():
            selected_agent = agent_selection_form.cleaned_data['selected_agent']
            agent_form = CreateAgentForm(
                data=request.POST or None,
                instance=selected_agent
            )
        if agent_form.is_valid() and user_form.is_valid():
            agent = agent_form.save(created_by=request.user)
            user = user_form.save(commit=False)
            user.first_name = request.POST.get("first_name")
            user.last_name = request.POST.get("last_name")
            user.email = request.POST.get("email")
            user.save()
            au = AgentUser(
                agent = agent,
                user = user)
            au.save()
            return HttpResponseRedirect('/%s/%s/'
                % ('accounting/agent', agent.id))
    return render_to_response("valueaccounting/create_user_and_agent.html", {
        "user_form": user_form,
        "agent_form": agent_form,
        "agent_selection_form": agent_selection_form,
    }, context_instance=RequestContext(request)) 
Example 39
Project: MyTube   Author: gjergjk71   File: views.py    MIT License 5 votes vote down vote up
def signUp(request):
	if request.method == "POST":
		form = UserCreationForm(request.POST)
		if form.is_valid():
			form.save()
			return redirect('/auth/login')
		else:
			return render(request,"registration/signUp.html",{"form":form})
	else:
		form = UserCreationForm()
		return render(request,"registration/signUp.html",{"form":form}) 
Example 40
Project: GetTogether   Author: GetTogetherComm   File: user.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 41
Project: HackTheCommute   Author: FerryTime   File: views.py    GNU General Public License v3.0 5 votes vote down vote up
def register(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            return HttpResponseRedirect("/")
    else:
        form = UserCreationForm()
    return render(request, "registration/register.html", {
        'form': form,
    }) 
Example 42
Project: global-ssh-server   Author: nthiep   File: views.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def register(request):
	if request.user.is_authenticated():
		return HttpResponseRedirect('/')
	if request.method == 'POST':
		form = UserCreationForm(request.POST)
		if form.is_valid():
			new_user = form.save()
			return HttpResponseRedirect('/login/?redirect=register')
	else:
		form = UserCreationForm()
	return render(request, "pages/register.html", {
		'form': form,
	}) 
Example 43
Project: c3nav   Author: c3nav   File: views.py    Apache License 2.0 5 votes vote down vote up
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 44
Project: Karmo-Onsite-Judge   Author: chunky2808   File: views.py    MIT License 5 votes vote down vote up
def signup(request):
	if request.method == "POST":
		form = UserCreationForm(request.POST)
		if form.is_valid():
			user = form.save()
			auth_login(request, user)
			return redirect('home')
	else:	
		form = UserCreationForm()
	return render(request,'users/signup.html',{'form':form}) 
Example 45
Project: lookit-api   Author: lookit   File: forms.py    MIT License 5 votes vote down vote up
def save(self, commit=True):
        user = super(UserCreationForm, self).save(commit=False)
        user.set_password(self.cleaned_data["password1"])
        user.is_active = True
        if commit:
            user.save()
        return user 
Example 46
Project: wikicoding   Author: arjun024   File: forms.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(UserCreationForm, self).__init__(*args, **kwargs)
        self.reserved_words = ['wikicoding', 'admin', 'root', 'wiki', 'meta', '_accounts', 'accounts', '_search',
        '_revision', 'LICENSE', 'raw', 'plugin', 'user', 'log', 'pages', 'recent', 'robots.txt', 'policies', 'donate']
        
        # Add honeypots
        self.honeypot_fieldnames = "address", "phone"
        self.honeypot_class = ''.join(random.choice(string.ascii_uppercase + string.digits) for __ in range(10))
        self.honeypot_jsfunction = 'f'+''.join(random.choice(string.ascii_uppercase + string.digits) for __ in range(10))
        
        for fieldname in self.honeypot_fieldnames:
            self.fields[fieldname] = forms.CharField(
                widget=forms.TextInput(attrs={'class': self.honeypot_class}),
                required=False,
        ) 
Example 47
Project: wikicoding   Author: arjun024   File: forms.py    GNU General Public License v3.0 5 votes vote down vote up
def clean_username(self):
        super(UserCreationForm, self).clean_username()
        username = self.cleaned_data["username"]
        if username in self.reserved_words:
            raise forms.ValidationError("You are trying to use a reserved word. Please use a different username.")
        return username 
Example 48
Project: wikicoding   Author: arjun024   File: forms.py    GNU General Public License v3.0 5 votes vote down vote up
def clean(self):
        cd = super(UserCreationForm, self).clean()
        for fieldname in self.honeypot_fieldnames:
            if cd[fieldname]: raise forms.ValidationError("Thank you, non-human visitor. Please keep trying to fill in the form.")
        return cd 
Example 49
Project: ctf-manager   Author: BurningNetel   File: test_views.py    GNU General Public License v3.0 5 votes vote down vote up
def test_registration_uses_register_form(self):
        response = self.client.get(reverse('register'))
        registration_form = response.context['form']
        self.assertIsInstance(registration_form, UserCreationForm) 
Example 50
Project: callisto-core   Author: project-callisto   File: test_views.py    GNU Affero General Public License v3.0 5 votes vote down vote up
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 51
Project: django-example-channels   Author: realpython   File: views.py    MIT License 5 votes vote down vote up
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 52
Project: elmolino   Author: palichis   File: views.py    GNU General Public License v2.0 4 votes vote down vote up
def usuario(request):
    hist,redes,men = general(request)
    cform = ''
    cusuario = ''
    if request.method == 'POST':
        #cform = clienteform(request.POST)
        cusuario = UserCreationForm(request.POST)
        print request.POST
        try:
            user_id = cusuario.save()
        except Exception as inst:
            print type(inst)     # the exception instance
            print inst.args      # arguments stored in .args
            print inst           # __str__ allows args to be printed directly
            #x, y = inst.args
            #print 'x =', x
            #print 'y =', y
        clform = cliente()
        clform.nombre = request.POST['nombre']
        clform.apellido = request.POST['apellido']
        clform.correo = request.POST['correo']
        clform.cedula = request.POST['cedula']
        clform.telefono = request.POST['telefono']
        clform.usuario = user_id
        clform.save()
        ctx = {'nombre' : request.POST['nombre'],
               'apellido' : request.POST['apellido'],
               'username' : request.POST['username'],
               'password1' : request.POST['password1']}
        message = get_template('mailusuario.html').render(Context(ctx))
        msg = EmailMessage('Vivero "El Molino"', message, to=[request.POST['correo'],"sayanguicela@hotmail.com","mvargas@totaltek.com.ec"], from_email='palichis@katarisoft.com')
        msg.content_subtype = 'html'
        msg.send()
        #foro_obj = foro.objects.filter(id = request.GET['id'])[0]
        #mensaje = comentario()
        #mensaje.tema = request.POST['tema']
        #mensaje.descripcion = request.POST['comment']
        #mensaje.cforo = foro_obj
        #mensaje.cusuario = request.user
        #mensaje.save()
    else:
        cform = clienteform()
        cusuario = UserCreationForm()
    
        
    return render_to_response('usuario.html',{'menu':men, 'content': cform, 'content1': cusuario, 'foother': hist, 'red':redes}) 
Example 53
Project: ctf-manager   Author: BurningNetel   File: views.py    GNU General Public License v3.0 4 votes vote down vote up
def register_page(request):
    form = UserCreationForm(data=request.POST)
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            return redirect('login')
    return render(request, 'registration/register.html', {'form': UserCreationForm()})