コード例 #1
0
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:
                print('found it')
                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, 'polls/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #2
0
ファイル: views.py プロジェクト: shivam-jindal/repo.mysite
def register(request):
	registered = False

	if request.method == 'POST':
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)
		pass1 = request.POST.get('password')
		pass2 = request.POST.get('p2')
		if user_form.is_valid() and profile_form.is_valid():
			if (pass1 != pass2 ):
				user_form.non_field_errors = 'Passwords did not match.'
				print user_form.non_field_errors
			else:
				user = user_form.save()
				user.set_password(user.password)
				user.save()
	
				profile = profile_form.save(commit=False)
				profile.user = user
				profile.save()
				registered = True
		else:
			print user_form.errors, profile_form.errors

	else:
		user_form = UserForm()
		profile_form = UserProfileForm()
	
	return render(request,
		'polls/register.html',
		{'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
コード例 #3
0
ファイル: views.py プロジェクト: rjain111/hello-world
def register(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.save()
			profile = profile_form.save(commit=False)
			profile.user=user

			if 'picture' in request.FILES:
				profile.picture = request.Files[ 'picture']

			profile.save()
			registered = True

		else:
			print user_form.errors, profile_form.errors

	else:
		user_form = UserForm()
		profile_form = UserProfileForm()

	return render(request,'polls/register.html' , 
		{ 'user_form': user_form, 'profile_form':profile_form, 'registered':registered})
コード例 #4
0
ファイル: views.py プロジェクト: leian7/polls
def register(request):
    context = RequestContext(request)
    registered = False  #default-- if register success, set to True

    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.save()
            profile = profile_form.save(commit=False)  #don't save right away
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            registered = True

        else:
            print user_form.errors, profile_form.errors

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render_to_response(
        'polls/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        }, context)
コード例 #5
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        #profile_form = UserProfileForm(data = request.POST)

        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            #profile = profile_form.save(commit = False)
            #profile.user = user
            '''if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']'''

            #profile.save()
            registered = True
        else:
            print user_form.errors  #, profile_form.errors
    else:
        user_form = UserForm()
        #profile_form = UserProfileForm()

    return render(request, 'polls/register.html', {
        'user_form': user_form,
        'registered': registered
    })
コード例 #6
0
def login(request):
    if request.session.get('is_login',None):
        return redirect("/index/")
    if request.method == "POST":
        login_form = UserForm(request.POST)
        message = "请检查填写的内容!"
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            try:
                user = Userlg.objects.get(name=username)
                if user.password == hash_code(password):  # 哈希值和数据库内的值进行比对
                #if user.password == password:
                    request.session['is_login'] = True
                    request.session['user_id'] = user.id
                    request.session['user_name'] = user.name
                    return redirect('/index/')
                else:
                    message = "密码不正确!"
            except:
                message = "用户不存在!"
        return render(request, 'login/login.html', locals())

    login_form = UserForm()
    return render(request, 'login/login.html', locals())
コード例 #7
0
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        pass1 = request.POST.get('password')
        pass2 = request.POST.get('p2')
        if user_form.is_valid() and profile_form.is_valid():
            if (pass1 != pass2):
                user_form.non_field_errors = 'Passwords did not match.'
                print user_form.non_field_errors
            else:
                user = user_form.save()
                user.set_password(user.password)
                user.save()

                profile = profile_form.save(commit=False)
                profile.user = user
                profile.save()
                registered = True
        else:
            print user_form.errors, profile_form.errors

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(
        request, 'polls/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #8
0
def register(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.pasword)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()

            registered = true

        else:
            print user_form.errors, profile_form.errors

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(
        request, 'polls/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #9
0
ファイル: views.py プロジェクト: ahmadyosr/ahmadyosr
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render_to_response(
            'polls/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)
コード例 #10
0
ファイル: views.py プロジェクト: meenagorwishankar/pcg2015_mg
def register(request):

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render(request,
            'polls/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered} )
コード例 #11
0
ファイル: views.py プロジェクト: riasto1/NoopDjangoMongodb
def register(request):
    # Get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST.
    if request.method == "POST":
        # Grab information from the raw form information.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Hash the password with the set_password method.
            # Update the user object.
            user.set_password(user.password)
            user.save()

            # Sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if "picture" in request.FILES:
                profile.picture = request.FILES["picture"]

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render_to_response(
        "D:\Sublime\Mission\mysite\website\templates\register.html",
        {"user_form": user_form, "profile_form": profile_form, "registered": registered},
        context,
    )
コード例 #12
0
ファイル: views.py プロジェクト: bomiiisong/Airbnb
def signup(request):
    if request.method == "POST":
        form = UserForm(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('base')
    else:
        form = UserForm()
    return render(request, 'info/signup.html', {'form': form})
コード例 #13
0
ファイル: views.py プロジェクト: paulin-mipt/dgap_voting
def profile_view(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        if request.user.social_auth.exists():
            profile_form = UserProfileFormReduced(request.POST, instance=request.user.userprofile)
        else:
            profile_form = UserProfileForm(request.POST, instance=request.user.userprofile)
        if profile_form.is_valid() and (request.user.social_auth.exists() or user_form.is_valid()):
            dorm = check_user(request)
            if dorm:
#DONE тут уже надо нормально разобраться с кучей карточек и людьми с одинаковыми именами и фамилиями одновременно
# долгое и мучительное обдумывание привело к выводу: candidat, у которых одинаковые firts_name, last_name, cardnumber, считаются одинаковыми по определению
# по сути, проверяем, есть ли вообще подходящие карточки. Если нет, то уже выпилили. Если есть, то неважно, сколько их. Вероятность того, что в базе будет два человека с одинаковыми ФИ и днём рождения, считается малой


# что делать, если в базе несколько человек с одинаовыми ФИ?
# считаем, что их не поселят в одну комнату, иначе ручная обработка 

                if len(dorm) > 1:
                    messages.error(request, 'Поздравляем! Судя по нашим данным, вам очень повезло с соседом. Если вы уверены в правильности введённых данных, пишите на [email protected], указывая тему письма "Замечательный сосед"')
                elif check_dorm(dorm[0].id):
                    messages.error(request, 'Пользователь с такими данными уже зарегистрирован. Если вы уверены в правильности введённых данных, пишите на [email protected], указывая тему письма "Проблемы при регистрации"')
                else:
                    dorm = dorm[0]
                    if not request.user.social_auth.exists():
                        user_form.save()
                    profile_form.save()
                    request.user.userprofile.dorm = dorm.id
                    request.user.userprofile.middlename = dorm.middle_name
                    #request.user.userprofile.room = dorm.room
                    request.user.userprofile.group = dorm.group
                    request.user.userprofile.approval = True 
                    request.user.userprofile.save()
                    messages.success(request, "Регистрация пройдена. Теперь вы можете участвовать в голосовании")
                    return redirect('polls:done')
            else:
                messages.error(request, 'Пользователя, удовлетворяющего введённым данным, в базе не обнаружено. Если вы уверены в правильности введённых данных, пишите на [email protected], указывая тему письма "Проблемы при регистрации"')
    else:
        user_form = UserForm(instance = request.user)
        if request.user.social_auth.exists():
            profile_form = UserProfileFormReduced(instance = request.user.userprofile)
        else:
            profile_form = UserProfileForm(instance = request.user.userprofile)

    return render(request, 'polls/profile.html', {
        'user_form': user_form,
        'profile_form': profile_form,
    })
コード例 #14
0
ファイル: views.py プロジェクト: victorddiniz/genomika
def signup_user(request):
	if request.method == 'POST':
		form = UserForm(request.POST)
		if form.is_valid():
			users = User.objects.filter(Q(Q(email = request.POST['email']) | Q(username = request.POST['username'])))
			if not users.exists():
				new_user = User.objects.create_user(username = request.POST['username'], email = request.POST['email'], password = request.POST['password'], first_name = request.POST['first_name'], last_name = request.POST['last_name'])
			else:
				context = {}
				context['email'] = True
				return render(request, 'signup.html', context)
		else:
			context = {}
			context['username'] = True
			if 'email' in request.POST:
				if User.objects.filter(email = request.POST['email']).exists():
					context['email'] = True
			return render(request, 'signup.html', context)
	return redirect('/')
コード例 #15
0
ファイル: views.py プロジェクト: Wlhzhang/djangosix
def login(request):
    forms = UserForm(request.POST)
    code = request.POST.get('cache_code', None)
    if code == request.session['code']:
        if forms.is_valid():
            user = auth.authenticate(username=forms.cleaned_data['username'],
                                     password=forms.cleaned_data['password'])
            # user = MyUser.objects.filter(username=forms.cleaned_data['username'],password=forms.cleaned_data['password'])
            if user:
                auth.login(request, user)
                return JsonResponse({'msg': '登录成功', 'status': 'success'})
            else:
                return JsonResponse({'msg': '用户名或者密码错误', 'status': 'fail'})
        else:
            form_error = forms.errors.as_json()
            return JsonResponse({
                'msg': '格式不正确',
                'data': form_error,
                'status': 'form_error'
            })
    else:
        return JsonResponse({'msg': '验证码错误', 'status': 'fail'})
コード例 #16
0
ファイル: views.py プロジェクト: dralley/pollsite
def register(request):
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)

        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            user = authenticate(username=request.POST['username'],
                                password=request.POST['password'])

            if user is not None:
                if user.is_active:
                    login(request, user)
            return redirect(reverse('polls:index'))
        else:
            print user_form.errors
    else:
        user_form = UserForm()

    context_dict = {'user_form': user_form}

    return render(request, 'polls/register.html', context_dict)
コード例 #17
0
ファイル: views.py プロジェクト: mahipjain/polls-app
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.save()
			profile = profile_form.save(commit=False)
			profile.user = user
			profile.save()
			registered = True
		else:
			print user_form.errors, profile_form.errors
	else:
		user_form =UserForm()
		profile_form=UserProfileForm()
	return render_to_response(
		'polls/register.html',
		{'user_form':user_form, 'profile_form': profile_form, 'registered': registered},
		context)