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

Python user_repo.get_by_name函数代码示例

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

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



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

示例1: manage_user

def manage_user(access_token, user_data):
    """Manage the user after signin"""
    # Twitter API does not provide a way
    # to get the e-mail so we will ask for it
    # only the first time
    info = dict(twitter_token=access_token)

    user = user_repo.get_by(twitter_user_id=user_data['user_id'])

    if user is not None:
        user.info['twitter_token'] = access_token
        user_repo.save(user)
        return user

    user = user_repo.get_by_name(user_data['screen_name'])
    if user is not None:
        return None

    user = User(fullname=user_data['screen_name'],
                name=user_data['screen_name'],
                email_addr=user_data['screen_name'],
                twitter_user_id=user_data['user_id'],
                info=info)
    user_repo.save(user)
    return user
开发者ID:influencerplus123,项目名称:tinybee.ai,代码行数:25,代码来源:twitter.py


示例2: manage_user

def manage_user(access_token, user_data):
    """Manage the user after signin"""
    # We have to store the oauth_token in the session to get the USER fields

    user = user_repo.get_by(google_user_id=user_data['id'])

    # user never signed on
    if user is None:
        google_token = dict(oauth_token=access_token)
        info = dict(google_token=google_token)
        name = username_from_full_name(user_data['name'])
        user = user_repo.get_by_name(name)

        email = user_repo.get_by(email_addr=user_data['email'])

        if ((user is None) and (email is None)):
            user = User(fullname=user_data['name'],
                        name=name,
                        email_addr=user_data['email'],
                        google_user_id=user_data['id'],
                        info=info)
            user_repo.save(user)
            if newsletter.is_initialized():
                newsletter.subscribe_user(user)
            return user
        else:
            return None
    else:
        # Update the name to fit with new paradigm to avoid UTF8 problems
        if type(user.name) == unicode or ' ' in user.name:
            user.name = username_from_full_name(user.name)
            user_repo.update(user)
        return user
开发者ID:Skytim,项目名称:pybossa,代码行数:33,代码来源:google.py


示例3: reset_password

def reset_password():
    """
    Reset password method.

    Returns a Jinja2 template.

    """
    key = request.args.get('key')
    if key is None:
        abort(403)
    userdict = {}
    try:
        timeout = current_app.config.get('ACCOUNT_LINK_EXPIRATION', 3600)
        userdict = signer.loads(key, max_age=timeout, salt='password-reset')
    except BadData:
        abort(403)
    username = userdict.get('user')
    if not username or not userdict.get('password'):
        abort(403)
    user = user_repo.get_by_name(username)
    if user.passwd_hash != userdict.get('password'):
        abort(403)
    form = ChangePasswordForm(request.form)
    if form.validate_on_submit():
        user.set_password(form.new_password.data)
        user_repo.update(user)
        flash(gettext('You reset your password successfully!'), 'success')
        return _sign_in_user(user)
    if request.method == 'POST' and not form.validate():
        flash(gettext('Please correct the errors'), 'error')
    return render_template('/account/password_reset.html', form=form)
开发者ID:bluetropic,项目名称:pybossa,代码行数:31,代码来源:account.py


示例4: manage_user

def manage_user(access_token, user_data, next_url):
    """Manage the user after signin"""
    # We have to store the oauth_token in the session to get the USER fields

    user = user_repo.get_by(google_user_id=user_data['id'])

    # user never signed on
    if user is None:
        google_token = dict(oauth_token=access_token)
        info = dict(google_token=google_token)
        name = user_data['name'].encode('ascii', 'ignore').lower().replace(" ", "")
        user = user_repo.get_by_name(name)

        email = user_repo.get_by(email_addr=user_data['email'])

        if ((user is None) and (email is None)):
            user = User(fullname=user_data['name'],
                   name=user_data['name'].encode('ascii', 'ignore')
                                         .lower().replace(" ", ""),
                   email_addr=user_data['email'],
                   google_user_id=user_data['id'],
                   info=info)
            user_repo.save(user)
            return user
        else:
            return None
    else:
        # Update the name to fit with new paradigm to avoid UTF8 problems
        if type(user.name) == unicode or ' ' in user.name:
            user.name = user.name.encode('ascii', 'ignore').lower().replace(" ", "")
            user_repo.update(user)
        return user
开发者ID:chamaa,项目名称:pybossa,代码行数:32,代码来源:google.py


示例5: manage_user_login

def manage_user_login(user, user_data, next_url):
    """Manage user login."""
    if user is None:
        # Give a hint for the user
        user = user_repo.get_by(email_addr=user_data['email'])
        if user is None:
            name = username_from_full_name(user_data['name'])
            user = user_repo.get_by_name(name)

        msg, method = get_user_signup_method(user)
        flash(msg, 'info')
        if method == 'local':
            return redirect(url_for_app_type('account.forgot_password',
                                             _hash_last_flash=True))
        else:
            return redirect(url_for_app_type('account.signin',
                                             _hash_last_flash=True))
    else:
        login_user(user, remember=True)
        flash("Welcome back %s" % user.fullname, 'success')
        if user.newsletter_prompted is False and newsletter.is_initialized():
            return redirect(url_for_app_type('account.newsletter_subscribe',
                                             next=next_url,
                                             _hash_last_flash=True))
        return redirect(next_url)
开发者ID:keyinfluencerplus,项目名称:tinybee.ai,代码行数:25,代码来源:google.py


示例6: manage_user

def manage_user(access_token, user_data, next_url):
    """Manage the user after signin"""
    user = user_repo.get_by(facebook_user_id=user_data['id'])

    if user is None:
        facebook_token = dict(oauth_token=access_token)
        info = dict(facebook_token=facebook_token)
        user = user_repo.get_by_name(user_data['username'])
        # NOTE: Sometimes users at Facebook validate their accounts without
        # registering an e-mail (see this http://stackoverflow.com/a/17809808)
        email = None
        if user_data.get('email'):
            email = user_repo.get_by(email_addr=user_data['email'])

        if user is None and email is None:
            if not user_data.get('email'):
                user_data['email'] = "None"
            user = User(fullname=user_data['name'],
                   name=user_data['username'],
                   email_addr=user_data['email'],
                   facebook_user_id=user_data['id'],
                   info=info)
            user_repo.save(user)
            return user
        else:
            return None
    else:
        return user
开发者ID:chamaa,项目名称:pybossa,代码行数:28,代码来源:facebook.py


示例7: manage_user

def manage_user(access_token, user_data):
    """Manage the user after signin"""
    # Twitter API does not provide a way
    # to get the e-mail so we will ask for it
    # only the first time
    twitter_token = dict(oauth_token=access_token["oauth_token"], oauth_token_secret=access_token["oauth_token_secret"])
    info = dict(twitter_token=twitter_token)

    user = user_repo.get_by(twitter_user_id=user_data["user_id"])

    if user is not None:
        user.info["twitter_token"] = twitter_token
        user_repo.save(user)
        return user

    user = user_repo.get_by_name(user_data["screen_name"])
    if user is not None:
        return None

    user = User(
        fullname=user_data["screen_name"],
        name=user_data["screen_name"],
        email_addr=user_data["screen_name"],
        twitter_user_id=user_data["user_id"],
        info=info,
    )
    user_repo.save(user)
    return user
开发者ID:jshake,项目名称:pybossa,代码行数:28,代码来源:twitter.py


示例8: manage_user

def manage_user(access_token, user_data):
    """Manage the user after signin"""
    user = user_repo.get_by(facebook_user_id=user_data['id'])

    if user is None:
        facebook_token = dict(oauth_token=access_token)
        info = dict(facebook_token=facebook_token)
        name = username_from_full_name(user_data['name'])
        user_exists = user_repo.get_by_name(name) is not None
        # NOTE: Sometimes users at Facebook validate their accounts without
        # registering an e-mail (see this http://stackoverflow.com/a/17809808)
        email_exists = (user_data.get('email') is not None and
                        user_repo.get_by(email_addr=user_data['email']) is not None)

        if not user_exists and not email_exists:
            if not user_data.get('email'):
                user_data['email'] = name
            user = User(fullname=user_data['name'],
                        name=name,
                        email_addr=user_data['email'],
                        facebook_user_id=user_data['id'],
                        info=info)
            user_repo.save(user)
            if newsletter.is_initialized() and user.email_addr != name:
                newsletter.subscribe_user(user)
            return user
        else:
            return None
    else:
        return user
开发者ID:Skytim,项目名称:pybossa,代码行数:30,代码来源:facebook.py


示例9: warm_cache

def warm_cache():  # pragma: no cover
    """Background job to warm cache."""
    from pybossa.core import create_app
    app = create_app(run_as_server=False)
    projects_cached = []
    import pybossa.cache.projects as cached_projects
    import pybossa.cache.categories as cached_cat
    import pybossa.cache.users as cached_users
    import pybossa.cache.project_stats as stats
    from pybossa.util import rank
    from pybossa.core import user_repo

    def warm_project(_id, short_name, featured=False):
        if _id not in projects_cached:
            #cached_projects.get_project(short_name)
            #cached_projects.n_tasks(_id)
            #n_task_runs = cached_projects.n_task_runs(_id)
            #cached_projects.overall_progress(_id)
            #cached_projects.last_activity(_id)
            #cached_projects.n_completed_tasks(_id)
            #cached_projects.n_volunteers(_id)
            #cached_projects.browse_tasks(_id)
            #if n_task_runs >= 1000 or featured:
            #    # print ("Getting stats for %s as it has %s task runs" %
            #    #        (short_name, n_task_runs))
            stats.update_stats(_id, app.config.get('GEO'))
            projects_cached.append(_id)

    # Cache top projects
    projects = cached_projects.get_top()
    for p in projects:
        warm_project(p['id'], p['short_name'])

    # Cache 3 pages
    to_cache = 3 * app.config['APPS_PER_PAGE']
    projects = rank(cached_projects.get_all_featured('featured'))[:to_cache]
    for p in projects:
        warm_project(p['id'], p['short_name'], featured=True)

    # Categories
    categories = cached_cat.get_used()
    for c in categories:
        projects = rank(cached_projects.get_all(c['short_name']))[:to_cache]
        for p in projects:
            warm_project(p['id'], p['short_name'])
    # Users
    users = cached_users.get_leaderboard(app.config['LEADERBOARD'])
    for user in users:
        # print "Getting stats for %s" % user['name']
        print user_repo
        u = user_repo.get_by_name(user['name'])
        cached_users.get_user_summary(user['name'])
        cached_users.projects_contributed_cached(u.id)
        cached_users.published_projects_cached(u.id)
        cached_users.draft_projects_cached(u.id)

    return True
开发者ID:fiorda,项目名称:pybossa,代码行数:57,代码来源:jobs.py


示例10: profile

def profile(name):
    """
    Get user profile.

    Returns a Jinja2 template with the user information.

    """
    user = user_repo.get_by_name(name=name)
    if user is None:
        raise abort(404)
    if current_user.is_anonymous() or (user.id != current_user.id):
        return _show_public_profile(user)
    if current_user.is_authenticated() and user.id == current_user.id:
        return _show_own_profile(user)
开发者ID:bluetropic,项目名称:pybossa,代码行数:14,代码来源:account.py


示例11: confirm_account

def confirm_account():
    """Confirm account endpoint."""
    key = request.args.get('key')
    if key is None:
        abort(403)
    try:
        timeout = current_app.config.get('ACCOUNT_LINK_EXPIRATION', 3600)
        userdict = signer.loads(key, max_age=timeout, salt='account-validation')
    except BadData:
        abort(403)
    # First check if the user exists
    user = user_repo.get_by_name(userdict['name'])
    if user is not None:
        return _update_user_with_valid_email(user, userdict['email_addr'])
    return _create_account(userdict)
开发者ID:bluetropic,项目名称:pybossa,代码行数:15,代码来源:account.py


示例12: oauth_authorized

def oauth_authorized(resp):  # pragma: no cover
    """Called after authorization. After this function finished handling,
    the OAuth information is removed from the session again. When this
    happened, the tokengetter from above is used to retrieve the oauth
    token and secret.

    Because the remote application could have re-authorized the application
    it is necessary to update the values in the database.

    If the application redirected back after denying, the response passed
    to the function will be `None`. Otherwise a dictionary with the values
    the application submitted. Note that Twitter itself does not really
    redirect back unless the user clicks on the application name.
    """
    next_url = request.args.get('next') or url_for('home.home')
    if resp is None:
        flash(u'You denied the request to sign in.', 'error')
        return redirect(next_url)

    access_token = dict(oauth_token=resp['oauth_token'],
                        oauth_token_secret=resp['oauth_token_secret'])

    user_data = dict(screen_name=resp['screen_name'],
                     user_id=resp['user_id'])

    user = manage_user(access_token, user_data, next_url)

    if user is None:
        user = user_repo.get_by_name(user_data['screen_name'])
        msg, method = get_user_signup_method(user)
        flash(msg, 'info')
        if method == 'local':
            return redirect(url_for('account.forgot_password'))
        else:
            return redirect(url_for('account.signin'))

    first_login = False
    login_user(user, remember=True)
    flash("Welcome back %s" % user.fullname, 'success')
    if user.email_addr != user.name:
        return redirect(next_url)
    if first_login:
        flash("This is your first login, please add a valid e-mail")
    else:
        flash("Please update your e-mail address in your profile page")
    return redirect(url_for('account.update_profile', name=user.name))
开发者ID:chamaa,项目名称:pybossa,代码行数:46,代码来源:twitter.py


示例13: reset_api_key

def reset_api_key(name):
    """
    Reset API-KEY for user.

    Returns a Jinja2 template.

    """
    user = user_repo.get_by_name(name)
    if not user:
        return abort(404)
    ensure_authorized_to('update', user)
    user.api_key = model.make_uuid()
    user_repo.update(user)
    cached_users.delete_user_summary(user.name)
    msg = gettext('New API-KEY generated')
    flash(msg, 'success')
    return redirect(url_for('account.profile', name=name))
开发者ID:bluetropic,项目名称:pybossa,代码行数:17,代码来源:account.py


示例14: manage_user_login

def manage_user_login(user, user_data, next_url):
    """Manage user login."""
    if user is None:
        user = user_repo.get_by_name(user_data['screen_name'])
        msg, method = get_user_signup_method(user)
        flash(msg, 'info')
        if method == 'local':
            return redirect(url_for_app_type('account.forgot_password'))
        else:
            return redirect(url_for_app_type('account.signin'))

    login_user(user, remember=True)
    flash("Welcome back %s" % user.fullname, 'success')
    if ((user.email_addr != user.name) and user.newsletter_prompted is False
            and newsletter.is_initialized()):
        return redirect(url_for_app_type('account.newsletter_subscribe',
                                         next=next_url))
    return redirect(next_url)
开发者ID:fiorda,项目名称:pybossa,代码行数:18,代码来源:twitter.py


示例15: delete

def delete(name):
    """
    Delete user account.
    """
    user = user_repo.get_by_name(name)
    if not user:
        return abort(404)
    if current_user.name != name:
        return abort(403)

    super_queue.enqueue(delete_account, user.id)

    if (request.headers.get('Content-Type') == 'application/json' or
        request.args.get('response_format') == 'json'):

        response = dict(job='enqueued', template='account/delete.html')
        return handle_content_type(response)
    else:
        return redirect(url_for('account.signout'))
开发者ID:keyinfluencerplus,项目名称:tinybee.ai,代码行数:19,代码来源:account.py


示例16: start_export

def start_export(name):
    """
    Starts a export of all user data according to EU GDPR

    Data will be available on GET /export after it is processed

    """
    user = user_repo.get_by_name(name)
    if not user:
        return abort(404)
    if user.id != current_user.id:
        return abort(403)

    ensure_authorized_to('update', user)
    export_queue.enqueue(export_userdata,
                         user_id=user.id)
    msg = gettext('GDPR export started')
    flash(msg, 'success')
    return redirect_content_type(url_for('account.profile', name=name))
开发者ID:keyinfluencerplus,项目名称:tinybee.ai,代码行数:19,代码来源:account.py


示例17: oauth_authorized

def oauth_authorized(resp):  # pragma: no cover
    #print "OAUTH authorized method called"
    next_url = url_for('home.home')

    if resp is None or request.args.get('error'):
        flash(u'You denied the request to sign in.', 'error')
        flash(u'Reason: ' + request.args['error'], 'error')
        if request.args.get('error'):
                return redirect(url_for('account.signin'))
        return redirect(next_url)

    headers = {'Authorization': ' '.join(['OAuth', resp['access_token']])}
    url = 'https://www.googleapis.com/oauth2/v1/userinfo'
    try:
        r = requests.get(url, headers=headers)
    except requests.exceptions.http_error:
        # Unauthorized - bad token
        if r.status_code == 401:
            return redirect(url_for('account.signin'))
        return r.content

    access_token = resp['access_token']
    session['oauth_token'] = access_token
    import json
    user_data = json.loads(r.content)
    user = manage_user(access_token, user_data, next_url)
    if user is None:
        # Give a hint for the user
        user = user_repo.get_by(email_addr=user_data['email'])
        if user is None:
            name = user_data['name'].encode('ascii', 'ignore').lower().replace(' ', '')
            user = user_repo.get_by_name(name)

        msg, method = get_user_signup_method(user)
        flash(msg, 'info')
        if method == 'local':
            return redirect(url_for('account.forgot_password'))
        else:
            return redirect(url_for('account.signin'))
    else:
        login_user(user, remember=True)
        flash("Welcome back %s" % user.fullname, 'success')
        return redirect(next_url)
开发者ID:chamaa,项目名称:pybossa,代码行数:43,代码来源:google.py


示例18: reset_api_key

def reset_api_key(name):
    """
    Reset API-KEY for user.

    Returns a Jinja2 template.

    """
    user = user_repo.get_by_name(name)
    if not user:
        return abort(404)
    require.user.update(user)
    title = ("User: %s · Settings"
             "- Reset API KEY") % current_user.fullname
    user.api_key = model.make_uuid()
    user_repo.update(user)
    cached_users.delete_user_summary(user.name)
    msg = gettext('New API-KEY generated')
    flash(msg, 'success')
    return redirect(url_for('account.profile', name=name))
开发者ID:chamaa,项目名称:pybossa,代码行数:19,代码来源:account.py


示例19: projects

def projects(name):
    """
    List user's project list.

    Returns a Jinja2 template with the list of projects of the user.

    """
    user = user_repo.get_by_name(name)
    if not user:
        return abort(404)
    if current_user.name != name:
        return abort(403)

    user = user_repo.get(current_user.id)
    projects_published, projects_draft = _get_user_projects(user.id)

    return render_template('account/projects.html',
                           title=gettext("Projects"),
                           projects_published=projects_published,
                           projects_draft=projects_draft)
开发者ID:bluetropic,项目名称:pybossa,代码行数:20,代码来源:account.py


示例20: manage_user_login

def manage_user_login(user, user_data, next_url):
    """Manage user login."""
    if user is None:
        user = user_repo.get_by_name(user_data["screen_name"])
        msg, method = get_user_signup_method(user)
        flash(msg, "info")
        if method == "local":
            return redirect(url_for("account.forgot_password"))
        else:
            return redirect(url_for("account.signin"))

    login_user(user, remember=True)
    flash("Welcome back %s" % user.fullname, "success")
    if (user.email_addr != user.name) and user.newsletter_prompted is False and newsletter.is_initialized():
        return redirect(url_for("account.newsletter_subscribe", next=next_url))
    if user.email_addr != user.name:
        return redirect(next_url)
    else:
        flash("Please update your e-mail address in your profile page")
        return redirect(url_for("account.update_profile", name=user.name))
开发者ID:jshake,项目名称:pybossa,代码行数:20,代码来源:twitter.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python user_repo.update函数代码示例发布时间:2022-05-25
下一篇:
Python user_repo.get_by函数代码示例发布时间: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