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


Python User.authenticate方法代码示例

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


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

示例1: get_user

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import authenticate [as 别名]
def get_user(headers):
    current_user = get_endpoints_current_user(raise_unauthorized=False)
    user = None
    if current_user is None:
        credential_pair = get_credential(headers)
        email = credential_pair[0]
        validate_email(email)
        User.authenticate(credential_pair[0], md5(credential_pair[1]))
        user = User.find_user_by_email(email)
    else:
        user = User.find_user_by_email(current_user.email())
    return user
开发者ID:ignitesol,项目名称:tasks,代码行数:14,代码来源:utils.py

示例2: authenticate

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import authenticate [as 别名]
    def authenticate(self, request):
        email = request.user_email
        validate_email(email)
        team_key = request.team_key
        user = User.find_user_by_email(email, team_key)

        if team_key:
            team_secret = request.team_secret
            validate_team_secret(team_secret)

            display_name = request.display_name
            image_url = request.user_image_url

            if not user:
                user = User.insert_user(email=email, username=display_name, account_type=team_key, image_url=image_url)
                community = Community.getCommunityFromTeamKey(team_key)
                UserRole.insert(user, community)
            elif (display_name != user.display_name) or (image_url != user.image_url):
                User.update_user(user=user, email=email, username=display_name, account_type=team_key, image_url=image_url)
            if not Community.authenticate(team_key, md5(team_secret)):
                raise endpoints.UnauthorizedException("Authentication failed. Team key and secret are not matched.")
        elif user.auth_source == AuthSourceType.ANNO:
            password = request.password
            validate_password(password)
            if not user:
                raise endpoints.NotFoundException("Authentication failed. User account " + email + " doesn't exist.")
            if not User.authenticate(email, md5(password)):
                raise endpoints.UnauthorizedException("Authentication failed. Email and password are not matched.")
        else:
            raise endpoints.ForbiddenException("Account for '%s' is Google or Facebook OAuth account." % email)

        return UserMessage(id=user.key.id(), display_name=user.display_name)
开发者ID:usersource,项目名称:anno,代码行数:34,代码来源:account_api.py

示例3: auth_user

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import authenticate [as 别名]
def auth_user(headers):
    current_user = get_endpoints_current_user(raise_unauthorized=False)
    user = None

    if current_user is None:
        credential_pair = get_credential(headers)

        signinMethod = SignInMethod.ANNO
        team_key = None
        team_secret = None
        display_name = None
        image_url = None

        if len(credential_pair) == 2:
            email, password = credential_pair
        elif len(credential_pair) == 5:
            signinMethod, email, password, team_key, team_secret = credential_pair
        else:
            signinMethod, email, password, team_key, team_secret, display_name, image_url = credential_pair

        validate_email(email)
        user = User.find_user_by_email(email, team_key)

        if signinMethod == SignInMethod.ANNO:
            User.authenticate(email, md5(password))
        elif signinMethod == SignInMethod.PLUGIN:
            if not Community.authenticate(team_key, team_secret):
                 raise endpoints.UnauthorizedException("Incorrect team key or secret")

            display_name = unicode(display_name, "utf-8", "ignore")
            if not user:
                user = User.insert_user(email=email, username=display_name, account_type=team_key, image_url=image_url)
                community = Community.getCommunityFromTeamKey(team_key)
                UserRole.insert(user, community)
            elif (display_name and display_name != user.display_name) or (image_url and image_url != user.image_url):
                User.update_user(user=user, email=email, username=display_name, account_type=team_key, image_url=image_url)
    else:
        user = User.find_user_by_email(current_user.email())

    if user is None:
        raise endpoints.UnauthorizedException("Oops, something went wrong. Please try later.")

    return user
开发者ID:usersource,项目名称:anno,代码行数:45,代码来源:utils.py

示例4: authenticate

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import authenticate [as 别名]
 def authenticate(self, request):
     email = request.user_email
     validate_email(email)
     password = request.password
     validate_password(password)
     user = User.find_user_by_email(email)
     if not user:
         raise endpoints.NotFoundException("Authentication failed. User account " + email + " doesn't exist.")
     if not User.authenticate(email, md5(password)):
         raise endpoints.UnauthorizedException("Authentication failed. User name and password are not matched.")
     return UserMessage(id=user.key.id(), display_name=user.display_name)
开发者ID:ignitesol,项目名称:tasks,代码行数:13,代码来源:account_api.py


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