Ejemplo n.º 1
0
	def get(self):
		import gdata.auth
		import gdata.calendar
		import gdata.calendar.service
		import gdata_for_gae

		context = {
		    'title': '短信提醒',
		    'page': 'calendar_token',
		    'msg': '',
		    'token': ''
		}
		if ADMIN_PASSWORD:
			context['use_pw'] = True
			calendar_client = gdata_for_gae.programmatic_login(ADMIN_EMAIL, ADMIN_PASSWORD)
			if calendar_client:
				context['msg'] = '当前使用账号密码方式登录,已通过认证'
			else:
				context['msg'] = '当前使用账号密码方式登录,但密码不正确'
		else:
			context['use_pw'] = False
			scope = 'http://www.google.com/calendar/feeds/'
			feed = self.GET['feed']
			if feed:
				auth_token = gdata.auth.extract_auth_sub_token_from_url(self.request.uri)
				if auth_token:
					try:
						calendar_client = gdata.calendar.service.CalendarService()
						gdata_for_gae.run_on_appengine(calendar_client, user=ADMIN_EMAIL, url=feed)
						calendar_client.UpgradeToSessionToken(auth_token)
						context['msg'] = 'Token保存成功'
						context['token'] = gdata_for_gae.load_auth_token(ADMIN_EMAIL)
					except:
						context['msg'] = 'Token验证失败'
				else:
					self.redirect(str(gdata.auth.generate_auth_sub_url(self.request.uri, (scope,))))
					return
			else:
				calendar_client = gdata.calendar.service.CalendarService()
				gdata_for_gae.run_on_appengine(calendar_client, user=ADMIN_EMAIL)
				if not isinstance(calendar_client.token_store.find_token(scope), gdata.auth.AuthSubToken):
					context['msg'] = '尚未保存有效Token'
				else:
					context['msg'] = '已存在有效Token'
					context['token'] = gdata_for_gae.load_auth_token(ADMIN_EMAIL)
		self.echo('calendar_token.html', context)
Ejemplo n.º 2
0
	def get(self):
		import gdata.auth
		import gdata.calendar
		import gdata.calendar.service
		import gdata_for_gae

		context = {
		    'title': 'SMS notice',
		    'page': 'calendar_token',
		    'msg': '',
		    'token': ''
		}
		if ADMIN_PASSWORD:
			context['use_pw'] = True
			calendar_client = gdata_for_gae.programmatic_login(ADMIN_EMAIL, ADMIN_PASSWORD)
			if calendar_client:
				context['msg'] = 'Using account id and password to login and has passed the authentication.'
			else:
				context['msg'] = 'Using account id and password to login, but the password is incorrect.'
		else:
			context['use_pw'] = False
			scope = 'http://www.google.com/calendar/feeds/'
			feed = self.GET['feed']
			if feed:
				auth_token = gdata.auth.extract_auth_sub_token_from_url(self.request.uri)
				if auth_token:
					try:
						calendar_client = gdata.calendar.service.CalendarService()
						gdata_for_gae.run_on_appengine(calendar_client, user=ADMIN_EMAIL, url=feed)
						calendar_client.UpgradeToSessionToken(auth_token)
						context['msg'] = 'Token save successful.'
						context['token'] = gdata_for_gae.load_auth_token(ADMIN_EMAIL)
					except:
						context['msg'] = 'Token authentication failed.'
				else:
					self.redirect(str(gdata.auth.generate_auth_sub_url(self.request.uri, (scope,))))
					return
			else:
				calendar_client = gdata.calendar.service.CalendarService()
				gdata_for_gae.run_on_appengine(calendar_client, user=ADMIN_EMAIL)
				if not isinstance(calendar_client.token_store.find_token(scope), gdata.auth.AuthSubToken):
					context['msg'] = 'No available token exists.'
				else:
					context['msg'] = 'Available token exists.'
					context['token'] = gdata_for_gae.load_auth_token(ADMIN_EMAIL)
		self.echo('calendar_token.html', context)
Ejemplo n.º 3
0
	def get(self):
		import gdata.auth
		import gdata.calendar
		import gdata.calendar.service
		import gdata_for_gae

		context = {
		    'title': '短信提醒',
		    'page': 'calendar_token',
		    'msg': '',
		    'token': ''
		}
		if ADMIN_PASSWORD:
			context['use_pw'] = True
			calendar_client = gdata_for_gae.programmatic_login(ADMIN_EMAIL, ADMIN_PASSWORD)
			if calendar_client:
				context['msg'] = '当前使用账号密码方式登录,已通过认证'
			else:
				context['msg'] = '当前使用账号密码方式登录,但密码不正确'
		else:
			context['use_pw'] = False
			scope = 'http://www.google.com/calendar/feeds/'
			feed = self.GET['feed']
			if feed:
				auth_token = gdata.auth.extract_auth_sub_token_from_url(self.request.uri)
				if auth_token:
					try:
						calendar_client = gdata.calendar.service.CalendarService()
						gdata_for_gae.run_on_appengine(calendar_client, user=ADMIN_EMAIL, url=feed)
						calendar_client.UpgradeToSessionToken(auth_token)
						context['msg'] = 'Token保存成功'
						context['token'] = gdata_for_gae.load_auth_token(ADMIN_EMAIL)
					except:
						context['msg'] = 'Token验证失败'
				else:
					self.redirect(str(gdata.auth.generate_auth_sub_url(self.request.uri, (scope,))))
					return
			else:
				calendar_client = gdata.calendar.service.CalendarService()
				gdata_for_gae.run_on_appengine(calendar_client, user=ADMIN_EMAIL)
				if not isinstance(calendar_client.token_store.find_token(scope), gdata.auth.AuthSubToken):
					context['msg'] = '尚未保存有效Token'
				else:
					context['msg'] = '已存在有效Token'
					context['token'] = gdata_for_gae.load_auth_token(ADMIN_EMAIL)
		self.echo('calendar_token.html', context)
Ejemplo n.º 4
0
    def get(self):
        import gdata.auth
        import gdata.calendar
        import gdata.calendar.service
        import gdata_for_gae

        context = {
                'title': 'SMS Notify',
                'page': 'admin_calendar_token',
                'msg': '',
                'token': ''
                }

        scope = 'http://www.google.com/calendar/feeds/'
        feed = self.GET['feed']
        if feed:
            auth_token = gdata.auth.extract_auth_sub_token_from_url(self.request.uri)
            if auth_token:
                try:
                    calendar_client = gdata.calendar.service.CalendarService()
                    gdata_for_gae.run_on_appengine(calendar_client, user=ADMIN_EMAIL, url=feed)
                    calendar_client.UpgradeToSessionToken(auth_token)
                    context['msg'] = 'token verify success. have saved to datastore'
                    context['token'] = gdata_for_gae.load_auth_token(ADMIN_EMAIL)
                except:
                    context['msg'] = 'Cant verify this token'
            else:
                self.redirect(str(gdata.auth.generate_auth_sub_url(self.request.uri, (scope,))))
                return
        else:
            calendar_client = gdata.calendar.service.CalendarService()
            gdata_for_gae.run_on_appengine(calendar_client, user=ADMIN_EMAIL)
            if not isinstance(calendar_client.token_store.find_token(scope), gdata.auth.AuthSubToken):
                context['msg'] = 'Have not valid token yet'
            else:
                context['msg'] = 'You have had a valid token'
                context['token'] = gdata_for_gae.load_auth_token(ADMIN_EMAIL)
        self.echo('calendar_token.html', context)