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


Python User.get方法代码示例

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


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

示例1: verify_password_change_token

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def verify_password_change_token(token, max_age=None):
    data, valid = verify_data_token(token, max_age=max_age)
    if valid == Validity.BAD_HASH:
        try:
            data = int(data)
        except:
            return None, Validity.INVALID_FORMAT
        user = User.get(data)
        if not user:
            return None, Validity.DATA_NOT_FOUND
        password = user.password.decode('iso-8859-1') if user.password else 'empty'
        data, valid = verify_data_token(token, password, max_age)
        return user, valid
    # Try decoding legacy
    try:
        id, hash = token.split('e', 1)
        id = int(id)
        user = User.get(id)
        if not user:
            return user, Validity.DATA_NOT_FOUND
        age = datetime.utcnow() - user.last_login
        if age > timedelta(days=3):
            return user, Validity.EXPIRED
        check = str(id) + user.last_login.isoformat()[:19]
        valid = verify_password(
            check, hash, HashEncoding.HEX)
        if not valid:
            return user, Validity.BAD_HASH
        return user, Validity.VALID
    except:
        return None, Validity.INVALID_FORMAT
开发者ID:assembl,项目名称:assembl,代码行数:33,代码来源:password.py

示例2: do_password_change

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def do_password_change(request):
    localizer = request.localizer
    token = request.matchdict.get('ticket')
    (verified, user_id) = verify_password_change_token(token, 24)

    if not verified:
        if not user_id:
            raise HTTPBadRequest(localizer.translate(_(
                "Wrong password token.")))
        else:
            return HTTPFound(location=maybe_contextual_route(
                request, 'password_change_sent', profile_id=user_id, _query=dict(
                    sent=True, error=localizer.translate(_(
                        "This token is expired. "
                        "Do you want us to send another?")))))
    user = User.get(user_id)
    headers = remember(request, user_id)
    request.response.headerlist.extend(headers)
    user.last_login = datetime.utcnow()
    slug = request.matchdict.get('discussion_slug', None)
    slug_prefix = "/" + slug if slug else ""
    return dict(
        get_default_context(request),
        slug_prefix=slug_prefix,
        title=localizer.translate(_('Change your password')))
开发者ID:rmoorman,项目名称:assembl,代码行数:27,代码来源:views.py

示例3: finish_password_change

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def finish_password_change(request):
    logged_in = authenticated_userid(request)
    if not logged_in:
        raise HTTPUnauthorized()
    user = User.get(logged_in)
    localizer = request.localizer
    discussion_slug = request.matchdict.get('discussion_slug', None)
    error = None
    p1, p2 = (request.params.get('password1', '').strip(),
              request.params.get('password2', '').strip())
    if p1 != p2:
        error = localizer.translate(_('The passwords are not identical'))
    elif p1:
        user.password_p = p1
        return HTTPFound(location=request.route_url(
            'home' if discussion_slug else 'discussion_list',
            discussion_slug=discussion_slug,
            _query=dict(
                message=localizer.translate(_(
                    "Password changed")))))

    slug_prefix = "/" + discussion_slug if discussion_slug else ""
    return dict(
        get_default_context(request),
        slug_prefix=slug_prefix, error=error)
开发者ID:rmoorman,项目名称:assembl,代码行数:27,代码来源:views.py

示例4: voting_widget_view

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def voting_widget_view(request):
    user_id = authenticated_userid(request) or Everyone
    ctx = request.context
    view = (request.matchdict or {}).get('view', None)\
        or ctx.get_default_view() or 'default'
    widget = ctx._instance
    permissions = get_permissions(
        user_id, ctx.get_discussion_id())
    json = widget.generic_json(view, user_id, permissions)
    #json['discussion'] = ...
    if user_id != Everyone:
        user = User.get(user_id)
        json['user'] = user.generic_json(view, user_id, permissions)
        json['user_permissions'] = get_permissions(
            user_id, widget.get_discussion_id())
        user_state = widget.get_user_state(user_id)
        if user_state is not None:
            json['user_state'] = user_state
    target_id = request.GET.get('target', None)
    if target_id and Idea.get_database_id(target_id):
        json['user_votes_url'] = widget.get_user_votes_url(target_id)
        json['voting_urls'] = widget.get_voting_urls(target_id)
    json['criteria'] = [idea.generic_json(view, user_id, permissions)
                        for idea in widget.criteria]
    return json
开发者ID:Lornz-,项目名称:assembl,代码行数:27,代码来源:widget.py

示例5: widget_view

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def widget_view(request):
    # IF_OWNED not applicable for widgets... so far
    ctx = request.context
    user_id = authenticated_userid(request) or Everyone
    permissions = get_permissions(
        user_id, ctx.get_discussion_id())
    check_permissions(ctx, user_id, permissions, CrudPermissions.READ)
    view = (request.matchdict or {}).get('view', None)\
        or ctx.get_default_view() or 'default'
    json = ctx._instance.generic_json(view, user_id, permissions)
    # json['discussion'] = ...
    if user_id != Everyone:
        user = User.get(user_id)
        user_state = ctx._instance.get_user_state(user_id)
        json['user'] = user.generic_json(view, user_id, permissions)
        json['user_permissions'] = get_permissions(
            user_id, ctx._instance.get_discussion_id())
        if user_state is not None:
            json['user_state'] = user_state
    target_id = request.GET.get('target', None)
    if target_id:
        idea = Idea.get_instance(target_id)
        if idea:
            json['target'] = idea.generic_json(view, user_id, permissions)
        else:
            return HTTPNotFound("No idea "+target_id)
    return json
开发者ID:Lornz-,项目名称:assembl,代码行数:29,代码来源:widget.py

示例6: request_password_change

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def request_password_change(request):
    localizer = request.localizer
    identifier = request.params.get('identifier') or ''
    user_id = request.params.get('user_id') or ''
    error = request.params.get('error') or ''
    user = None

    if user_id:
        try:
            user = User.get(int(user_id))
            identifier = identifier or user.get_preferred_email() or ''
        except:
            error = error or localizer.translate(_("This user cannot be found"))
    elif identifier:
        user, account = from_identifier(identifier)
        if user:
            user_id = user.id
        else:
            error = error or localizer.translate(_("This user cannot be found"))
    if error or not user:
        context = get_default_context(request)
        get_route = context['get_route']
        request.session.flash(error)
        return HTTPFound(location=get_route('react_request_password_change'))

    discussion_slug = request.matchdict.get('discussion_slug', None)
    route = 'password_change_sent'
    if discussion_slug:
        route = 'contextual_' + route
    return HTTPFound(location=maybe_contextual_route(
        request, 'password_change_sent', profile_id=user_id,
        _query=dict(email=identifier if '@' in identifier else '')))
开发者ID:assembl,项目名称:assembl,代码行数:34,代码来源:views.py

示例7: discussion_list_view

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def discussion_list_view(request):
    user_id = authenticated_userid(request) or Everyone
    user = None
    if user_id != Everyone:
        user = User.get(user_id)
    roles = get_roles(user_id)
    context = get_default_context(request)
    context['discussions'] = []
    #Show even anonymous users every discussion one has access to if 
    #authenticated, so they can login and read them
    discussions = discussions_with_access(Authenticated if user_id == Everyone else user_id)
    for discussion in discussions:
        discussionFrontendUrls = FrontendUrls(discussion)
        discussion_context = {
            'topic': discussion.topic,
            'slug': discussion.slug,
            'url': discussionFrontendUrls.get_discussion_url()
        }
        if user_has_permission(discussion.id, user_id, P_ADMIN_DISC):
            discussion_context['admin_url'] = discussionFrontendUrls.get_discussion_edition_url()
            discussion_context['permissions_url'] = request.route_url(
                'discussion_permissions', discussion_id=discussion.id)
        context['discussions'].append(discussion_context)
    if R_SYSADMIN in roles:
        context['discussions_admin_url'] = request.route_url('discussion_admin')
        context['permissions_admin_url'] = request.route_url('general_permissions')
    context['user'] = user
    return context
开发者ID:hypnotics,项目名称:assembl,代码行数:30,代码来源:views.py

示例8: maybe_merge

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def maybe_merge(
        backend, details, user=None, other_users=None,
        *args, **kwargs):
    # If we do not already have a user, see if we're in a situation
    # where we're adding an account to an existing user, and maybe
    # even merging
    request = backend.strategy.request
    adding_account = request.session.get("add_account", None)
    if adding_account is not None:
        del request.session["add_account"]
    # current discussion and next?
    logged_in = request.authenticated_userid
    if logged_in:
        logged_in = User.get(logged_in)
        if adding_account:
            if user and user != logged_in:
                # logged_in presumably newer?
                logged_in.merge(user)
                logged_in.db.delete(user)
                logged_in.db.flush()
            user = logged_in
        else:
            forget(request)
    if other_users:
        if not user:
            user = other_users.pop(0)
        # Merge other accounts with same verified email
        for profile in other_users:
            user.merge(profile)
            profile.delete()
    return {"user": user}
开发者ID:assembl,项目名称:assembl,代码行数:33,代码来源:social_auth.py

示例9: discussion_list_view

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def discussion_list_view(request):
    user_id = authenticated_userid(request) or Everyone
    user = None
    if user_id != Everyone:
        user = User.get(id=user_id)
    context = get_default_context()
    context['discussions'] = discussions_with_access(user_id)
    context['user'] = user
    return context
开发者ID:hellsingblack,项目名称:assembl,代码行数:11,代码来源:views.py

示例10: add_local_role

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def add_local_role(request):
    # Do not use check_permissions, this is a special case
    ctx = request.context
    user_id = request.authenticated_userid
    if not user_id:
        raise HTTPUnauthorized()
    discussion_id = ctx.get_discussion_id()
    discussion = Discussion.get(discussion_id)
    user_uri = User.uri_generic(user_id)
    if discussion_id is None:
        raise HTTPBadRequest()
    permissions = get_permissions(user_id, discussion_id)
    json = request.json_body
    if "discussion" not in json:
        json["discussion"] = Discussion.uri_generic(discussion_id)
    requested_user = json.get('user', None)
    if not requested_user:
        json['user'] = requested_user = user_uri
    elif requested_user != user_uri and P_ADMIN_DISC not in permissions:
        raise HTTPUnauthorized()
    if P_ADMIN_DISC not in permissions:
        if P_SELF_REGISTER in permissions:
            json['requested'] = False
            json['role'] = R_PARTICIPANT
            req_user = User.get_instance(requested_user)
            if not discussion.check_authorized_email(req_user):
                raise HTTPForbidden()
        elif P_SELF_REGISTER_REQUEST in permissions:
            json['requested'] = True
        else:
            raise HTTPUnauthorized()
    try:
        instances = ctx.create_object("LocalUserRole", json, user_id)
    except HTTPClientError as e:
        raise e
    except Exception as e:
        raise HTTPBadRequest(e)
    if instances:
        first = instances[0]
        db = first.db
        for instance in instances:
            db.add(instance)
        db.flush()
        # Side effect: materialize subscriptions.
        if not first.requested:
            # relationship may not be initialized
            user = first.user or User.get(first.user_id)
            user.get_notification_subscriptions(discussion_id, True)

        # Update the user's AgentStatusInDiscussion
        user.update_agent_status_subscribe(discussion)

        view = request.GET.get('view', None) or 'default'
        permissions = get_permissions(
            user_id, ctx.get_discussion_id())
        return CreationResponse(first, user_id, permissions, view)
开发者ID:assembl,项目名称:assembl,代码行数:58,代码来源:auth.py

示例11: add_local_role

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def add_local_role(request):
    # Do not use check_permissions, this is a special case
    ctx = request.context
    user_id = authenticated_userid(request)
    if user_id == Everyone:
        raise HTTPUnauthorized()
    discussion_id = ctx.get_discussion_id()
    user_uri = User.uri_generic(user_id)
    if discussion_id is None:
        raise HTTPBadRequest()
    permissions = get_permissions(user_id, discussion_id)
    json = request.json_body
    if "discussion" not in json:
        json["discussion"] = Discussion.uri_generic(discussion_id)
    requested_user = json.get('user', None)
    if not requested_user:
        json['user'] = requested_user = user_uri
    elif requested_user != user_uri and P_ADMIN_DISC not in permissions:
        raise HTTPUnauthorized()
    if P_ADMIN_DISC not in permissions:
        if P_SELF_REGISTER in permissions:
            json['requested'] = False
            json['role'] = R_PARTICIPANT
        elif P_SELF_REGISTER_REQUEST in permissions:
            json['requested'] = True
        else:
            raise HTTPUnauthorized()
    try:
        instances = ctx.create_object("LocalUserRole", json, user_id)
    except HTTPClientError as e:
        raise e
    except Exception as e:
        raise HTTPBadRequest(e)
    if instances:
        first = instances[0]
        db = first.db()
        for instance in instances:
            db.add(instance)
        db.flush()
        # Side effect: materialize subscriptions.
        if not first.requested:
            # relationship may not be initialized
            user = first.user or User.get(first.user_id)
            user.get_notification_subscriptions(discussion_id, True)
        view = request.GET.get('view', None) or 'default'
        permissions = get_permissions(
            user_id, ctx.get_discussion_id())
        return Response(
            dumps(first.generic_json(view, user_id, permissions)),
            location=first.uri_generic(first.id),
            status_code=201)
开发者ID:hypnotics,项目名称:assembl,代码行数:53,代码来源:auth.py

示例12: delete_local_role

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def delete_local_role(request):
    ctx = request.context
    instance = ctx._instance
    user_id = request.authenticated_userid
    if not user_id:
        raise HTTPUnauthorized()
    discussion_id = ctx.get_discussion_id()

    if discussion_id is None:
        raise HTTPBadRequest()
    permissions = get_permissions(user_id, discussion_id)
    requested_user = instance.user
    if requested_user.id != user_id and P_ADMIN_DISC not in permissions:
        raise HTTPUnauthorized()

    user = User.get(user_id)
    discussion = Discussion.get(discussion_id)
    instance.db.delete(instance)
    # Update the user's AgentStatusInDiscussion
    user.update_agent_status_unsubscribe(discussion)
    instance.db.flush()  # maybe unnecessary
    return {}
开发者ID:assembl,项目名称:assembl,代码行数:24,代码来源:auth.py

示例13: set_local_role

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def set_local_role(request):
    # Do not use check_permissions, this is a special case
    ctx = request.context
    instance = ctx._instance
    user_id = request.authenticated_userid
    if not user_id:
        raise HTTPUnauthorized()
    discussion_id = ctx.get_discussion_id()
    user_uri = User.uri_generic(user_id)
    if discussion_id is None:
        raise HTTPBadRequest()
    permissions = get_permissions(user_id, discussion_id)
    json = request.json_body
    requested_user = json.get('user', None)
    if not requested_user:
        json['user'] = requested_user = user_uri
    elif requested_user != user_uri and P_ADMIN_DISC not in permissions:
        raise HTTPUnauthorized()
    if P_ADMIN_DISC not in permissions:
        if P_SELF_REGISTER in permissions:
            json['requested'] = False
            json['role'] = R_PARTICIPANT
        elif P_SELF_REGISTER_REQUEST in permissions:
            json['requested'] = True
        else:
            raise HTTPUnauthorized()
    updated = instance.update_from_json(json, user_id, ctx)
    view = request.GET.get('view', None) or 'default'

    # Update the user's AgentStatusInDiscussion
    user = User.get(user_id)
    discussion = Discussion.get(discussion_id)
    user.update_agent_status_subscribe(discussion)

    if view == 'id_only':
        return [updated.uri()]
    else:
        return updated.generic_json(view, user_id, permissions)
开发者ID:assembl,项目名称:assembl,代码行数:40,代码来源:auth.py

示例14: maybe_social_logout

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def maybe_social_logout(request):
    """If the user has a an account with the default social provider,
    and that account has a logout URL, redirect there.
    Maybe the next argument should be carried?"""
    discussion = discussion_from_request(request)
    if not discussion:
        return
    backend_name = discussion.preferences['authorization_server_backend']
    if not backend_name:
        return
    user_id = request.authenticated_userid
    if not user_id:
        return
    user = User.get(user_id)
    for account in user.accounts:
        if getattr(account, 'provider_with_idp', None) == backend_name:
            break
    else:
        return
    # TODO: tell the account that the login has expired.
    # Also check if already expired?
    return config.get('SOCIAL_AUTH_%s_LOGOUT_URL' % (
        account.provider.upper(),))
开发者ID:assembl,项目名称:assembl,代码行数:25,代码来源:social_auth.py

示例15: request_password_change

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import get [as 别名]
def request_password_change(request):
    localizer = request.localizer
    identifier = request.params.get('identifier') or ''
    user_id = request.params.get('user_id') or ''
    error = request.params.get('error') or ''
    user = None
    if user_id:
        try:
            user = User.get(int(user_id))
            identifier = identifier or user.get_preferred_email() or ''
        except:
            error = error or localizer.translate(_("This user cannot be found"))
    elif identifier:
        user, account = from_identifier(identifier)
        if user:
            user_id = user.id
        else:
            error = error or localizer.translate(_("This user cannot be found"))
    if error or not user:
        slug = request.matchdict.get('discussion_slug', None)

        return dict(
            get_default_context(request),
            error=error,
            user_id=user_id,
            identifier=identifier,
            slug_prefix="/" + slug if slug else "",
            title=localizer.translate(_('I forgot my password')))

    discussion_slug = request.matchdict.get('discussion_slug', None)
    route = 'password_change_sent'
    if discussion_slug:
        route = 'contextual_' + route
    return HTTPFound(location=maybe_contextual_route(
        request, 'password_change_sent', profile_id=user_id,
        _query=dict(email=identifier if '@' in identifier else '')))
开发者ID:festrade,项目名称:assembl,代码行数:38,代码来源:views.py


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