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


Python GsuserManager.get_thirdpartyUser_by_type_tpId方法代码示例

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


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

示例1: github_authenticate

# 需要导入模块: from gitshell.gsuser.models import GsuserManager [as 别名]
# 或者: from gitshell.gsuser.models.GsuserManager import get_thirdpartyUser_by_type_tpId [as 别名]
def github_authenticate(thirdpartyUser):
    tp_id, tp_username, tp_email, github_user_info = thirdpartyUser.tp_id, thirdpartyUser.tp_username, thirdpartyUser.tp_email, thirdpartyUser.github_user_info
    thirdpartyUser_find = GsuserManager.get_thirdpartyUser_by_type_tpId(ThirdpartyUser.GITHUB, tp_id)
    if thirdpartyUser_find is not None:
        if thirdpartyUser_find.access_token != thirdpartyUser.access_token:
            thirdpartyUser_find.access_token = thirdpartyUser.access_token
            thirdpartyUser_find.save()
        user_id = thirdpartyUser_find.id
        user = GsuserManager.get_user_by_id(user_id)
        return user
    username = __get_uniq_username(tp_username)
    email = __get_uniq_email(tp_email)
    password = __get_random_password()
    if username is None or email is None or password is None:
        return None
    create_user = None
    try:
        create_user = User.objects.create_user(username, email, password)
        if create_user is not None and create_user.is_active:
            userprofile = Userprofile(username = create_user.username, email = create_user.email, imgurl = hashlib.md5(create_user.email.lower()).hexdigest())
            _fill_github_user_info(userprofile, github_user_info)
            userprofile.id = create_user.id
            userprofile.save()
            if username == tp_username and email == tp_email:
                thirdpartyUser.init = 1
            thirdpartyUser.user_type = ThirdpartyUser.GITHUB
            thirdpartyUser.id = create_user.id
            thirdpartyUser.save()
    except IntegrityError, e:
        logger.exception(e)
开发者ID:ZheYuan,项目名称:gitshell,代码行数:32,代码来源:views.py

示例2: login_github_apply

# 需要导入模块: from gitshell.gsuser.models import GsuserManager [as 别名]
# 或者: from gitshell.gsuser.models.GsuserManager import get_thirdpartyUser_by_type_tpId [as 别名]
def login_github_apply(request):
    error = u''
    code = request.GET.get('code')
    if code is None:
        error = u'GitHub 关联失败,没有相关 code'
    access_token = github_oauth_access_token(code)
    if access_token == '':
        error = u'GitHub 关联失败,获取不到 access_token,请再次重试'
    thirdpartyUser = github_get_thirdpartyUser(access_token)
    if thirdpartyUser is None or thirdpartyUser.tp_id is None or thirdpartyUser.tp_username is None:
        error = u'获取不到 GitHub 信息,请再次重试'
    thirdpartyUser_find = GsuserManager.get_thirdpartyUser_by_type_tpId(ThirdpartyUser.GITHUB, thirdpartyUser.tp_id)
    if thirdpartyUser_find is not None:
        error = u'该 GitHub 账户已经关联 Gitshell,请直接使用 GitHub 账户登录'
    if error != '':
        return HttpResponseRedirect('/%s/-/repo/create/?%s#via-github' % (request.user.username, urllib.urlencode({'apply_error': error.encode('utf8')})))
    thirdpartyUser.user_type = ThirdpartyUser.GITHUB
    thirdpartyUser.access_token = access_token
    thirdpartyUser.id = request.user.id
    thirdpartyUser.init = 1
    thirdpartyUser.save()
    return HttpResponseRedirect('/%s/-/repo/create/#via-github' % request.user.username)
开发者ID:ZheYuan,项目名称:gitshell,代码行数:24,代码来源:views.py


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