当前位置: 首页>>代码示例>>Python>>正文


Python User.by_credentials方法代码示例

本文整理汇总了Python中pyvac.models.User.by_credentials方法的典型用法代码示例。如果您正苦于以下问题:Python User.by_credentials方法的具体用法?Python User.by_credentials怎么用?Python User.by_credentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyvac.models.User的用法示例。


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

示例1: test_by_credentials_ok

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
 def test_by_credentials_ok(self):
     from pyvac.models import User
     user = User.by_credentials(self.session, u'jdoe', u'changeme')
     self.assertIsInstance(user, User)
     self.assertEqual(user.login, u'jdoe')
     self.assertEqual(user.name, u'John Doe')
     self.assertEqual(user.role, u'user')
开发者ID:doyousoft,项目名称:pyvac,代码行数:9,代码来源:test_models.py

示例2: authenticated_userid

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
    def authenticated_userid(self, request):

        auth = request.environ.get('HTTP_AUTHORIZATION')
        try:
            authmeth, auth = auth.split(' ', 1)
        except AttributeError as ValueError:  # not enough values to unpack
            return None

        if authmeth.lower() != 'basic':
            return None

        try:
            # Python 3's string is already unicode
            auth = auth.strip().decode('base64')
            if sys.version_info[0] == 2:
                auth = unicode(auth)
        except binascii.Error:  # can't decode
            return None
        try:
            login, password = auth.split(':', 1)
        except ValueError:  # not enough values to unpack
            return None

        if User.by_credentials(DBSession(), login, password):
            return login

        return None
开发者ID:doyousoft,项目名称:pyvac,代码行数:29,代码来源:authentication.py

示例3: test_change_password_post_ko_unchanged

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
 def test_change_password_post_ko_unchanged(self):
     from pyvac.models import User
     from pyvac.views.user import ChangePassword as ChangePwd
     view = ChangePwd(self.create_request({'form.submitted': u'1',
                                           'current_password': u'changeme',
                                           'user.password': u'changeme',
                                           'confirm_password': u'changeme',
                                           }))()
     self.assertEqual(view['errors'],
                      [u'password is inchanged'])
     admin = User.by_credentials(self.session, u'admin', u'changeme')
     self.assertIsInstance(admin, User)
开发者ID:doyousoft,项目名称:pyvac,代码行数:14,代码来源:test_user.py

示例4: test_change_password_post_ok

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
 def test_change_password_post_ok(self):
     from pyvac.models import User
     from pyvac.views.user import ChangePassword as ChangePwd
     ChangePwd(self.create_request({'form.submitted': u'1',
                                    'current_password': u'changeme',
                                    'user.password': u'newpassw',
                                    'confirm_password': u'newpassw',
                                    }))()
     admin = User.by_credentials(self.session, u'admin', u'newpassw')
     self.assertIsInstance(admin, User)
     admin.password = u'changeme'
     self.session.add(admin)
开发者ID:doyousoft,项目名称:pyvac,代码行数:14,代码来源:test_user.py

示例5: test_change_password_post_ko_not_matched

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
 def test_change_password_post_ko_not_matched(self):
     from pyvac.models import User
     from pyvac.views.user import ChangePassword as ChangePwd
     view = ChangePwd(self.create_request({'form.submitted': u'1',
                                           'current_password': u'CHANGEME',
                                           'user.password': u'newpassw',
                                           'confirm_password': u'NEWPASSW',
                                           }))()
     self.assertEqual(view['errors'],
                      [u'current password is not correct',
                       u'passwords do not match'])
     admin = User.by_credentials(self.session, u'admin', u'changeme')
     self.assertIsInstance(admin, User)
开发者ID:doyousoft,项目名称:pyvac,代码行数:15,代码来源:test_user.py

示例6: validate

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
    def validate(self, model, errors):
        r = self.request

        if not User.by_credentials(self.session, model.login,
                                   r.params['current_password']):
            errors.append(_(u'current password is not correct'))
        elif r.params['user.password'] == r.params['current_password']:
            errors.append(_(u'password is inchanged'))

        if r.params['user.password'] != r.params['confirm_password']:
            errors.append(_(u'passwords do not match'))

        return len(errors) == 0
开发者ID:doyousoft,项目名称:pyvac,代码行数:15,代码来源:user.py

示例7: render

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
    def render(self):

        login_url = resource_url(self.request.context, self.request, "login")
        referrer = self.request.url
        # never use the login form itself as came_from
        if referrer == login_url:
            referrer = "/"
        came_from = self.request.params.get("came_from", referrer)
        if came_from == "/":
            came_from = "/home"

        login = self.request.params.get("login", "")
        if "submit" in self.request.params:
            password = self.request.params.get("password", u"")
            if password:
                settings = self.request.registry.settings
                ldap = False
                if "pyvac.use_ldap" in settings:
                    ldap = asbool(settings.get("pyvac.use_ldap"))

                try:
                    user = User.by_credentials(self.session, login, password, ldap)
                    if user is not None:
                        log.info("login %r succeed" % user.login)
                        headers = remember(self.request, user.login)

                        # check for available users for sudo
                        sudoers = Sudoer.alias(self.session, user)
                        if sudoers:
                            location = route_url("sudo", self.request)
                            return HTTPFound(location=location, headers=headers)

                        return HTTPFound(location=came_from, headers=headers)
                    else:
                        msg = "Invalid credentials."
                        self.request.session.flash("error;%s" % msg)
                except SERVER_DOWN:
                    msg = "Cannot reach ldap server."
                    self.request.session.flash("error;%s" % msg)
                except INVALID_CREDENTIALS:
                    msg = "Invalid credentials."
                    self.request.session.flash("error;%s" % msg)
                except UnknownLdapUser:
                    msg = "Unknown ldap user %s" % login
                    self.request.session.flash("error;%s" % msg)

        return {"came_from": came_from, "csrf_token": self.request.session.get_csrf_token()}
开发者ID:doyousoft,项目名称:pyvac,代码行数:49,代码来源:credentials.py

示例8: render

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
    def render(self):

        login_url = resource_url(self.request.context, self.request, 'login')
        referrer = self.request.url
        # never use the login form itself as came_from
        if referrer == login_url:
            referrer = '/'
        came_from = self.request.params.get('came_from', referrer)
        if came_from == '/':
            came_from = '/home'

        login = self.request.params.get('login', '')
        if 'submit' in self.request.params:
            password = self.request.params.get('password', u'')
            if password:
                settings = self.request.registry.settings
                ldap = False
                if 'pyvac.use_ldap' in settings:
                    ldap = asbool(settings.get('pyvac.use_ldap'))

                try:
                    user = User.by_credentials(self.session, login,
                                               password, ldap)
                    if user is not None:
                        log.info('login %r succeed' % login)
                        headers = remember(self.request, login)
                        return HTTPFound(location=came_from,
                                         headers=headers)
                    else:
                        msg = 'Invalid credentials.'
                        self.request.session.flash('error;%s' % msg)
                except SERVER_DOWN:
                    msg = 'Cannot reach ldap server.'
                    self.request.session.flash('error;%s' % msg)
                except INVALID_CREDENTIALS:
                    msg = 'Invalid credentials.'
                    self.request.session.flash('error;%s' % msg)
                except UnknownLdapUser:
                    msg = 'Unknown ldap user %s' % login
                    self.request.session.flash('error;%s' % msg)

        return {'came_from': came_from,
                'csrf_token': self.request.session.get_csrf_token(),
                }
开发者ID:grigouze,项目名称:pyvac,代码行数:46,代码来源:credentials.py

示例9: test_update_post_ok

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
 def test_update_post_ok(self):
     from pyvac.models import User
     from pyvac.views.user import Edit
     view = Edit(self.create_request({'form.submitted': u'1',
                                      'user.login': u'root',
                                      'user.firstname': u'Admin',
                                      'user.lastname': u'Istrator',
                                      }))()
     self.assertIsRedirect(view)
     self.session.flush()
     admin = User.by_credentials(self.session, u'root', u'changeme')
     self.assertIsInstance(admin, User)
     self.assertEqual(admin.login, u'root')
     self.assertEqual(admin.firstname, u'Admin')
     self.assertEqual(admin.lastname, u'Istrator')
     admin.login = u'admin'
     admin.password = u'changeme'
     admin.firstname = None
     admin.lastname = None
     self.session.add(admin)
开发者ID:doyousoft,项目名称:pyvac,代码行数:22,代码来源:test_user.py

示例10: validate

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
    def validate(self, model, errors):
        r = self.request
        settings = r.registry.settings
        ldap = False
        if 'pyvac.use_ldap' in settings:
            ldap = asbool(settings.get('pyvac.use_ldap'))

        if 'current_password' in r.params and r.params['current_password']:
            if not User.by_credentials(self.session, model.login,
                                       r.params['current_password'], ldap):
                errors.append(_(u'current password is not correct'))
            elif r.params['user.password'] == r.params['current_password']:
                errors.append(_(u'password is unchanged'))

            if r.params['user.password'] != r.params['confirm_password']:
                errors.append(_(u'passwords do not match'))

            if errors:
                self.request.session.flash('error;%s' % ','.join(errors))

        return len(errors) == 0
开发者ID:grigouze,项目名称:pyvac,代码行数:23,代码来源:account.py

示例11: test_by_credentials_ko_password

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
 def test_by_credentials_ko_password(self):
     from pyvac.models import User
     user = User.by_credentials(self.session, u'admin', 'CHANGEME')
     self.assertIsNone(user)
开发者ID:doyousoft,项目名称:pyvac,代码行数:6,代码来源:test_models.py

示例12: test_by_credentials_ko_mirrored

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
 def test_by_credentials_ko_mirrored(self):
     from pyvac.models import User
     user = User.by_credentials(self.session, u'johndo', '')
     self.assertEqual(user, None)
开发者ID:doyousoft,项目名称:pyvac,代码行数:6,代码来源:test_models.py

示例13: test_by_credentials_ko_unexists

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_credentials [as 别名]
 def test_by_credentials_ko_unexists(self):
     from pyvac.models import User
     user = User.by_credentials(self.session, u'u404', u"' OR 1 = 1 #")
     self.assertEqual(user, None)
开发者ID:doyousoft,项目名称:pyvac,代码行数:6,代码来源:test_models.py


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