本文整理汇总了Python中models.user.User.login方法的典型用法代码示例。如果您正苦于以下问题:Python User.login方法的具体用法?Python User.login怎么用?Python User.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.login方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def login_user():
email = request.form['email']
password = request.form['password']
if User.login_valid(email, password):
User.login(email)
else:
session['email'] = None
return render_template("profile.html", email=session['email'])
示例2: POST
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def POST(self, request):
body = request.values.get('Body')
if not body:
body = request.get_json()['Body']
print("received message %s" % body)
phone = request.values.get('From')
if not phone:
phone = request.get_json()['From']
credentials = User.credentials(phone)
try:
sender = User.login(*credentials)
except (ResourceRequestBadRequest, KeyError):
return ('', 401)
# Languages
if body.startswith('add'):
return self._add_language(sender, body, request)
elif body.startswith('remove'):
return self._remove_language(sender, body, request)
# Pen Pals
elif body.startswith('report'):
return self._report_pen_pal(sender, body, request)
elif body.startswith('swap'):
return self._swap_pen_pal(sender, body, request)
# Messages
else:
return self._queue_message(sender, body, request)
示例3: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def post(self):
username = self.request.get('username')
password = self.request.get('password')
u = User.login(username, password)
if u:
self.login(u)
self.redirect('/welcome')
else:
msg = "Invalid login.Please enter a valid username and password or go to the signup page" # noqa
self.render("login_user.html", error=msg)
示例4: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def post(self):
username = self.request.get('username')
password = self.request.get('password')
u = User.login(username, password)
if u:
self.login(u)
self.redirect('/blog')
else:
msg = 'Invalid login'
self.render('login-form.html', error=msg)
示例5: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def post(self):
redirect = False
username = self.request.get('username')
password = self.request.get('password')
if (User.login(username, password)):
user = User.by_username(username)
self.login(user)
self.redirect("/")
else:
self.render_form(login_error=True)
示例6: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def post(self):
username = self.request.get('username')
password = self.request.get('password')
self.user = User.login(username, password)
params = {}
if self.user:
self.login(self.user)
self.redirect('/welcome')
else:
params['error'] = 'Invalid login'
self.render('login.html', **params)
示例7: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def post(self, *args, **kwargs):
""""""
username = self.get_argument('username', None)
password = self.get_argument('password', None)
if username is None or password is None:
raise TError(code=2001, msg='username or password not valid')
uid = User.login(username, password)
if uid is None:
if not User.username_exists(username):
uid = User.register(username, password)
if uid is None: #
self.redirect('/dyw/login')
return
self.session.set_session(dict(uid=uid))
self.set_secure_cookie('sid', self.session.sid, domain=self.settings['cookie_domain'])
self.redirect('/')
示例8: login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def login():
if request.method == 'GET':
return render_template(
'login.html',
title='Bluestreets login'
)
values = json.loads(request.form['params'])
dao = Dao(stateful=True)
try:
rec = User.login(dao, values['username'], values['password'])
session['user'] = rec
return jsonify(msg='Hello %s!' % rec['first_name'])
except Exception as ex:
return jsonify(error=str(ex))
finally:
dao.close()
示例9: login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def login():
if request.method == 'GET':
return render_template(
'login.html',
title='allocat login'
)
values = json.loads(request.form['params'])
try:
rec = User.login(values['username'], values['password'])
session['is_authenticated'] = True
session['is_admin'] = rec['role_id'] == 1
session['user_id'] = rec['id']
if 'target' in values:
return redirect(url_for(values['target']))
return jsonify(msg='Successful login!')
except Exception as ex:
return jsonify(error=str(ex))
示例10: login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def login():
next_url = request.args.get('next') or request.form.get('next') or ''
show_notice = request.args.get('show', type=bool) or request.form.get('show', type=bool) or 0
if not g.user.is_anonymous():
return redirect(next_url or url_for('home'))
username = request.form.get('username') or ''
password = request.form.get('password') or ''
remember = ( request.form.get('stay_in', type=bool) or False ) == True
invalid = False
if request.method == 'POST':
if username and password:
user = User.login(username, password)
if user:
if login_user(user, remember):
return redirect(next_url or url_for('home'))
invalid = True
return render(page='login', title=gettext('Log in'), section='login', username=username, password=password, invalid=invalid, next_url=next_url, show_notice=show_notice)
示例11: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def post(self):
'''
check the information entered against information stored
in the db. if all is well, log the user in and redirect
them to the welcome page.
if not, render the login form again with an error message
'''
have_error = False
username = self.request.get("username").encode("latin-1")
password = self.request.get("password").encode("latin-1")
user = User.login(username, password)
if user:
self.login(user)
self.redirect('/welcome')
else:
error = 'Invalid login'
self.render('users/login.html', error=error)
示例12: parse_request
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login [as 别名]
def parse_request(self, data):
tokenz = data.split("#")
code = tokenz[0]
args = tokenz[1:]
if not self.loggedin:
if code == "LGN_REQ":
x = User.login(args[0], args[1])
if x == 0:
self.client_socket.send("LGN_RES#0\n")
elif x == 2:
self.client_socket.send("LGN_RES#2\n")
else:
self.user = x
self.loggedin = True
self.client_socket.send("LGN_RES#1\n")
elif code == "REG_REQ":
x = User.register(args[0], args[1])
if x == 0:
self.client_socket.send("REG_RES#0\n")
elif x == 1:
self.client_socket.send("REG_RES#1\n")
elif code == "ACT_REQ":
x = User.verify(args[0], args[1])
if x == 0:
self.client_socket.send("ACT_RES#0\n")
else:
self.user = x
self.loggedin = True
self.client_socket.send("ACT_RES#1\n")
else:
if code == "MAK_VOT":
x = self.user.vote(args[0], args[1])
if x == 0:
self.client_socket.send("RES_VOT#0\n")
elif x == 1:
self.client_socket.send("RES_VOT#1\n")
elif code == "POLL_REQ":
x = Poll.get_by_id(args[0])
if x == 0:
self.client_socket.send("POLL_RES#0\n")
else:
self.client_socket.send("POLL_RES#"+str(x)+"\n")
elif code == "CHK_VOT":
x = self.user.check_vote(args[0])
if x == 0:
self.client_socket.send("CHK_RES#0")
else:
self.client_socket.send("CHK_RES#" + x +"\n")
elif code == "LGO_REQ":
self.user = None
self.loggedin = False
elif code == "DCR_POL":
if self.user.is_admin == 1:
poll = Poll.get_by_id(args[0])
if poll == 0:
self.client_socket.send("RES_VOT#0\n")
else:
poll.get_result(poll.private_key)
else:
self.client_socket.send("RES_VOT#2\n")
elif code == "create":
pass