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


Python UserProfile.hostname方法代码示例

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


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

示例1: process_request

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import hostname [as 别名]
 def process_request(self, request):
     if request.user.is_authenticated():
         return
     PartyHooks.execute_hook('user.prelogin', request=request)
     hostname = request.META['REMOTE_HOST'] or request.META['REMOTE_ADDR']
     try:
         # reverse the profile back to user based on hostname
         up = UserProfile.objects.get(hostname=hostname)
         user = up.user
         user.backend = 'django.contrib.auth.backends.ModelBackend'
         request.user = user
         auth.login(request, up.user)
         if request.path not in ['/favicon.ico'] and not settings.STATIC_URL in request.path:
             if up.departed:
                 up.departed = False
                 up.save()
                 PartyHooks.execute_hook('user.returns')
                 messages.success(request, "Welcome back to the LAN!")
     except UserProfile.DoesNotExist:
         # if we're the first user, we're always an admin
         first_admin = (User.objects.count() == 0)
         # add a new user
         random_password = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(12))
         username = request.META['REMOTE_HOST'] or 'User-'+''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(6))
         user = User.objects.create_user(username, None, random_password)
         user.save()
         profile = UserProfile()
         profile.user = user
         profile.hostname = hostname
         if first_admin:
             profile.set_flag(FLAG_ADMIN)
         profile.save()
         request.user = user
         user = auth.authenticate(username=username, password=random_password)
         auth.login(request, user)
         if first_admin:
             # redirect to admin panel for setup
             messages.success(request, "Welcome to pyParty!  As the first user, you're automatically an admin.  Please continue setting up pyParty as you normally would!")
             return HttpResponseRedirect('/admin/')
         else:
             messages.success(request, "Welcome to %s!  We set up an account for you.  There's no need for a password, you will be recognized by your computer.  Feel free to <a href='/accounts/profile/'>continue setting up your profile</a>." % get_setting('lan_name'))
开发者ID:JonnyFunFun,项目名称:pyParty,代码行数:43,代码来源:middleware.py


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