本文整理汇总了Python中models.User.login方法的典型用法代码示例。如果您正苦于以下问题:Python User.login方法的具体用法?Python User.login怎么用?Python User.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.login方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: callback
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def callback():
'''用户成功登录授权后,会回调此方法,获取access_token,完成授权'''
verifier = request.args.get('oauth_verifier', None)
# 设置之前保存在session的request_token
if 'oauth_request_token' in session:
request_token = session['oauth_request_token']
del session['oauth_request_token']
else:
return render_template('index.html')
auth_client.set_request_token(request_token.key, request_token.secret)
access_token = auth_client.get_access_token(verifier)
at_key = access_token.key
at_secret = access_token.secret
#设定用户令牌密钥
auth_client.setToken( at_key, at_secret )
#绑定用户验证信息.
api = API(auth_client)
#获取微博信息
weibo = api.verify_credentials()
if weibo is False or weibo is None:
flash(u'杯具啊,你木有开通微博吧(⊙﹏⊙)a', 'error')
return render_template('index.html')
#记录用户登录信息,更新用户微博资料
User.login(weibo=weibo)
Weibo.set(weibo=weibo, at_key=at_key, at_secret=at_secret)
#设置session
session['id'] = weibo.id
session.permanent = True
# 跳转回最初登录前的页面
back_to_url = session.get('login_back_to_url', '/')
return redirect(back_to_url)
示例2: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def post(self):
print('[POST]', self.request.POST)
username = self.request.get('username')
password = self.request.get('password')
# Login from any page and get redirected to that page when complete.
next_url = str(self.request.get('referer'))
if not next_url or next_url.startswith('/login'):
next_url = '/'
if username and password:
# Fetch user
user = User.login(username, password)
if user:
print('PASSWORD OK')
# Store user id in secure cookie
self.set_secure_cookie('userId', str(user.key().id()))
# Redirect to referring page
self.redirect(next_url)
else:
error = 'Error, username or password wrong.'
self.render_page(username, password, error, next_url)
else:
error = 'Error, you need to fill in all values.'
self.render_page(username, password, error, next_url)
示例3: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def post(self):
login_valid, user = User.login(self.request.get('email'), self.request.get('password'))
if login_valid:
abstractions.set_login_cookie(user, self)
# cookie_token = abstractions.generate_auth_token(user.key.urlsafe())
# helpers.set_cookie('auth_token', cookie_token, self)
self.redirect('/notes')
示例4: login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def login():
# receive post params
username = request.values.get('username')
password = request.values.get('password')
user_id = User.login(username, password)
return jsonify({'user_id' : user_id})
示例5: _save_data
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def _save_data(self, base_data, form):
super(DepartmentEntity, self)._save_data(base_data, form)
department_id = base_data.id
if base_data.id is None:
department_counter = db.session.query(db.func.max(Department.id)
).scalar()
department_id = department_counter + 1 if department_counter else 1
department = Department.query.get(department_id)
u = User.query.filter(User.did == department_id).first()
h = Hardware.query.filter(Hardware.did == department_id).first()
if not u:
u = User(name='',
department_id=department_id,
did=department_id)
h = Hardware(serial=department_id,
inum=department_id,
department_id=department_id,
did=department_id,
model='--department--'
)
u.view_name = '--{}--'.format(department.name)
u.surname = '--{}--'.format(department.name)
u.login = department.name
h.name = '--{}--'.format(department.name)
h.view_name = '--{}--'.format(department.name)
db.session.add(h)
db.session.add(u)
db.session.commit()
示例6: user_login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def user_login(self, email, password):
# user the utils login and set user
# on the session. or return none if fails
login_result = User.login(email, password)
if login_result:
self.session['user'] = login_result
return login_result
示例7: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def post(self):
username = self.request.get("username")
password = self.request.get("password")
user = User.login(username, password)
if user:
self.login(user)
self.redirect("/wiki/welcome")
else:
error_login = "Invalid Login"
self.render("wiki_login.html", username=username, error_login=error_login)
示例8: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def post(self):
username = self.request.get("username")
password = self.request.get("password")
user = User.login(username, password)
if not user:
error = 'Invalid login.'
self.render('login.jinja', username=username, error=error)
else:
self.login(user)
self.redirect_to('WikiPage', page_name='/')
示例9: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.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('/wiki')
else:
self.get("invalid user name or password")
示例10: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def post(self):
username = self.request.get('username')
password = self.request.get('password')
user = User.login(username, password) #login() from User class
if user:
self.login(user)
self.redirect('/')
else:
error_login = "Invalid login."
self.render('login-form.html', error_login=error_login)
示例11: __decorator
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def __decorator(self, reactor, **kwargs):
auth_str = reactor.environ.get('HTTP_AUTHORIZATION')
if auth_str:
m = re.match(r'Basic (\w+)', auth_str)
if m:
username, password = base64.decodestring(m.group(1)).split(':', 1)
reactor.user = User.login(username, password)
if reactor.user:
return func(self, reactor, **kwargs)
raise HttpAuthentication
示例12: get_or_create_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def get_or_create_user(self, user):
u = User.query.filter_by(gh_id=user.id).first()
if u is None:
u = User()
u.gh_id = user.id
u.login = user.login
u.avatar_url = user.avatar_url
db.session.add(u)
db.session.commit()
return u
示例13: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def post(self):
username = self.request.get("username")
password = self.request.get("password")
user = User.login(username, password)
if user:
self.login(user)
self.redirect("/blog/welcome")
else:
error = "username and password doesn't match"
self.render("login.html", username=username, error=error)
示例14: create_get_user_entry
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import login [as 别名]
def create_get_user_entry(ldap_uname, ldap_email):
user = db.session.query(User).filter_by(login=ldap_uname, email=ldap_email).first()
if not user:
user = User()
user.login = ldap_uname
user.email = ldap_email
db.session.add(user)
db.session.commit()
return user
示例15: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.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)