• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python session.pop函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pylons.session.pop函数的典型用法代码示例。如果您正苦于以下问题:Python pop函数的具体用法?Python pop怎么用?Python pop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: authenticated_user

def authenticated_user(reload=False):
    """
    Returns reference to AuthenticatedUser which is stored in session.
    If it's not in session method will add it and save session, then return object.
    """

    AUTHENTICATED_USER = "AUTHENTICATED_USER"

    # Create authenticated user if it doesn't exist
    if request.environ.has_key('REMOTE_USER'):
        if reload or not session.has_key(AUTHENTICATED_USER) \
            or session[AUTHENTICATED_USER] == None \
            or session[AUTHENTICATED_USER].username != request.environ['REMOTE_USER']:
            model = request.environ['sqlalchemy.model']
            db = request.environ['sqlalchemy.session']

            try:
                authenticated_user = db.query(model.AuthenticatedUser).filter_by(username=request.environ['REMOTE_USER']).one()
            except:
                authenticated_user = model.AuthenticatedUser(
                    username = request.environ['REMOTE_USER'], email = request.environ['REMOTE_USER'])
                db.save(authenticated_user)
                db.commit()
                log.info(_("Created an %s" % (str(authenticated_user))))
            db.expunge(authenticated_user)
            session[AUTHENTICATED_USER] = authenticated_user
            session.save()
    
        return session[AUTHENTICATED_USER]

    if session.has_key(AUTHENTICATED_USER):
        session.pop(AUTHENTICATED_USER, None)
        session.save()

    return None
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:35,代码来源:helpers.py


示例2: logout

 def logout(self):
     if "user" not in session:
         return redirect("/")
     else:
         session.pop("user")
         session.save()
         return redirect("/")
开发者ID:maguire,项目名称:Montserrat,代码行数:7,代码来源:users.py


示例3: index

 def index(self):
     c.user_name = session.pop('user_name', '')
     c.user_url = session.pop('user_url', '')
     c.user_phone = session.pop('user_phone', '')
     c.user_email = session.pop('user_email', '')
     c.capcha_error = session.pop('capcha_error', '')
     session.save()
     return render('/register_user.mako.html')
开发者ID:testTemtProj,项目名称:OLD_PROJECT,代码行数:8,代码来源:register_user.py


示例4: import_metadata

 def import_metadata(self, **kwargs):
     if request.method == 'POST':
         redirect_url = self._import_metadata(request.params)
         redirect(redirect_url)
     else:
         c.group_id = request.params.get('group')
         c.error_summary = session.pop('error_summary', None)
         c.errors = session.pop('errors', None)
         c.result = session.pop('result', None)
         return render('package/import_metadata.html')
开发者ID:PublicaMundi,项目名称:ckanext-publicamundi,代码行数:10,代码来源:package.py


示例5: logout

 def logout(self):
     if 'user' not in session:
         session['flash'] = 'Not logged in'
         session.save()
         return redirect('/')
     else:
         session.pop('user')
         session.save()
         session['flash'] = 'Successfully logged out'
         session.save()
         return redirect('/')
开发者ID:cmoylan,项目名称:chrismoylan-legacy,代码行数:11,代码来源:users.py


示例6: _process_contact

    def _process_contact(self):

        # Validate secure_form's (CSRF protection) token

        if not (request.params.get(secure_form.token_key) == secure_form.authentication_token()):
            abort (403, detail=u'Not permitted (possible CSRF attack)')

        # If cancelled, dont do anything

        if request.params.get('op') != 'Submit':
            session.pop('contactform.errors', None)
            session.pop('contactform.values', None)
            return url(controller='contactform', action='nevermind')

        # Validate form fields ...

        schema = ContactForm()
        try:
            fields = schema.to_python(dict(request.params))
            session.pop('contactform.errors', None)
            session.pop('contactform.values', None)
            self._save_contact(fields, schema)
            return url(controller='contactform', action='thanks')
        except formencode.Invalid, ex:
            session.update({
                'contactform.errors': ex.error_dict,
                'contactform.values': ex.value,
            })
            return url(controller='contactform', action='contact')
开发者ID:drmalex07,项目名称:pylons-helloworld,代码行数:29,代码来源:contactform.py


示例7: do_signin

    def do_signin(self):
        path_before_login = session.pop("path_before_login", self.default_path)
        
        g = self._py_object.app_globals
        
        # disable api check in *.ini config
        if g.check_api:
            api = eveapi.EVEAPIConnection()

            auth = api.auth(userID=c.api_userid, apiKey=c.api_key)
            
            def check_character(name):
                try:
                    result = auth.account.Characters()
                except eveapi.Error, e:
                    c.errors.add(e.args[0])
                    return None

                for char in result.characters:
                    if char.name == name:
                        return char
                return None
            
            def get_corp(char):
                try:
                    result = auth.corp.CorporationSheet(characterID=char.characterID)
                except eveapi.Error, e:
                    c.errors.add(e.args[0])
                    return None
                
                return result
开发者ID:udoprog,项目名称:battleplan,代码行数:31,代码来源:auth.py


示例8: logged_in

    def logged_in(self):
        # we need to set the language via a redirect
        lang = session.pop('lang', None)
        session.save()

        # we need to set the language explicitly here or the flash
        # messages will not be translated.
        ckan.lib.i18n.set_lang(lang)

        if c.user:
            context = {'model': model,
                       'user': c.user}

            data_dict = {'id': c.user}

            user_dict = get_action('user_show')(context, data_dict)

            h.flash_success(_("%s is now logged in") %
                            user_dict['display_name'])
            return self.me(locale=lang)
        else:
            err = _('Login failed. Bad username or password.')
            if g.openid_enabled:
                err += _(' (Or if using OpenID, it hasn\'t been associated '
                         'with a user account.)')
            h.flash_error(err)
            h.redirect_to(locale=lang, controller='user', action='login')
开发者ID:abulte,项目名称:ckan,代码行数:27,代码来源:user.py


示例9: logged_in

    def logged_in(self):
        # we need to set the language via a redirect
        lang = session.pop("lang", None)
        session.save()
        came_from = request.params.get("came_from", "")

        # we need to set the language explicitly here or the flash
        # messages will not be translated.
        i18n.set_lang(lang)

        if c.user:
            context = None
            data_dict = {"id": c.user}

            user_dict = get_action("user_show")(context, data_dict)

            h.flash_success(_("%s is now logged in") % user_dict["display_name"])
            if came_from:
                return h.redirect_to(str(came_from))
            return self.me()
        else:
            err = _("Login failed. Bad username or password.")
            if g.openid_enabled:
                err += _(" (Or if using OpenID, it hasn't been associated " "with a user account.)")
            if h.asbool(config.get("ckan.legacy_templates", "false")):
                h.flash_error(err)
                h.redirect_to(locale=lang, controller="user", action="login", came_from=came_from)
            else:
                return self.login(error=err)
开发者ID:Web5design,项目名称:ckan,代码行数:29,代码来源:user.py


示例10: login

    def login(self, error=None):
        lang = session.pop('lang', None)
        if lang:
            session.save()
            return h.redirect_to(locale=str(lang), controller='user',
                                 action='login')
        if 'error' in request.params:
            h.flash_error(request.params['error'])

        if request.environ['SCRIPT_NAME'] and g.openid_enabled:
            # #1662 restriction
            log.warn('Cannot mount CKAN at a URL and login with OpenID.')
            g.openid_enabled = False

        if not c.user:
            came_from = request.params.get('came_from', '')
            c.login_handler = h.url_for(
                self._get_repoze_handler('login_handler_path'),
                came_from=came_from)
            if error:
                vars = {'error_summary': {'': error}}
            else:
                vars = {}
            return render('user/login.html', extra_vars=vars)
        else:
            return render('user/logout_first.html')
开发者ID:Lennaron,项目名称:ckan,代码行数:26,代码来源:user.py


示例11: pop_messages

 def pop_messages(self):
     from pylons import session
     messages = session.pop(self.session_key, [])
     # only save session if it has changed
     if messages:
         session.save()
     return [Message(*m) for m in messages]
开发者ID:allanglen,项目名称:ckan,代码行数:7,代码来源:helpers.py


示例12: logged_in

    def logged_in(self):
        # we need to set the language via a redirect
        lang = session.pop('lang', None)
        session.save()
        came_from = request.params.get('came_from', '')

        # we need to set the language explicitly here or the flash
        # messages will not be translated.
        i18n.set_lang(lang)

        if c.user:
            context = None
            data_dict = {'id': c.user}

            user_dict = get_action('user_show')(context, data_dict)

            h.flash_success(_("%s is now logged in") %
                            user_dict['display_name'])
            if came_from:
                return h.redirect_to(str(came_from))
            return self.me()
        else:
            err = _('Login failed. Bad username or password.')
            if g.openid_enabled:
                err += _(' (Or if using OpenID, it hasn\'t been associated '
                         'with a user account.)')
            if h.asbool(config.get('ckan.legacy_templates', 'false')):
                h.flash_error(err)
                h.redirect_to(locale=lang, controller='user',
                              action='login', came_from=came_from)
            else:
                return self.login(error=err)
开发者ID:Lennaron,项目名称:ckan,代码行数:32,代码来源:user.py


示例13: pop_message

 def pop_message(self):
     message = session.pop("flash", None)
     session['flash'] = None
     session.save()
     if not message:
         return None
     return message
开发者ID:JoneXiong,项目名称:FreePyBX,代码行数:7,代码来源:flash.py


示例14: logged_in

    def logged_in(self):
        # we need to set the language via a redirect
        lang = session.pop('lang', None)
        session.save()

        # we need to set the language explicitly here or the flash
        # messages will not be translated.
        i18n.set_lang(lang)

        if c.user:
            is_new = False
            is_sysadmin = new_authz.is_sysadmin(c.user)

            # Retrieve information about the current user
            context = {'model': model, 'session': model.Session,
                   'user': c.user or c.author,
                   'schema': schema.user_new_form_schema()}
            data_dict = {'id': c.user}

            user_dict = get_action('user_show')(context, data_dict)

            # This check is not needed (or correct) for sys admins
            if not is_sysadmin:

                # Get all organizations and all groups the user belongs to
                orgs_q = model.Session.query(model.Group) \
                    .filter(model.Group.is_organization == True) \
                    .filter(model.Group.state == 'active')
                q = model.Session.query(model.Member) \
                    .filter(model.Member.table_name == 'user') \
                    .filter(model.Member.table_id == user_dict['id'])

                group_ids = []
                for row in q.all():
                    group_ids.append(row.group_id)

                if not group_ids:
                    is_new = True
                else:
                    orgs_q = orgs_q.filter(model.Group.id.in_(group_ids))

                    orgs_list = model_dictize.group_list_dictize(orgs_q.all(), context)

                    if len(orgs_list) == 0:
                        is_new = True

            h.flash_success(_("<p><strong>Note</strong></p>"
                "<p>%s is now logged in</p>") %
                user_dict['display_name'], allow_html=True)

            if is_new:
                return h.redirect_to(controller='ckanext.canada.controller:CanadaController',
                                         action='view_new_user', locale=lang)
            else:
                return h.redirect_to(controller='package',
                    action='search', locale=lang)
        else:
            h.flash_error(_('Login failed. Bad username or password.'))
            return h.redirect_to(controller='user',
                action='login', locale=lang)
开发者ID:mathew-thomas,项目名称:ckanext-canada,代码行数:60,代码来源:controller.py


示例15: pop_messages

    def pop_messages(self):
        """Return all accumulated messages and delete them from the session.

        The return value is a list of ``Message`` objects.
        """
        from pylons import session
        messages = session.pop(self.session_key, [])
        session.save()
        return [_Message(*m) for m in messages]
开发者ID:greenboxindonesia,项目名称:rhodecode,代码行数:9,代码来源:helpers.py


示例16: _process_login

 def _process_login(self):
     user = self.form_result['user']
     user.process_login()        
     success_flash('You have logged into PylonsHQ')
     if session.get('redirect'):
         redir_url = session.pop('redirect')
         session.save()
         redirect(url(redir_url))
     redirect(url('home'))
开发者ID:Pylons,项目名称:kai,代码行数:9,代码来源:accounts.py


示例17: _finish_signup

    def _finish_signup(self):
        c.person = h.signed_in_person()
        self.finish_edit(c.person)

        redirect_location = session.pop('redirect_to', None)
        if redirect_location:
            redirect_to(str(redirect_location))
        else:
            redirect_to('home')
开发者ID:iseppi,项目名称:zookeepr,代码行数:9,代码来源:person.py


示例18: getFlash

def getFlash(toRender=True):
	session = _get_session()
	if(toRender):
		session['flashRendered'] = True
	flash = session.get("flash",False)
	if not toRender and session.get('flashRendered',False):
		flash = session.pop("flash",False)
	session.save()
	return flash
	pass
开发者ID:sinjax,项目名称:drsin,代码行数:10,代码来源:flash.py


示例19: signin

    def signin(self):

        role_error = session.pop('role_error', None)
        if role_error:
            h.flash(role_error)
        elif h.signed_in_person():
            h.flash("You're already logged in")
            redirect_to('home')

        return render('/person/signin.mako')
开发者ID:iseppi,项目名称:zookeepr,代码行数:10,代码来源:person.py


示例20: signout

 def signout(self):
     domain = request.params.get('domain')
     username = request.params.get('username')
     userid = request.params.get('userid')
     if domain and username or userid:
         try:
             keys = [k for k in session.get('account_keys', '').split(',') if k]
             rem_keys = keys[:]
             for k in keys:
                 acct = session[k]
                 if acct['domain']==domain and \
                    (not username or acct['username']==username) and \
                    (not userid or acct['userid']==userid):
                     session.pop(k)
                     rem_keys.remove(k)
             session['account_keys'] = ','.join(rem_keys)
         except:
             log.exception('failed to signout from domain %s', domain)
             session.clear()
     else:
         session.clear()
     session.save()
开发者ID:tarekziade,项目名称:server-share-send,代码行数:22,代码来源:account.py



注:本文中的pylons.session.pop函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python session.save函数代码示例发布时间:2022-05-25
下一篇:
Python session.has_key函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap