当前位置: 首页>>代码示例>>Python>>正文


Python User.login方法代码示例

本文整理汇总了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)
开发者ID:FerminYang,项目名称:doodle,代码行数:35,代码来源:auth.py

示例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)
开发者ID:iingemar,项目名称:dazzling-octo-wiki,代码行数:27,代码来源:login.py

示例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')
开发者ID:tominovak33,项目名称:notes-webapp,代码行数:9,代码来源:handlers.py

示例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})
开发者ID:WXGBridgeQ,项目名称:ios-test,代码行数:9,代码来源:app.py

示例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()
开发者ID:ansermak,项目名称:equipment_flask,代码行数:30,代码来源:views.py

示例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
开发者ID:hackrole,项目名称:daily-program,代码行数:11,代码来源:base.py

示例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)
开发者ID:Eduardoescamilla,项目名称:Udacity_blog,代码行数:12,代码来源:wiki.py

示例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='/')
开发者ID:romanlevin,项目名称:roman-wiki,代码行数:12,代码来源:wiki.py

示例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")
开发者ID:zoedai,项目名称:Wiki,代码行数:12,代码来源:main.py

示例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)
开发者ID:yijiaow,项目名称:multi-user-blog,代码行数:12,代码来源:main.py

示例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
开发者ID:superisaac,项目名称:rainy,代码行数:12,代码来源:util.py

示例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
开发者ID:ascott1,项目名称:govcode,代码行数:12,代码来源:gh_import.py

示例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)
开发者ID:naveenpanwar,项目名称:helloworld,代码行数:13,代码来源:unit2.py

示例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
开发者ID:ermandoser,项目名称:foodops,代码行数:13,代码来源:forms.py

示例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)
开发者ID:LeilaniAnn,项目名称:blog,代码行数:13,代码来源:main.py


注:本文中的models.User.login方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。