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


Python UserProfile.user方法代码示例

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


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

示例1: save

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import user [as 别名]
    def save(self):
        email = self.cleaned_data["email"]
        first_name = self.cleaned_data["first_name"]
        last_name = self.cleaned_data["last_name"]
        password = self.cleaned_data["password"]
        password_c = self.cleaned_data["password_c"]
        bio = self.cleaned_data["bio"]
        random_username = hashlib.sha224(email).hexdigest()[:30]
        activation_code = hashlib.sha224(email).hexdigest()[:50]
        
        user = User()
        user.username = random_username
        user.email = email
        user.first_name = first_name
        user.last_name = last_name
        user.is_active = False
        user.set_password(password)
        user.save()

        user_profile = UserProfile()
        user_profile.bio = bio
        user_profile.user = user
        user_profile.activation_code = activation_code
        user_profile.save()
        send_user_activation_mail.delay(activation_code, email)
开发者ID:iskeltan,项目名称:blox,代码行数:27,代码来源:forms.py

示例2: login_core

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import user [as 别名]
def login_core(request, username, password):
    ret = False
    
    if username == 'admin':
        # 特殊用户 admin
        user = authenticate(username=username, password=password)
    else:
        if password == '':
            return False
        # LDAP验证
        if not login_ldap(username, password):
            return False
            
        # 检查此用户是否存在,如果不存在,则自动插入用户记录
        res = User.objects.filter(username=username)
        if not res:
            # 从LDAP获取用户信息
            dd = search_user(username)[0]
            password = make_password(username, salt=None, hasher='default')
            user = User(username=username, password=password, email=dd['mail'])
            user.save()
            # 用户附加信息
            profile = UserProfile()
            profile.department = dd['department']
            profile.phone = dd['phone']
            profile.realname = dd['cn']
            profile.user = user
            profile.save()
        
        # 这里请注意   *** password=username ***
        user = authenticate(username=username, password=username)
            
    # 登陆核心方法
    if user:
        if user.is_active:
            auth_login(request, user)
            ret = True
        else:
            messages.add_message(request, messages.INFO, _(u'用户没有激活'))
    else:
        messages.add_message(request, messages.INFO, _(u'用户不存在'))
    return ret
开发者ID:yindashan,项目名称:workorder,代码行数:44,代码来源:views.py

示例3: login_evernote_token

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import user [as 别名]
def login_evernote_token(request):
    """ as get_evernote_token(), but logs the user in as well
    """
    everAuth = EvernoteAPI()
    credentials = everAuth.get_user_token(request)
    if not credentials:
        return HttpResponseRedirect(reverse('account.views.login_page', args=[]))
    if request.user.is_authenticated():
        user = request.user
    else:
        evernoteHost = settings.EVERNOTE_HOST
        userStoreUri = "https://" + evernoteHost + "/edam/user"
        userStoreHttpClient = THttpClient.THttpClient(userStoreUri)
        userStoreProtocol = TBinaryProtocol.TBinaryProtocol(userStoreHttpClient)
        userStore = UserStore.Client(userStoreProtocol)
        evernoteUser = userStore.getUser(credentials['oauth_token'])
        user = authenticate(username=evernoteUser.username, password=str(evernoteUser.id))
        if not user:
            newUser = User.objects.create_user(evernoteUser.username, evernoteUser.email, str(evernoteUser.id))
            names = evernoteUser.name.split() if evernoteUser.name else None
            newUser.first_name = names[0] if names and len(names) > 0 else ""
            newUser.last_name = names[1] if names and len(names) > 1 else ""
            newUser.save()
            user = authenticate(username=evernoteUser.username, password=str(evernoteUser.id))
        login(request, user)

    try:
        expires_time = datetime.fromtimestamp(int(credentials['expires']))
    except TypeError:
        logging.error("Error parsing token expires time")
        expires_time = datetime.now()

    profile = UserProfile()
    profile.user = user
    profile.evernote_token = credentials['oauth_token']
    profile.evernote_token_expires_time = expires_time
    profile.evernote_note_store_url = credentials['edam_noteStoreUrl']
    profile.save()
    return HttpResponseRedirect(reverse('base.views.index', args=[]))
开发者ID:amcglathery,项目名称:evernote_minihack,代码行数:41,代码来源:views.py

示例4: post

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import user [as 别名]
    def post(self, request, format=None):
        resutl = {}
        serializer = UserRegisterSerializer(data=request.data)
        if serializer.is_valid():
            username = serializer.validated_data.get('username')
            password = serializer.validated_data.get('password')
            email = serializer.validated_data.get('email')
            type = serializer.validated_data.get('type', 0)
            auth_user = User()
            auth_user.username = username
            auth_user.set_password(password)
            auth_user.email = email
            auth_user.save()

            # 保存user扩展
            userProfile = UserProfile()
            userProfile.user = auth_user
            userProfile.telephone = username
            userProfile.type = type
            userProfile.save()

            return Response({'status': 'ok'})
开发者ID:jinchaozhi,项目名称:dissect,代码行数:24,代码来源:views.py


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