def _get_element(self, **kwargs) -> _html.Element: """Render widget. :param **kwargs: """ # If 'verifier' is here, we need to exchange it to an access token if not self._user_id: inp_oauth_verifier = _router.request().inp.get('oauth_verifier') if inp_oauth_verifier: token = self._session.get_access_token(inp_oauth_verifier) self._oauth_token = token['oauth_token'] self._oauth_token_secret = token['oauth_token_secret'] self._user_id = token['user_id'] self._screen_name = token['screen_name'] wrapper = _html.TagLessElement() wrapper.append( _widget.input.Hidden( uid=self.uid + '[oauth_token]', value=self.oauth_token, ).renderable()) wrapper.append( _widget.input.Hidden( uid=self.uid + '[oauth_token_secret]', value=self.oauth_token_secret, ).renderable()) wrapper.append( _widget.input.Hidden( uid=self.uid + '[user_id]', value=self.user_id, ).renderable()) wrapper.append( _widget.input.Hidden( uid=self.uid + '[screen_name]', value=self.screen_name, ).renderable()) if self.screen_name: title = self.screen_name href = 'https://twitter.com/' + self._screen_name else: title = _lang.t('twitter@authorization') href = self._session.get_authorization_url(self._callback_uri) a = _html.A(title, href=href) a.append(_html.I(css='fa fa-twitter')) wrapper.append( _widget.static.HTML( uid=self.uid + '[auth_link]', em=a, ).renderable()) return wrapper
def _get_element(self, **kwargs) -> _html.Element: """Get HTML element of the widget. :param **kwargs: """ wrapper = _html.TagLessElement() wrapper.append( _widget.input.Text( uid='{}[username]'.format(self._uid), label=_lang.t('content_export_livejournal@username'), required=True, value=self._username, ).renderable()) wrapper.append( _widget.input.Password( uid='{}[password]'.format(self._uid), label=_lang.t('content_export_livejournal@password'), required=True, value=self._password, ).renderable()) wrapper.append( _widget.input.Text( uid='{}[lj_like]'.format(self._uid), label=_lang.t('content_export_livejournal@lj_like_buttons'), help=_lang.t( 'content_export_livejournal@lj_like_buttons_help'), value=self._lj_like, ).renderable()) wrapper.append( _widget.input.Hidden( uid='title', name='{}[title]'.format(self._uid), required=True, value=self._title, ).renderable()) return wrapper
def _get_element(self, **kwargs) -> _html.Element: """Render widget. :param **kwargs: """ authorize_url = _router.url('https://oauth.vk.com/authorize', query={ 'client_id': self._app_id, 'scope': ','.join(self.scope), 'redirect_uri': 'https://oauth.vk.com/blank.html', 'display': 'page', 'response_type': 'token', 'v': '5.37', }) wrapper = _html.TagLessElement() wrapper.append( _widget.input.Text( uid=self.uid + '[access_url]', weight=10, label=_lang.t('vkontakte@access_url'), help=_lang.t('vkontakte@access_url_help', {'link': authorize_url}), value=self.access_url, required=True, ).renderable()) wrapper.append( _widget.input.Integer(uid=self.uid + '[group_id]', weight=20, label=_lang.t('vkontakte@group_id'), value=self.group_id, h_size='col-sm-2').renderable()) return wrapper
def _get_element(self, **kwargs) -> _html.Element: """Get HTML element representation of the widget. :param **kwargs: """ # 'state' and 'code' typically received after successful Facebook authorization redirect inp = _router.request().inp state = inp.get('state') auth_code = inp.get('code') # Try to fetch access token from Facebook if not self._access_token and (state and auth_code): t_info = _AuthSession(state).get_access_token(auth_code) self._access_token = t_info['access_token'] self._access_token_type = t_info['token_type'] self._access_token_expires = float(t_info.get('expires_in', 0)) if self._access_token_expires: self._access_token_expires = int(_datetime.now().timestamp() + self._access_token_expires) me = _Session(self._access_token).me() self._user_id = me['id'] self._screen_name = me['name'] # Pages if self._access_token: for acc in _Session(self._access_token).accounts(): if 'CREATE_CONTENT' in acc['perms']: self._pages.append((acc['id'], acc['name'])) # Link to user profile or to facebook authorization URL if self._user_id and self._screen_name: a = _html.A(self._screen_name, href='https://facebook.com/' + self._user_id, target='_blank') a.append(_html.I(css='fa fa-facebook-square')) else: a = _html.A(href=_AuthSession(redirect_uri=self._redirect_url). get_authorization_url(self._scope)) a.append( _html.Img(src=_assetman.url( 'facebook@img/facebook-login-button.png'))) cont = _html.TagLessElement() cont.append( _widget.static.Text(self.uid + '[auth_url]', label=_lang.t('facebook@user'), text=a.render()).renderable()) # Page select if self.pages: cont.append( _widget.select.Select(self.uid + '[page_id]', value=self._page_id, label=_lang.t('facebook@page'), items=self.pages, h_size='col-sm-6').renderable()) cont.append( _widget.input.Hidden(self.uid + '[access_token]', value=self.access_token).renderable()) cont.append( _widget.input.Hidden(self.uid + '[access_token_type]', value=self.access_token_type).renderable()) cont.append( _widget.input.Hidden(self.uid + '[access_token_expires]', value=self.access_token_expires).renderable()) cont.append( _widget.input.Hidden(self.uid + '[user_id]', value=self.user_id).renderable()) cont.append( _widget.input.Hidden(self.uid + '[screen_name]', value=self.screen_name).renderable()) return cont
def _get_element(self, **kwargs) -> _html.Element: """Hook """ # If 'verifier' is here, we need to exchange it to an access token inp_oauth_token = _router.request().inp.get('oauth_token') inp_oauth_verifier = _router.request().inp.get('oauth_verifier') if inp_oauth_token and inp_oauth_verifier: access_data = TumblrAuthSession(inp_oauth_token).get_access_token( self._callback_uri) self._oauth_token = access_data['oauth_token'] self._oauth_token_secret = access_data['oauth_token_secret'] user_info = TumblrSession(self._oauth_token, self._oauth_token_secret).user_info() self._screen_name = user_info['name'] if self._oauth_token and self._oauth_token_secret and self._screen_name: user_info = TumblrSession(self._oauth_token, self._oauth_token_secret).user_info() self._user_blogs = [(i['name'], i['title']) for i in user_info['blogs']] wrapper = _html.TagLessElement() wrapper.append( _widget.input.Hidden( uid=self.uid + '[oauth_token]', value=self.oauth_token, ).renderable()) wrapper.append( _widget.input.Hidden( uid=self.uid + '[oauth_token_secret]', value=self.oauth_token_secret, ).renderable()) wrapper.append( _widget.input.Hidden( uid=self.uid + '[screen_name]', value=self.screen_name, ).renderable()) if self.user_blogs: a = _html.A(' {}'.format(self.screen_name), href='http://{}.tumblr.com'.format(self.screen_name), target='_blank') a.append(_html.I(css='fa fa-fw fa-tumblr')) wrapper.append( _widget.static.HTML(self.uid + '[user]', em=a).renderable()) wrapper.append( _widget.select.Select( uid=self.uid + '[user_blog]', h_size='col-sm-6', items=self.user_blogs, value=self.user_blog, required=True, label=_lang.t('tumblr@blog')).renderable()) else: auth_s = TumblrAuthSession( callback_uri=self._callback_uri).fetch_request_token() a = _html.A(_lang.t('tumblr@authorization'), href=auth_s.get_authorization_url()) a.append(_html.I(css='fa fa-fw fa-tumblr')) wrapper.append( _widget.static.HTML(self.uid + '[user]', em=a).renderable()) return wrapper
def _get_element(self, **kwargs) -> _html.Element: return _html.TagLessElement( _tpl.render('auth_ui_ulogin@widget', {'widget': self}))