本文整理汇总了Python中models.user.User.authenticate方法的典型用法代码示例。如果您正苦于以下问题:Python User.authenticate方法的具体用法?Python User.authenticate怎么用?Python User.authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.authenticate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_internal
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import authenticate [as 别名]
def create_internal(self, user, password):
user_id = User.create(user, password)
assert User.authenticate(user_id, password)
assert not User.authenticate(user_id, "otherpassword")
assert not User.authenticate(user_id, user)
recreated_user = User(user_id)
assert_equals(user_id, recreated_user.user_id)
assert_equals(user, recreated_user.name)
示例2: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import authenticate [as 别名]
def post(self, *args, **kwargs):
name = self.get_argument("name", None)
pwd = self.get_argument("pwd", None)
user_doc = User.authenticate(name, pwd)
if user_doc:
self.write(self.make_result(1, "login OK", user_doc))
else:
self.write(self.make_result(0, "user not found or wrong password", None))
示例3: login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import authenticate [as 别名]
def login(email, password):
user = User.authenticate(email, password)
if user:
session['user_id'] = str(user.id)
return { 'is_accepted': True,
'message':'User accepted'}
else:
return {'is_accepted':False,
'message': 'Wrong email and password'}
示例4: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import authenticate [as 别名]
def post(self):
email = self.get_argument('email', '')
password = self.get_argument('password', '')
user = User.authenticate(email=email, password=password)
if user is not None:
self.set_current_user(user)
self.redirect(self.reverse_url(name='index'))
else:
error_message = 'ユーザ名かパスワードが間違っています。'
self.render('auth/login.html', error_message=error_message)
示例5: login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import authenticate [as 别名]
def login():
form = LoginForm()
if request.method == 'POST':
if form.validate_on_submit():
user, authenticated = User.authenticate(form.username.data,
form.password.data)
if user and authenticated:
login_user(user, remember=form.remember_me.data)
return url_for('map.devices_on_map')
else:
return make_response(422, message='Incorrect username or password.')
return render_template('login.html', title='Sign In', form=form)
示例6: login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import authenticate [as 别名]
def login():
if request.method == 'GET':
return render_template('base_index.html')
if request.method == 'POST':
form = LoginForm(request.form)
if form.validate():
username = form.data.get('username', '')
password = form.data.get('password', '')
admin_user = User.authenticate(username, password)
if admin_user:
return_status(200)
else:
return_status(400)
else:
return_status(401)
示例7: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import authenticate [as 别名]
def post(self):
form = LoginForm(self.request.arguments)
if form.validate():
username = form.data.get('username', '')
password = form.data.get('password', '')
user = User.authenticate(username, password)
if user:
user.last_login_at = datetime.datetime.now()
user.last_login_ip = self.request.remote_ip
user.save()
self.set_secure_cookie('user_id', str(user.id))
self.redirect(self.reverse_url('admin'))
else:
return self.return_status(400, '用户名或密码错误')
else:
return self.return_status(400, form.errors)
示例8: validate
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import authenticate [as 别名]
def validate(self):
if not Form.validate(self):
return False
return User.authenticate(email=self.data['email'], password=self.data['password'])