本文整理汇总了Python中models.User.get_by_username方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_username方法的具体用法?Python User.get_by_username怎么用?Python User.get_by_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.get_by_username方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def get(self):
username = self.request.get('username')
user = User.get_by_username(username)
if user is not None:
userdict = {
'key': user.key.urlsafe(),
'username': user.username,
'email': user.email,
'first_name': user.first_name,
'last_name': user.last_name,
'permissions': json.loads(user.permissions),
'active': user.active,
'notes': user.notes,
'created': tools.datetime_to_str(user.created),
'organization_creation_allowed': True,
}
message = 'Detalles de usuario encontrados.'
status = 0
else:
userdict = {}
message = 'Detalles de usuario no encontrados.'
status = 1
self.response.headers['Content-Type'] = 'application/json'
self.response.write(json.dumps({'status': status, 'message': message, 'user': userdict}))
示例2: get_editors
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def get_editors():
editors = request.form.getlist('editors')
if editors:
users = User.get_by_username(editors)
return users
return []
示例3: login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.get_by_username(form.username.data)
login_user(user, form.remember_me.data)
flash("Logged in Successfully as {}.".format(user.username))
return redirect(request.args.get('next') or url_for('user', username=user.username))
return render_template('login.html', form=form)
示例4: authenticate
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def authenticate(self, username, password):
try:
user = User.get_by_username(username)
if user.check_password(password):
return user
else:
return None
except User.DoesNotExist:
return None
示例5: login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.get_by_username(form.username.data)
if user is not None and user.check_password(form.password.data):
login_user(user, form.remember_me.data)
flash("Logged in successfully as {}.".format(user.username))
return redirect(request.args.get('next') or url_for('user', username=user.username))
flash('Incorrect username or password.')
return render_template("login.html", form=form)
示例6: reset_init
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def reset_init():
if request.method == 'POST':
user = User.get_by_username(request.form['username'])
if user:
# add to session to begin the reset flow
session['reset_id'] = user.id
return redirect(url_for('reset_question'))
else:
flash('User not recognized.')
return render_template('reset_init.html')
示例7: login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.get_by_username(form.username.data)
if user is not None:
login_user(user, form.remember_me.data)
flash("Welcome Back %s" % user.username)
return redirect(request.args.get('next') or url_for('user',username=user.username))
flash("Incorrect username or password")
return render_template("login.html",form=form)
示例8: login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.get_by_username(form.username.data)
if user is not None and user.check_password(form.password.data):
login_user(user, form.remember_me.data)
return redirect(request.args.get('next') or url_for('user', username=user.username))
else:
flash("Generous Monkey banging QWERTY! OR maybe a bruteforce attempt!")
return render_template("login.html", form = form)
示例9: login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def login():
# logic for login
# confirms username & password combination is in DB before granting access to the rest of the application
form = LoginForm()
if form.validate_on_submit():
username = request.form['username']
password = request.form['password']
user = User.get_by_username(username)
if user is not None:
if user.password == password:
login_user(user)
return redirect(request.args.get("next") or url_for('index'))
else:
flash('Incorrect Username/Password Combination')
return render_template('login.html', form=form)
示例10: login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.get_by_username(form.username.data)
if not user:
flash('That didn\'t work :(. Never seen you before.')
return render_template('login.html', form=form)
if user.check_password(form.password.data, request) == False:
flash('That didn\'t work :(. Check yo self.')
return render_template('login.html', form=form)
login_user(user)
flash("Logged in successfully.")
return redirect(request.args.get("next") or url_for("home"))
return render_template("login.html", form=form)
示例11: cadastrar
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def cadastrar(_handler, _resp, name, username, email, passwd):
errors = []
if User.get_by_username(username):
errors.append('username_error')
if "@" not in email or "." not in email:
errors.append('invalid_email')
if len(passwd) < 6:
errors.append('invalid_pw')
if errors:
url = router.to_path(site_index) + "?errors=" + "+".join(errors)
_handler.redirect(url)
return
u = User(name=name, username=username.strip(), email=email, passwd=passwd)
u.put()
#to avoid eventually consistency
time.sleep(0.5)
logar(_handler, _resp, username, passwd)
示例12: get_editors
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def get_editors():
editors = request.form.get('editors', '').split(',')
return User.get_by_username(editors)
示例13: initialize
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def initialize(self, *a, **kw):
webapp2.RequestHandler.initialize(self, *a, **kw)
username = self.read_cookie('username')
if username and len(username) == 0:
username = None
self.user = username and User.get_by_username(username)
示例14: leader
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by_username [as 别名]
def leader(self):
return User.get_by_username(self.activity.owner)