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


Python User.verify_auth_token方法代码示例

本文整理汇总了Python中model.User.verify_auth_token方法的典型用法代码示例。如果您正苦于以下问题:Python User.verify_auth_token方法的具体用法?Python User.verify_auth_token怎么用?Python User.verify_auth_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.User的用法示例。


在下文中一共展示了User.verify_auth_token方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: auth_inv

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import verify_auth_token [as 别名]
def auth_inv(uid_or_token,passwd_or_method):
  """
   inv authentication 
  """
  from model import User

  # try token
  u = User.verify_auth_token(uid_or_token)

  if not u:
    # try ldap
    y = auth_ldap(uid_or_token,passwd_or_method)
    # success
    if 'givenname' in y:
      # search for user in db
      u = User.query.filter_by(uid=uid_or_token).first()
      if not u: # user does not exist...
        # get the name
        fname = y['givenname'][0] if type(y['givenname']) == list else y['givenname'] 
        lname = y['sn']
        # get the group type
        ou = y['ou'] # ou = organizational unit
        grp = User.Groups.NoGroup
        if 'Students' in ou:
          grp = User.Groups.Student
        elif 'Employees' in ou:
          grp = User.Groups.Employee

        admins = ['bkim11','cbannan','psingh']
        operators = ['rkarrant','hcook']
        # check admins
        uid = uid_or_token
        if uid in admins:
          grp = User.Groups.Admin
        # check operators
        if uid in operators:
          grp = User.Groups.Operator

        # set permissions
        perm = DefaultPermissions[grp]

        # get email
        email = y.get('mail')
        phone = y.get('employeecampusphone')
        if phone is None:
          phone = y.get('mobile')
        # create the user
        u = User(uid_or_token,fname,lname,grp,perm,email,phone)
        # add user to db
        from model import db
        db.session.add(u)
        db.session.commit()

  if u:
    from flask import g
    g.user = u
    return u
  # failure
  else:
    return False
开发者ID:briansan,项目名称:inv,代码行数:62,代码来源:auth.py

示例2: auth_token

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import verify_auth_token [as 别名]
 def auth_token(self, token):
     '''
     authenticate a user by a token
     when succeeded, return the database iterator
     otherwise return None
     '''
     user = User.verify_auth_token(token)
     return user
开发者ID:DreamReaver,项目名称:docklet,代码行数:10,代码来源:userManager.py

示例3: verify

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import verify_auth_token [as 别名]
def verify(username_or_token, password):
    user = User.verify_auth_token(username_or_token)
    if not user:
        user = User.query.filter_by(login=username_or_token).first()
        if not user or not user.verify_password(password):
            return False
    g.user = user
    return True
开发者ID:StasEvseev,项目名称:adminbuy,代码行数:10,代码来源:auth.py

示例4: verify_password

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import verify_auth_token [as 别名]
def verify_password(username_or_token, password):
    # first try to authenticate by token
    user = User.verify_auth_token(username_or_token)
    if not user:
        # try to authenticate with username/password
        user = User.query.filter_by(username = username_or_token).first()
        if not user or not user.verify_password(password):
            return False
    g.user = user
    return True
开发者ID:crichon,项目名称:crichonBackend,代码行数:12,代码来源:views.py

示例5: verify_password

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import verify_auth_token [as 别名]
def verify_password(email_or_token, password):
    user_id = User.verify_auth_token(email_or_token)
    if user_id:
        user = session.query(User).filter_by(id = user_id).one()
    else:
        user = session.query(User).filter_by(email = email_or_token).first()
        if not user or not user.verify_password(password):
            return False
    g.user = user
    return True
开发者ID:aw7373,项目名称:AdvIntTechUTT,代码行数:12,代码来源:mealDateAPI.py

示例6: verify_admin

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import verify_auth_token [as 别名]
def verify_admin(username, password):
    user = User.verify_auth_token(username)

    if not user:
        user = User.query.filter_by(login=username).first()
        if not user or not user.verify_password(password):
            return False

    if user.is_superuser:
        g.user = user
        return True
    return False
开发者ID:StasEvseev,项目名称:adminbuy,代码行数:14,代码来源:auth.py

示例7: logout

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import verify_auth_token [as 别名]
def logout(provider):
	#redis calls should be move to a singliton design
	redis = Redis()
	token = request.headers.get('Authorization')
	data = User.verify_auth_token(token)
	p = redis.pipeline()
	p.incr(token) # increments key
	p.expireat(token, data[1]['exp']) # expires based on the reset value
	results = p.execute()
	if results[0] >= 1 and results[1] == True:
		return jsonify({'data': 'Successfully logged out'})
	else:
		return jsonify({'error': 'Error logging out'})
开发者ID:rayutt,项目名称:internet-tech,代码行数:15,代码来源:main.py

示例8: validate

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import verify_auth_token [as 别名]
	def validate(*args, **kwargs):
		print 'before token call'
		token = request.headers.get('Authorization')
		print token
		data = User.verify_auth_token(token) if token else None
		print data
		if data:
			g.user = data[0]['id']
			print g.user
			g.token = token
			g.token_expire = data[1]['exp']
			return func(*args, **kwargs)
		else:
			return jsonify({'error': 'Invalid token', 'redirect' : '/' })
开发者ID:rayutt,项目名称:internet-tech,代码行数:16,代码来源:main.py


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