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


Python User.by_username方法代码示例

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


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

示例1: dashboard

# 需要导入模块: from notifico.models import User [as 别名]
# 或者: from notifico.models.User import by_username [as 别名]
def dashboard(u):
    """
    Display an overview of all the user's projects with summary
    statistics.
    """
    u = User.by_username(u)
    if not u:
        # No such user exists.
        return abort(404)

    is_owner = (g.user and g.user.id == u.id)

    # Get all projects by decending creation date.
    projects = (
        u.projects
        .order_by(False)
        .order_by(Project.created.desc())
    )
    if not is_owner:
        # If this isn't the users own page, only
        # display public projects.
        projects = projects.filter_by(public=True)

    return render_template('dashboard.html',
        user=u,
        is_owner=is_owner,
        projects=projects,
        page_title='Notifico! - {u.username}\'s Projects'.format(
            u=u
        )
    )
开发者ID:Forkk,项目名称:notifico,代码行数:33,代码来源:__init__.py

示例2: validate_username

# 需要导入模块: from notifico.models import User [as 别名]
# 或者: from notifico.models.User import by_username [as 别名]
    def validate_username(form, field):
        user = User.by_username(field.data)
        if not user:
            raise wtf.ValidationError('No such user exists.')

        if reset.count_tokens(user) >= 5:
            raise wtf.ValidationError(
                'You may not reset your password more than 5 times'
                ' in one day.'
            )
开发者ID:CompanyOnTheWorld,项目名称:notifico,代码行数:12,代码来源:forms.py

示例3: forgot_password

# 需要导入模块: from notifico.models import User [as 别名]
# 或者: from notifico.models.User import by_username [as 别名]
def forgot_password():
    """
    If NOTIFICO_PASSWORD_RESET is enabled and Flask-Mail is configured,
    this view allows you to request a password reset email. It also
    handles accepting those tokens.
    """
    # Because this functionality depends on Flask-Mail and
    # celery being properly configured, we default to disabled.
    if not current_app.config.get('NOTIFICO_PASSWORD_RESET'):
        flash(
            'Password resets have been disabled by the administrator.',
            category='warning'
        )
        return redirect('.login')

    # How long should reset tokens last? We default
    # to 24 hours.
    token_expiry = current_app.config.get(
        'NOTIFICO_PASSWORD_RESET_EXPIRY',
        60 * 60 * 24
    )

    form = UserForgotForm()
    if form.validate_on_submit():
        user = User.by_username(form.username.data)
        new_token = reset.add_token(user, expire=token_expiry)

        # Send the email as a background job so we don't block
        # up the browser (and to use celery's built-in rate
        # limiting).
        background.send_mail.delay(
            'Notifico - Password Reset for {username}'.format(
                username=user.username
            ),
            # We're already using Jinja2, so we might as well use
            # it to render our email templates as well.
            html=render_template(
                'email_reset.html',
                user=user,
                reset_link=url_for(
                    '.reset_password',
                    token=new_token,
                    uid=user.id,
                    _external=True
                ),
                hours=token_expiry / 60 / 60
            ),
            recipients=[user.email],
            sender=current_app.config['NOTIFICO_MAIL_SENDER']
        )
        flash('A reset email has been sent.', category='success')
        return redirect(url_for('.login'))

    return render_template('forgot.html', form=form)
开发者ID:CompanyOnTheWorld,项目名称:notifico,代码行数:56,代码来源:__init__.py

示例4: _wrapped

# 需要导入模块: from notifico.models import User [as 别名]
# 或者: from notifico.models.User import by_username [as 别名]
    def _wrapped(*args, **kwargs):
        u = User.by_username(kwargs.pop('u'))
        if not u:
            # No such user exists.
            return abort(404)

        p = Project.by_name_and_owner(kwargs.pop('p'), u)
        if not p:
            # Project doesn't exist (404 Not Found)
            return abort(404)

        kwargs['p'] = p
        kwargs['u'] = u

        return f(*args, **kwargs)
开发者ID:Forkk,项目名称:notifico,代码行数:17,代码来源:__init__.py

示例5: login

# 需要导入模块: from notifico.models import User [as 别名]
# 或者: from notifico.models.User import by_username [as 别名]
def login():
    """
    Standard login form.
    """
    if g.user:
        return redirect(url_for('public.landing'))

    form = UserLoginForm()
    if form.validate_on_submit():
        u = User.by_username(form.username.data)
        session['_u'] = u.id
        session['_uu'] = u.username
        return redirect(url_for('projects.dashboard', u=u.username))

    return render_template('login.html', form=form)
开发者ID:Forkk,项目名称:notifico,代码行数:17,代码来源:__init__.py

示例6: overview

# 需要导入模块: from notifico.models import User [as 别名]
# 或者: from notifico.models.User import by_username [as 别名]
def overview(u):
    """
    Display an overview of all the user's projects with summary
    statistics.
    """
    u = User.by_username(u)
    if not u:
        # No such user exists.
        return abort(404)

    is_owner = (g.user and g.user.id == u.id)

    return render_template('overview.html',
        user=u,
        is_owner=is_owner
    )
开发者ID:ammaraskar,项目名称:notifico,代码行数:18,代码来源:__init__.py

示例7: login

# 需要导入模块: from notifico.models import User [as 别名]
# 或者: from notifico.models.User import by_username [as 别名]
def login():
    """
    Standard login form.
    """
    if g.user:
        flash('You must logout before logging in.', 'error')
        return redirect(url_for('public.landing'))

    form = UserLoginForm()
    if form.validate_on_submit():
        u = User.by_username(form.username.data)
        session['_u'] = u.id
        session['_uu'] = u.username
        flash('Welcome back!', 'success')
        return redirect(url_for('public.landing'))

    return render_template('login.html', form=form)
开发者ID:ammaraskar,项目名称:notifico,代码行数:19,代码来源:__init__.py

示例8: admin_user

# 需要导入模块: from notifico.models import User [as 别名]
# 或者: from notifico.models.User import by_username [as 别名]
def admin_user(username):
    do = request.args.get('do', None)
    u = User.by_username(username)
    if u is None:
        return abort(404)

    password_form = UserPasswordForm()

    if do == 'p' and password_form.validate_on_submit():
        u.set_password(password_form.password.data)
        g.db.session.commit()
        return redirect(url_for('.admin_user', username=username))

    return render_template(
        'admin_user.html',
        u=u,
        password_form=password_form
    )
开发者ID:Forkk,项目名称:notifico,代码行数:20,代码来源:__init__.py


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