本文整理汇总了Python中notifico.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dashboard
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
)
)
示例2: validate_username
def validate_username(form, field):
from notifico.views.account import _reserved
username = field.data.strip().lower()
if username in _reserved or User.username_exists(username):
raise wtf.ValidationError(
'Sorry, but that username is taken.'
)
示例3: forgot_password
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)
示例4: _wrapped
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)
示例5: login
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)
示例6: overview
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
)
示例7: login
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)
示例8: admin_user
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
)
示例9: register
def register():
"""
If new user registrations are enabled, provides a registration form
and validation.
"""
if g.user:
return redirect(url_for('public.landing'))
# Make sure this instance is allowing new users.
if not current_app.config.get('PUBLIC_NEW_USERS', True):
return redirect(url_for('public.landing'))
form = UserRegisterForm()
if form.validate_on_submit():
# Checks out, go ahead and create our new user.
u = User.new(form.username.data, form.email.data, form.password.data)
g.db.session.add(u)
g.db.session.commit()
# ... and send them back to the login screen.
return redirect(url_for('.login'))
return render_template('register.html', form=form)
示例10: validate_password
def validate_password(form, field):
if not User.login(g.user.username, field.data):
raise wtf.ValidationError('Password is incorrect.')
示例11: validate_username
def validate_username(form, field):
username = field.data.strip().lower()
if username in _reserved or User.username_exists(username):
raise wtf.ValidationError(
'Sorry, but that username is taken.'
)