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


Python user.UserModel类代码示例

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


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

示例1: test_delete_ips

    def test_delete_ips(self, auto_clear_ip_permissions):
        self.log_user()
        default_user_id = User.get_default_user().user_id

        ## first add
        new_ip = '127.0.0.0/24'
        with test_context(self.app):
            user_model = UserModel()
            ip_obj = user_model.add_extra_ip(default_user_id, new_ip)
            Session().commit()

        ## double check that add worked
        # IP permissions are cached, need to invalidate this cache explicitly
        invalidate_all_caches()
        self.app.get(url('admin_permissions_ips'), status=302)
        # REMOTE_ADDR must match 127.0.0.0/24
        response = self.app.get(url('admin_permissions_ips'),
                                extra_environ={'REMOTE_ADDR': '127.0.0.1'})
        response.mustcontain('127.0.0.0/24')
        response.mustcontain('127.0.0.0 - 127.0.0.255')

        ## now delete
        response = self.app.post(url('edit_user_ips_delete', id=default_user_id),
                                 params=dict(del_ip_id=ip_obj.ip_id,
                                             _authentication_token=self.authentication_token()),
                                 extra_environ={'REMOTE_ADDR': '127.0.0.1'})

        # IP permissions are cached, need to invalidate this cache explicitly
        invalidate_all_caches()

        response = self.app.get(url('admin_permissions_ips'))
        response.mustcontain('All IP addresses are allowed')
        response.mustcontain(no=['127.0.0.0/24'])
        response.mustcontain(no=['127.0.0.0 - 127.0.0.255'])
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:34,代码来源:test_admin_permissions.py

示例2: create

 def create(self):
     c.default_extern_type = User.DEFAULT_AUTH_TYPE
     c.default_extern_name = ''
     user_model = UserModel()
     user_form = UserForm()()
     try:
         form_result = user_form.to_python(dict(request.POST))
         user = user_model.create(form_result)
         action_logger(request.authuser, 'admin_created_user:%s' % user.username,
                       None, request.ip_addr)
         h.flash(_('Created user %s') % user.username,
                 category='success')
         Session().commit()
     except formencode.Invalid as errors:
         return htmlfill.render(
             render('admin/users/user_add.html'),
             defaults=errors.value,
             errors=errors.error_dict or {},
             prefix_error=False,
             encoding="UTF-8",
             force_defaults=False)
     except UserCreationError as e:
         h.flash(e, 'error')
     except Exception:
         log.error(traceback.format_exc())
         h.flash(_('Error occurred during creation of user %s') \
                 % request.POST.get('username'), category='error')
     raise HTTPFound(location=url('edit_user', id=user.user_id))
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:28,代码来源:users.py

示例3: test_ip_restriction_hg

    def test_ip_restriction_hg(self, webserver):
        user_model = UserModel()
        try:
            user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
            Session().commit()
            clone_url = webserver.repo_url(HG_REPO)
            stdout, stderr = Command(TESTS_TMP_PATH).execute('hg clone', clone_url, _get_tmp_dir(), ignoreReturnCode=True)
            assert 'abort: HTTP Error 403: Forbidden' in stderr
        finally:
            #release IP restrictions
            for ip in UserIpMap.query():
                UserIpMap.delete(ip.ip_id)
            Session().commit()

        # IP permissions are cached, need to wait for the cache in the server process to expire
        time.sleep(1.5)

        clone_url = webserver.repo_url(HG_REPO)
        stdout, stderr = Command(TESTS_TMP_PATH).execute('hg clone', clone_url, _get_tmp_dir())

        assert 'requesting all changes' in stdout
        assert 'adding changesets' in stdout
        assert 'adding manifests' in stdout
        assert 'adding file changes' in stdout

        assert stderr == ''
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:26,代码来源:test_vcs_operations.py

示例4: delete_email

 def delete_email(self, id):
     user = self._get_user_or_raise_if_default(id)
     email_id = request.POST.get('del_email_id')
     user_model = UserModel()
     user_model.delete_extra_email(id, email_id)
     Session().commit()
     h.flash(_("Removed email from user"), category='success')
     raise HTTPFound(location=url('edit_user_emails', id=id))
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:8,代码来源:users.py

示例5: delete_email

 def delete_email(self, id):
     """DELETE /user_emails_delete/id: Delete an existing item"""
     # url('user_emails_delete', id=ID, method='delete')
     email_id = request.POST.get('del_email_id')
     user_model = UserModel()
     user_model.delete_extra_email(id, email_id)
     Session().commit()
     h.flash(_("Removed email from user"), category='success')
     return redirect(url('edit_user_emails', id=id))
开发者ID:zhumengyuan,项目名称:kallithea,代码行数:9,代码来源:users.py

示例6: delete_ip

    def delete_ip(self, id):
        ip_id = request.POST.get('del_ip_id')
        user_model = UserModel()
        user_model.delete_extra_ip(id, ip_id)
        Session().commit()
        h.flash(_("Removed IP address from user whitelist"), category='success')

        if 'default_user' in request.POST:
            raise HTTPFound(location=url('admin_permissions_ips'))
        raise HTTPFound(location=url('edit_user_ips', id=id))
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:10,代码来源:users.py

示例7: delete_ip

    def delete_ip(self, id):
        """DELETE /user_ips_delete/id: Delete an existing item"""
        # url('user_ips_delete', id=ID, method='delete')
        ip_id = request.POST.get('del_ip_id')
        user_model = UserModel()
        user_model.delete_extra_ip(id, ip_id)
        Session().commit()
        h.flash(_("Removed ip address from user whitelist"), category='success')

        if 'default_user' in request.POST:
            return redirect(url('admin_permissions_ips'))
        return redirect(url('edit_user_ips', id=id))
开发者ID:zhumengyuan,项目名称:kallithea,代码行数:12,代码来源:users.py

示例8: add_email

    def add_email(self, id):
        """POST /user_emails:Add an existing item"""
        # url('user_emails', id=ID, method='put')

        email = request.POST.get('new_email')
        user_model = UserModel()

        try:
            user_model.add_extra_email(id, email)
            Session().commit()
            h.flash(_("Added email %s to user") % email, category='success')
        except formencode.Invalid, error:
            msg = error.error_dict['email']
            h.flash(msg, category='error')
开发者ID:zhumengyuan,项目名称:kallithea,代码行数:14,代码来源:users.py

示例9: create_default_user

 def create_default_user(self):
     log.info('creating default user')
     # create default user for handling default permissions.
     user = UserModel().create_or_update(username=User.DEFAULT_USER,
                                         password=str(uuid.uuid1())[:20],
                                         email='[email protected]',
                                         firstname=u'Anonymous',
                                         lastname=u'User')
     # based on configuration options activate/deactivate this user which
     # controls anonymous access
     if self.cli_args.get('public_access') is False:
         log.info('Public access disabled')
         user.active = False
         Session().commit()
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:14,代码来源:db_manage.py

示例10: add_ip

    def add_ip(self, id):
        """POST /user_ips:Add an existing item"""
        # url('user_ips', id=ID, method='put')

        ip = request.POST.get('new_ip')
        user_model = UserModel()

        try:
            user_model.add_extra_ip(id, ip)
            Session().commit()
            h.flash(_("Added ip %s to user whitelist") % ip, category='success')
        except formencode.Invalid, error:
            msg = error.error_dict['ip']
            h.flash(msg, category='error')
开发者ID:zhumengyuan,项目名称:kallithea,代码行数:14,代码来源:users.py

示例11: add_email

    def add_email(self, id):
        user = self._get_user_or_raise_if_default(id)
        email = request.POST.get('new_email')
        user_model = UserModel()

        try:
            user_model.add_extra_email(id, email)
            Session().commit()
            h.flash(_("Added email %s to user") % email, category='success')
        except formencode.Invalid as error:
            msg = error.error_dict['email']
            h.flash(msg, category='error')
        except Exception:
            log.error(traceback.format_exc())
            h.flash(_('An error occurred during email saving'),
                    category='error')
        raise HTTPFound(location=url('edit_user_emails', id=id))
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:17,代码来源:users.py

示例12: edit_perms

    def edit_perms(self, id):
        c.user = self._get_user_or_raise_if_default(id)
        c.active = 'perms'
        c.perm_user = AuthUser(dbuser=c.user)

        umodel = UserModel()
        defaults = c.user.get_dict()
        defaults.update({
            'create_repo_perm': umodel.has_perm(c.user, 'hg.create.repository'),
            'create_user_group_perm': umodel.has_perm(c.user,
                                                      'hg.usergroup.create.true'),
            'fork_repo_perm': umodel.has_perm(c.user, 'hg.fork.repository'),
        })
        return htmlfill.render(
            render('admin/users/user_edit.html'),
            defaults=defaults,
            encoding="UTF-8",
            force_defaults=False)
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:18,代码来源:users.py

示例13: auto_clear_ip_permissions

def auto_clear_ip_permissions():
    """Fixture that provides nothing but clearing IP permissions upon test
    exit. This clearing is needed to avoid other test failing to make fake http
    accesses."""
    yield
    # cleanup
    user_model = UserModel()

    user_ids = []
    user_ids.append(User.get_default_user().user_id)
    user_ids.append(User.get_by_username(TEST_USER_REGULAR_LOGIN).user_id)

    for user_id in user_ids:
        for ip in UserIpMap.query().filter(UserIpMap.user_id == user_id):
            user_model.delete_extra_ip(user_id, ip.ip_id)

    # IP permissions are cached, need to invalidate this cache explicitly
    invalidate_all_caches()
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:18,代码来源:conftest.py

示例14: add_ip

    def add_ip(self, id):
        ip = request.POST.get('new_ip')
        user_model = UserModel()

        try:
            user_model.add_extra_ip(id, ip)
            Session().commit()
            h.flash(_("Added IP address %s to user whitelist") % ip, category='success')
        except formencode.Invalid as error:
            msg = error.error_dict['ip']
            h.flash(msg, category='error')
        except Exception:
            log.error(traceback.format_exc())
            h.flash(_('An error occurred while adding IP address'),
                    category='error')

        if 'default_user' in request.POST:
            raise HTTPFound(location=url('admin_permissions_ips'))
        raise HTTPFound(location=url('edit_user_ips', id=id))
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:19,代码来源:users.py

示例15: __init__

    def __init__(self, user_id=None, dbuser=None, authenticating_api_key=None,
            is_external_auth=False):

        self.is_authenticated = False
        self.is_external_auth = is_external_auth
        self.authenticating_api_key = authenticating_api_key

        user_model = UserModel()
        self._default_user = User.get_default_user(cache=True)

        # These attributes will be overridden by fill_data, below, unless the
        # requested user cannot be found and the default anonymous user is
        # not enabled.
        self.user_id = None
        self.username = None
        self.api_key = None
        self.name = ''
        self.lastname = ''
        self.email = ''
        self.admin = False
        self.inherit_default_permissions = False

        # Look up database user, if necessary.
        if user_id is not None:
            log.debug('Auth User lookup by USER ID %s', user_id)
            dbuser = user_model.get(user_id)
        else:
            # Note: dbuser is allowed to be None.
            log.debug('Auth User lookup by database user %s', dbuser)

        is_user_loaded = self._fill_data(dbuser)

        # If user cannot be found, try falling back to anonymous.
        if not is_user_loaded:
            is_user_loaded =  self._fill_data(self._default_user)

        self.is_default_user = (self.user_id == self._default_user.user_id)
        self.is_anonymous = not is_user_loaded or self.is_default_user

        if not self.username:
            self.username = 'None'

        log.debug('Auth User is now %s', self)
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:43,代码来源:auth.py


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