Beispiel #1
0
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})
Beispiel #2
0
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,
    })
Beispiel #3
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
        })
Beispiel #4
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.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})
Beispiel #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
    })
Beispiel #6
0
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)
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
        })
Beispiel #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
        })
Beispiel #9
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})
Beispiel #10
0
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)
Beispiel #11
0
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} )
Beispiel #12
0
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,
    )
Beispiel #13
0
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)
Beispiel #14
0
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)