예제 #1
0
파일: views.py 프로젝트: amon-ra/tollgate
def login(request):
	if request.user.is_authenticated():
		# already logged in
		return redirect('index')

	if request.method == 'POST':
		f = LoginForm(request.POST)
		if not f.is_valid():
			return render_to_response('frontend/login.html', {
				'f': f,
				'fail': False
			}, context_instance=RequestContext(request))

		# check if the user has a password set already
		user = authenticate(
			username=f.cleaned_data['username'],
			password=f.cleaned_data['password']
		)
		if user == None:
			d = {
				'f': f,
				'fail': True,
				'fail_credentials': True,
			}

			return render_to_response('frontend/login.html', d,
				context_instance=RequestContext(request))
		else:
			# user already exists locally, lets use that stuff instead.
			if not user.is_active:
				d = {
					'f': f,
					'fail': True,
					'fail_disabled': True,
				}

				return render_to_response('frontend/login.html', d,
					context_instance=RequestContext(request))

			# success!
			login_do(request, user)

			# also try to sync firewall in this operation
			# reason being is the next operation could change the amount of quota
			# a user has.
			profile = get_userprofile(user)
			try:
				sync_user_connections(profile)
			except:
				# why did this error out?  it probably doesn't need to.
				#return controller_error(request)
				pass

			current_event = get_current_event()
			# check if they need to have their attendance reset
			if not has_userprofile_attended(current_event, profile):
				if user.has_perm('frontend.can_register_attendance'):
					# user is allowed to sign other people in, so let them login.

					# note to them that they need attendance set.
					messages.warning(request, 
						_('Your account does not have attendance registered.  ' + \
							'Login was allowed so that you can do this.')
					)

					# return them to homepage
					return redirect('index')

				else:
					# failure
					d = {
						'f': f, 'fail': True,
						'fail_attendance': True,
					}

					# log them out if they've already had a useraccount for some
					# reason
					logout_do(request)

					return render_to_response('frontend/login.html', d,
						context_instance=RequestContext(request))

			attendance = get_attendance_currentevent(profile)

			# turn on the user's internet connection if they say they wanted it on
			if f.cleaned_data['internet'] or profile.internet_on:
				try:
					enable_user_quota(attendance)
				except:
					return controller_error(request)

			if f.cleaned_data['internet']:
				# we need to do an internet login as well for the user.
				# lets send them across
				#return redirect('internet-login-here')
				return internet_login_here(request)

			# no internet login requested
			# send to homepage
			return redirect('index')
	else:
		f = LoginForm()
		return render_to_response('frontend/login.html', {
			'f': f,
			'fail': False
		}, context_instance=RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: MUCS/tollgate
def login(request):
    if request.user.is_authenticated():
        # already logged in
        return HttpResponseRedirect('/')

    if request.method == 'POST':
        f = LoginForm(request.POST)
        if not f.is_valid():
            return render_to_response('frontend/login.html', {
                'f': f,
                'fail': False
            },
                                      context_instance=RequestContext(request))

        # check if the user has a password set already
        user = authenticate(username=f.cleaned_data['username'],
                            password=f.cleaned_data['password'])
        if user == None:
            d = {
                'f': f,
                'fail': True,
                'fail_credentials': True,
            }

            return render_to_response('frontend/login.html',
                                      d,
                                      context_instance=RequestContext(request))
        else:
            # user already exists locally, lets use that stuff instead.
            if not user.is_active:
                d = {
                    'f': f,
                    'fail': True,
                    'fail_disabled': True,
                }

                return render_to_response(
                    'frontend/login.html',
                    d,
                    context_instance=RequestContext(request))

            # success!
            login_do(request, user)

            # also try to sync firewall in this operation
            # reason being is the next operation could change the amount of quota a user has.
            profile = get_userprofile(user)
            try:
                sync_user_connections(profile)
            except:
                # why did this error out?  it probably doesn't need to.
                #return controller_error(request)
                pass

            current_event = get_current_event()
            # check if they need to have their attendance reset
            if not has_userprofile_attended(current_event, profile):
                if user.has_perm('frontend.can_register_attendance'):
                    # user is allowed to sign other people in, so let them login.

                    # note to them that they need attendance set.
                    messages.warning(
                        request,
                        'Your account does not have attendance registered.  Login was allowed so that you can do this.'
                    )

                    # return them to homepage
                    return HttpResponseRedirect('/')

                else:
                    # failure
                    d = {
                        'f': f,
                        'fail': True,
                        'fail_attendance': True,
                    }

                    # log them out if they've already had a useraccount for some reason
                    logout_do(request)

                    return render_to_response(
                        'frontend/login.html',
                        d,
                        context_instance=RequestContext(request))

            attendance = get_attendance_currentevent(profile)

            # turn on the user's internet connection if they say they wanted it on
            if f.cleaned_data['internet'] or profile.internet_on:
                try:
                    enable_user_quota(attendance)
                except:
                    return controller_error(request)

            if f.cleaned_data['internet']:
                # we need to do an internet login as well for the user.
                # lets send them across
                return HttpResponseRedirect('/internet/login/here/')

            # no internet login requested
            # send to homepage
            return HttpResponseRedirect('/')
    else:
        f = LoginForm()
        return render_to_response('frontend/login.html', {
            'f': f,
            'fail': False
        },
                                  context_instance=RequestContext(request))
예제 #3
0
파일: views.py 프로젝트: amon-ra/tollgate
def logout(request):
	logout_do(request)
	return render_to_response('frontend/logout.html',
		context_instance=RequestContext(request))
예제 #4
0
파일: views.py 프로젝트: MUCS/tollgate
def logout(request):
    logout_do(request)
    return render_to_response('frontend/logout.html',
                              context_instance=RequestContext(request))