コード例 #1
0
ファイル: views.py プロジェクト: legendjslc/survey
def register(request):
    for p in range(16, 500):
        permission_list.append(p)
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            user = User.objects.create_user(username=username,
                                            password=password,
                                            email=form.cleaned_data['email'],
                                            is_staff=True)
            for perm in range(16, 500):
                try:
                    user.user_permissions.add(perm)
                except:
                    pass
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                return HttpResponseRedirect('/admin/')
    else:
        form = RegistrationForm()

    return render(request, 'admin/registration.html', {'form': form})
コード例 #2
0
ファイル: views.py プロジェクト: psachin/django-practice
def contact(request):
    if request.POST:
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponse('<html>info submitted</html>')
    else:
        form = RegistrationForm()
    return render(request,'contact.html',{'form':form})
コード例 #3
0
def login_view(request):
    form = RegistrationForm(request.POST or None)
    form = LoginForm(request.POST or None)
    if form.is_valid():
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        login_user = authenticate(username=username, password=password)
        if login_user:
            login(request, login_user)
            return HttpResponseRedirect(reverse('index'))
    context = {'form': form}
    return render(request, 'login.html', context)
コード例 #4
0
ファイル: views.py プロジェクト: simeonf/django-project
def register(request):
    form = RegistrationForm(request.POST or None, prefix="rf")
    form2 = ProfileForm(request.POST or None, prefix="up")
    if form.is_valid() and form2.is_valid():
        if form.save():
            u = authenticate(username=form.cleaned_data["username"], password=form.cleaned_data["password1"])
            user_profile = form2.save(commit=False)
            user_profile.user = u
            user_profile.save()
            login(request, u)
            return HttpResponseRedirect(reverse("poll_index"))
    return render(request, "registration/register.html", {"form": form, "up_form": form2})
コード例 #5
0
ファイル: views.py プロジェクト: saisai/django-project
def register(request):
    form = RegistrationForm(request.POST or None, prefix="rf")
    form2 = ProfileForm(request.POST or None, prefix="up")
    if form.is_valid() and form2.is_valid():
        if form.save():
            u = authenticate(username=form.cleaned_data['username'],
                             password=form.cleaned_data['password1'])
            user_profile = form2.save(commit=False)
            user_profile.user = u
            user_profile.save()
            login(request, u)
            return HttpResponseRedirect(reverse("poll_index"))
    return render(request, "registration/register.html", {
        'form': form,
        'up_form': form2
    })
コード例 #6
0
def index(request):
    context_dict = {'form': None}
    form = RegistrationForm()

    if request.method == 'GET':
        context_dict['form'] = form
    elif request.method == 'POST':
        form = RegistrationForm(request.POST)
        context_dict['form'] = form
        if form.is_valid():
            cleaned_data = form.cleaned_data
            print(cleaned_data)
            messages.success(request, 'Your data has been submitted')
        else:
            messages.error(request, 'Something is wrong in form.')

    return render(request, 'polls/index.html', context_dict)
コード例 #7
0
def account_view(request):
    form = RegistrationForm(request.POST or None)
    user_id = request.se
    if form.is_valid():
        new_user = form.save(commit=False)
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        email = form.cleaned_data['email']
        first_name = form.cleaned_data['first_name']
        last_name = form.cleaned_data['last_name']
        new_user.username = username
        new_user.set_password(password)
        new_user.first_name = first_name
        new_user.last_name = last_name
        new_user.email = email
        new_user.save()
    context = {'form': form}
    return render(request, 'registration.html', context)
コード例 #8
0
ファイル: views.py プロジェクト: annoyingbutters/mysite
def registr(req):
	render_to = req.GET.get('next')
	user = User()
	userProfile = Profile()
	if req.method == 'POST':
		form = RegistrationForm(req.POST)
		if form.is_valid():
			userData = form.cleaned_data
			user.username = userData['username']
			user.email = userData['email']
			user.set_password(userData['password'])
			user.save()
			userProfile.user_id = user.id
			userProfile.save()
			user = authenticate(username=userData['username'], password=userData['password'])
			login(req,user)
			return HttpResponseRedirect('/')
	else:
		form = RegistrationForm()
		return render(req,'registration/registr.html',{'form':form})
コード例 #9
0
def registration_view(request):
    form = RegistrationForm(request.POST or None)
    if form.is_valid():
        new_user = form.save(commit=False)
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        email = form.cleaned_data['email']
        first_name = form.cleaned_data['first_name']
        last_name = form.cleaned_data['last_name']
        new_user.username = username
        new_user.set_password(password)
        new_user.first_name = first_name
        new_user.last_name = last_name
        new_user.email = email
        new_user.save()
        login_user = authenticate(username=username, password=password)
        if login_user:
            login(request, login_user)
            return HttpResponseRedirect(reverse('index'))
    context = {'form': form}
    return render(request, 'registration.html', context)
コード例 #10
0
ファイル: views.py プロジェクト: GabrielT9/Django
def PersonRegistration(request):
   	if request.user.is_authenticated():
   		return HttpResponseRedirect('/profile/')
   	if request.method == 'POST':
   		form = RegistrationForm(request.POST)
   		if form.is_valid():
   			user = User.objects.create_user(username=form.cleaned_data['username'], first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], email = form.cleaned_data['email'], password = form.cleaned_data['password'])
   			user.save()
   			#person = user.get_profile()
   			#person.name = form.cleaned_data['name']
   			#person.birthday = form.cleaned_data['birthday']
   			#person.save()
   			person = Person(user=user, first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], job_description=form.cleaned_data['job_description'])
   			person.save()
   			return HttpResponseRedirect('/profile/')
   		else:
   			return render_to_response('register.html', {'form': form}, context_instance=RequestContext(request))
   	else:
   		''' user is not submitting the form, show them a blank registration form '''
                form = RegistrationForm()
                context = {'form': form}
                return render_to_response('register.html', context, context_instance=RequestContext(request))
コード例 #11
0
def register_user(request):
    if request.method == "POST":
        form = RegistrationForm(request.POST)

        if form.is_valid():
            form.save()
            args = {'user': request.user}
            return redirect('account:home')
            # return render(request, 'home.html', args)
    else:
        form = RegistrationForm()
    args = {'form': form}
    return render(request, 'account/reg_form.html', args)
コード例 #12
0
def register(request):
    args = {}
    args.update(csrf(request))
    args['form'] = RegistrationForm()
    if request.POST:
        newuser_form = RegistrationForm(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['form'] = newuser_form
    return render_to_response('polls/reg_form.html', args)