本文整理汇总了Python中auth.models.User.get_by_type_and_id方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_type_and_id方法的具体用法?Python User.get_by_type_and_id怎么用?Python User.get_by_type_and_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类auth.models.User
的用法示例。
在下文中一共展示了User.get_by_type_and_id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: password_login_view
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_type_and_id [as 别名]
def password_login_view(request):
from auth.view_utils import render_template
from auth.views import after
from auth.models import User
error = None
if request.method == "GET":
form = LoginForm()
else:
form = LoginForm(request.POST)
# set this in case we came here straight from the multi-login chooser
# and thus did not have a chance to hit the "start/password" URL
request.session['auth_system_name'] = 'password'
if request.POST.has_key('return_url'):
request.session['auth_return_url'] = request.POST.get('return_url')
if form.is_valid():
username = form.cleaned_data['username'].strip()
password = form.cleaned_data['password'].strip()
try:
user = User.get_by_type_and_id('password', username)
if password_check(user, password):
request.session['password_user'] = user
return HttpResponseRedirect(reverse(after))
except User.DoesNotExist:
pass
error = 'Bad Username or Password'
return render_template(request, 'password/login', {'form': form, 'error': error})
示例2: password_forgotten_view
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_type_and_id [as 别名]
def password_forgotten_view(request):
"""
forgotten password view and submit.
includes return_url
"""
from auth.view_utils import render_template
from auth.models import User
if request.method == "GET":
return render_template(request, 'password/forgot', {'return_url': request.GET.get('return_url', '')})
else:
username = request.POST['username']
return_url = request.POST['return_url']
try:
user = User.get_by_type_and_id('password', username)
except User.DoesNotExist:
return render_template(request, 'password/forgot', {'return_url': request.GET.get('return_url', ''), 'error': 'no such username'})
body = """
This is a password reminder:
Your username: %s
Your password: %s
--
%s
""" % (user.user_id, user.info['password'], settings.SITE_TITLE)
# FIXME: make this a task
send_mail('password reminder', body, settings.SERVER_EMAIL, ["%s <%s>" % (user.info['name'], user.info['email'])], fail_silently=False)
return HttpResponseRedirect(return_url)
示例3: create_user
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_type_and_id [as 别名]
def create_user(username, password, name = None):
from auth.models import User
user = User.get_by_type_and_id('password', username)
if user:
raise Exception('user exists')
info = {'password' : password, 'name': name}
user = User.update_or_create(user_type='password', user_id=username, info = info)
user.save()
示例4: user
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_type_and_id [as 别名]
def user(self):
return User.get_by_type_and_id(self.voter_type, self.voter_id)