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


Python models.User类代码示例

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


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

示例1: register_internal

def register_internal(username, fullname, password):
    user = User(username=username, fullname=fullname, password=password)
    if not username:
        user.username = None
    db.session.add(user)
    user_registered.send(user)
    return user
开发者ID:finiterecursion,项目名称:lastuser,代码行数:7,代码来源:helpers.py

示例2: register_internal

def register_internal(username, fullname, password):
    user = User(username=username, fullname=fullname, password=password)
    if not username:
        user.username = None
    if user.username:
        # We can only use failsafe_add when a unique identifier like username is present
        user = failsafe_add(db.session, user, username=user.username)
    else:
        db.session.add(user)
    user_registered.send(user)
    return user
开发者ID:sindhus,项目名称:lastuser,代码行数:11,代码来源:helpers.py

示例3: user_get_by_userids

def user_get_by_userids(userid):
    """
    Returns users and organizations with the given userids (Lastuser internal userid).
    This is identical to get_by_userid but accepts multiple userids and returns a list
    of matching users and organizations
    """
    if not userid:
        return api_result('error', error='no_userid_provided')
    users = User.all(userids=userid)
    orgs = Organization.all(userids=userid)
    return api_result('ok',
        results=[
            {'type': 'user',
             'buid': u.userid,
             'userid': u.userid,
             'name': u.username,
             'title': u.fullname,
             'label': u.pickername,
             'timezone': u.timezone,
             'oldids': [o.userid for o in u.oldids]} for u in users] + [
            {'type': 'organization',
             'buid': o.userid,
             'userid': o.userid,
             'name': o.name,
             'title': o.fullname,
             'label': o.pickername} for o in orgs]
        )
开发者ID:gonrin,项目名称:lastuser,代码行数:27,代码来源:resource.py

示例4: lookup_current_user

def lookup_current_user():
    """
    If there's a userid in the session, retrieve the user object and add
    to the request namespace object g.
    """
    g.user = None
    g.usersession = None

    if 'sessionid' in session:
        usersession = UserSession.authenticate(buid=session['sessionid'])
        g.usersession = usersession
        if usersession:
            usersession.access()
            db.session.commit()  # Save access
            g.user = usersession.user
        else:
            session.pop('sessionid', None)

    # Transition users with 'userid' to 'sessionid'
    if 'userid' in session:
        if not g.usersession:
            user = User.get(userid=session['userid'])
            if user:
                usersession = UserSession(user=user)
                usersession.access()
                db.session.commit()  # Save access
                g.usersession = usersession
                g.user = user
                session['sessionid'] = usersession.buid
        session.pop('userid', None)

    # This will be set to True downstream by the requires_login decorator
    g.login_required = False
开发者ID:finiterecursion,项目名称:lastuser,代码行数:33,代码来源:helpers.py

示例5: user_get_by_userid

def user_get_by_userid():
    """
    Returns user or organization with the given userid (Lastuser internal userid)
    """
    userid = request.values.get('userid')
    if not userid:
        return api_result('error', error='no_userid_provided')
    user = User.get(userid=userid, defercols=True)
    if user:
        return api_result('ok',
            type='user',
            userid=user.userid,
            buid=user.userid,
            name=user.username,
            title=user.fullname,
            label=user.pickername,
            timezone=user.timezone,
            oldids=[o.userid for o in user.oldids])
    else:
        org = Organization.get(userid=userid, defercols=True)
        if org:
            return api_result('ok',
                type='organization',
                userid=org.userid,
                buid=org.userid,
                name=org.name,
                title=org.title,
                label=org.pickername)
    return api_result('error', error='not_found')
开发者ID:gonrin,项目名称:lastuser,代码行数:29,代码来源:resource.py

示例6: lookup_current_user

def lookup_current_user():
    """
    If there's a userid in the session, retrieve the user object and add
    to the request namespace object g.
    """
    g.user = None
    if "userid" in session:
        g.user = User.get(userid=session["userid"])
开发者ID:pombredanne,项目名称:lastuser,代码行数:8,代码来源:helpers.py

示例7: validate_username

 def validate_username(self, field):
     if field.data in current_app.config['RESERVED_USERNAMES']:
         raise wtforms.ValidationError, "That name is reserved"
     if not valid_username(field.data):
         raise wtforms.ValidationError(u"Invalid characters in name. Names must be made of ‘a-z’, ‘0-9’ and ‘-’, without trailing dashes")
     existing = User.get(username=field.data)
     if existing is not None:
         raise wtforms.ValidationError("That username is taken")
开发者ID:HashResearch,项目名称:lastuser,代码行数:8,代码来源:login.py

示例8: validate_name

 def validate_name(self, field):
     if not valid_username(field.data):
         raise wtforms.ValidationError("Invalid characters in name")
     if field.data in current_app.config['RESERVED_USERNAMES']:
         raise wtforms.ValidationError("That name is reserved")
     existing = User.get(username=field.data)
     if existing is not None:
         raise wtforms.ValidationError("That name is taken")
     existing = Organization.get(name=field.data)
     if existing is not None and existing.id != self.edit_id:
         raise wtforms.ValidationError("That name is taken")
开发者ID:HashResearch,项目名称:lastuser,代码行数:11,代码来源:org.py

示例9: lookup_current_user

def lookup_current_user():
    """
    If there's a userid in the session, retrieve the user object and add
    to the request namespace object g.
    """
    g.user = None
    g.usersession = None

    lastuser_cookie = {}
    lastuser_cookie_headers = {}  # Ignored for now, intended for future changes

    # Migrate data from Flask cookie session
    if 'sessionid' in session:
        lastuser_cookie['sessionid'] = session.pop('sessionid')
    if 'userid' in session:
        lastuser_cookie['userid'] = session.pop('userid')

    if 'lastuser' in request.cookies:
        try:
            lastuser_cookie, lastuser_cookie_headers = lastuser_oauth.serializer.loads(
                request.cookies['lastuser'], return_header=True)
        except itsdangerous.BadSignature:
            lastuser_cookie = {}

    if 'sessionid' in lastuser_cookie:
        g.usersession = UserSession.authenticate(buid=lastuser_cookie['sessionid'])
        if g.usersession:
            g.usersession.access()
            db.session.commit()  # Save access
            g.user = g.usersession.user

    # Transition users with 'userid' to 'sessionid'
    if not g.usersession and 'userid' in lastuser_cookie:
        g.user = User.get(userid=lastuser_cookie['userid'])
        if g.user:
            g.usersession = UserSession(user=g.user)
            g.usersession.access()
            db.session.commit()  # Save access

    if g.usersession:
        lastuser_cookie['sessionid'] = g.usersession.buid
    else:
        lastuser_cookie.pop('sessionid', None)
    if g.user:
        lastuser_cookie['userid'] = g.user.userid
    else:
        lastuser_cookie.pop('userid', None)

    g.lastuser_cookie = lastuser_cookie
    # This will be set to True downstream by the requires_login decorator
    g.login_required = False
开发者ID:sindhus,项目名称:lastuser,代码行数:51,代码来源:helpers.py

示例10: _load_user

    def _load_user(self):
        """
        If there's a buid in the session, retrieve the user object and add
        to the request namespace object g.
        """
        add_auth_attribute('user', None)
        add_auth_attribute('session', None)

        lastuser_cookie = {}
        lastuser_cookie_headers = {}  # Ignored for now, intended for future changes

        # Migrate data from Flask cookie session
        if 'sessionid' in session:
            lastuser_cookie['sessionid'] = session.pop('sessionid')
        if 'userid' in session:
            lastuser_cookie['userid'] = session.pop('userid')

        if 'lastuser' in request.cookies:
            try:
                lastuser_cookie, lastuser_cookie_headers = lastuser_oauth.serializer.loads(
                    request.cookies['lastuser'], return_header=True)
            except itsdangerous.BadSignature:
                lastuser_cookie = {}

        if 'sessionid' in lastuser_cookie:
            add_auth_attribute('session', UserSession.authenticate(buid=lastuser_cookie['sessionid']))
            if current_auth.session:
                current_auth.session.access()
                db.session.commit()  # Save access
                add_auth_attribute('user', current_auth.session.user)

        # Transition users with 'userid' to 'sessionid'
        if not current_auth.session and 'userid' in lastuser_cookie:
            add_auth_attribute('user', User.get(buid=lastuser_cookie['userid']))
            if current_auth.is_authenticated:
                add_auth_attribute('session', UserSession(user=current_auth.user))
                current_auth.session.access()
                db.session.commit()  # Save access

        if current_auth.session:
            lastuser_cookie['sessionid'] = current_auth.session.buid
        else:
            lastuser_cookie.pop('sessionid', None)
        if current_auth.is_authenticated:
            lastuser_cookie['userid'] = current_auth.user.buid
        else:
            lastuser_cookie.pop('userid', None)

        add_auth_attribute('cookie', lastuser_cookie)
        # This will be set to True downstream by the requires_login decorator
        add_auth_attribute('login_required', False)
开发者ID:hasgeek,项目名称:lastuser,代码行数:51,代码来源:helpers.py

示例11: user_autocomplete

def user_autocomplete():
    """
    Returns users (userid, username, fullname, twitter, github or email) matching the search term.
    """
    q = request.values.get('q', '')
    if not q:
        return api_result('error', error='no_query_provided')
    users = User.autocomplete(q)
    result = [{
        'userid': u.userid,
        'buid': u.userid,
        'name': u.username,
        'title': u.fullname,
        'label': u.pickername} for u in users]
    return api_result('ok', users=result)
开发者ID:gonrin,项目名称:lastuser,代码行数:15,代码来源:resource.py

示例12: validate_name

 def validate_name(self, field):
     if not valid_username(field.data):
         raise forms.ValidationError(_("Invalid characters in name"))
     if field.data in current_app.config['RESERVED_USERNAMES']:
         raise forms.ValidationError(_("This name is reserved"))
     existing = User.get(username=field.data)
     if existing is not None:
         if existing == current_auth.user:
             raise forms.ValidationError(Markup(_(u"This is <em>your</em> current username. "
                 u'You must change it first from <a href="{profile}">your profile</a> '
                 u"before you can assign it to an organization").format(
                     profile=url_for('profile'))))
         else:
             raise forms.ValidationError(_("This name is taken"))
     existing = Organization.get(name=field.data)
     if existing is not None and existing.id != self.edit_id:
         raise forms.ValidationError(_("This name is taken"))
开发者ID:bugrevelio,项目名称:lastuser,代码行数:17,代码来源:org.py

示例13: permission_user_delete

def permission_user_delete(client, kwargs):
    if client.user:
        user = User.get(userid=kwargs['userid'])
        if not user:
            abort(404)
        permassign = UserClientPermissions.query.filter_by(user=user, client=client).first_or_404()
        return render_delete_sqla(permassign, db, title=u"Confirm delete", message=u"Remove all permissions assigned to user {pname} for app ‘{title}’?".format(
                pname=user.pickername, title=client.title),
            success=u"You have revoked permisions for user {pname}".format(pname=user.pickername),
            next=url_for('.client_info', key=client.key))
    else:
        team = Team.get(userid=kwargs['userid'])
        if not team:
            abort(404)
        permassign = TeamClientPermissions.query.filter_by(team=team, client=client).first_or_404()
        return render_delete_sqla(permassign, db, title=u"Confirm delete", message=u"Remove all permissions assigned to team ‘{pname}’ for app ‘{title}’?".format(
                pname=team.title, title=client.title),
            success=u"You have revoked permisions for team {title}".format(title=team.title),
            next=url_for('.client_info', key=client.key))
开发者ID:finiterecursion,项目名称:lastuser,代码行数:19,代码来源:client.py

示例14: permission_user_edit

def permission_user_edit(client, kwargs):
    if client.user:
        user = User.get(userid=kwargs['userid'])
        if not user:
            abort(404)
        available_perms = Permission.query.filter(db.or_(
            Permission.allusers == True,
            Permission.user == g.user)).order_by('name').all()
        permassign = UserClientPermissions.query.filter_by(user=user, client=client).first_or_404()
    elif client.org:
        team = Team.get(userid=kwargs['userid'])
        if not team:
            abort(404)
        available_perms = Permission.query.filter(db.or_(
            Permission.allusers == True,
            Permission.org == client.org)).order_by('name').all()
        permassign = TeamClientPermissions.query.filter_by(team=team, client=client).first_or_404()
    form = PermissionEditForm()
    form.perms.choices = [(ap.name, u"{name} – {title}".format(name=ap.name, title=ap.title)) for ap in available_perms]
    if request.method == 'GET':
        if permassign:
            form.perms.data = permassign.access_permissions.split(u' ')
    if form.validate_on_submit():
        form.perms.data.sort()
        perms = u' '.join(form.perms.data)
        if not perms:
            db.session.delete(permassign)
        else:
            permassign.access_permissions = perms
        db.session.commit()
        if perms:
            if client.user:
                flash(u"Permissions have been updated for user {pname}".format(pname=user.pickername), 'success')
            else:
                flash(u"Permissions have been updated for team {title}".format(title=team.title), 'success')
        else:
            if client.user:
                flash(u"All permissions have been revoked for user {pname}".format(pname=user.pickername), 'success')
            else:
                flash(u"All permissions have been revoked for team {title}".format(title=team.title), 'success')
        return render_redirect(url_for('.client_info', key=client.key), code=303)
    return render_form(form=form, title="Edit permissions", formid="perm_edit", submit="Save changes", ajax=True)
开发者ID:finiterecursion,项目名称:lastuser,代码行数:42,代码来源:client.py

示例15: profile_merge

def profile_merge():
    if "merge_userid" not in session:
        return redirect(get_next_url(), code=302)
    other_user = User.get(userid=session["merge_userid"])
    if other_user is None:
        session.pop("merge_userid", None)
        return redirect(get_next_url(), code=302)
    form = ProfileMergeForm()
    if form.validate_on_submit():
        if "merge" in request.form:
            new_user = merge_users(g.user, other_user)
            login_internal(new_user)
            user_data_changed.send(new_user, changes=["merge"])
            flash(_("Your accounts have been merged"), "success")
            session.pop("merge_userid", None)
            db.session.commit()
            return redirect(get_next_url(), code=303)
        else:
            session.pop("merge_userid", None)
            return redirect(get_next_url(), code=303)
    return render_template("merge.html", form=form, user=g.user, other_user=other_user, login_registry=login_registry)
开发者ID:gonrin,项目名称:lastuser,代码行数:21,代码来源:account.py


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