Exemplo n.º 1
0
	def authenticate(self, ctx):
		"""
		Authenticate the current session.
		"""
		request = inevow.IRequest(ctx)
		
		creds = session.getSessionCredentials(ctx)
		iface, user, logout = yield self.portal.login(creds, None, inevow.IResource)
		yield session.updateSession(self.pool, request, user)
		
		self.user = user
Exemplo n.º 2
0
	def renderHTTP(self, ctx):
		"""
		Login form processing, logged-in user and OpenID flow redirect.
		
		@see: L{nevow.inevow.IResource}
		"""
		request = inevow.IRequest(ctx)
		requestData = protocol.OpenIDRequest(request)
		
		log.msg('UserPage request: %r' % requestData)
		if(requestData.get('submit') == 'cancel'):
			return_to = requestData.get('openid.return_to', protocol.OPENID_LOGIN_URL)
			redirect = util.appendQuery(return_to, {'openid.mode':'cancel'})
			request.redirect(redirect)
			returnValue('')
		elif(requestData.get('submit') == 'login'):
			creds = credentials.UsernamePassword(requestData.get('username', ''),
												 requestData.get('password', ''))
		else:
			creds = session.getSessionCredentials(ctx)
		
		iface, user, logout = yield self.portal.login(creds, None, inevow.IResource)
		
		for k, v in requestData.items():
			if not(k.startswith('openid.')):
				del requestData[k]
		
		yield session.updateSession(self.pool, request, user)
		
		if(user):
			if('openid.mode' in requestData):
				redirect = util.appendQuery(protocol.OPENID_PROVIDER_URL, requestData)
				request.redirect(redirect)
				returnValue('')
			else:
				# This will happen if someone logs in directly, or is already logged in.
				request.redirect(protocol.OPENID_INFO_URL)
				returnValue('')
		
		result = yield maybeDeferred(super(LoginPage, self).renderHTTP, ctx)
		returnValue(result)