本文整理汇总了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'))