本文整理汇总了Python中helios_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使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helios_auth.models.User
的用法示例。
在下文中一共展示了User.get_by_type_and_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: password_forgotten_view
# 需要导入模块: from helios_auth.models import User [as 别名]
# 或者: from helios_auth.models.User import get_by_type_and_id [as 别名]
def password_forgotten_view(request):
"""
forgotten password view and submit.
includes return_url
"""
from helios_auth.view_utils import render_template
from helios_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)
示例2: password_login_view
# 需要导入模块: from helios_auth.models import User [as 别名]
# 或者: from helios_auth.models.User import get_by_type_and_id [as 别名]
def password_login_view(request):
from helios_auth.view_utils import render_template
from helios_auth.views import after
from helios_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_id'] = user.user_id
return HttpResponseRedirect(reverse(after))
except User.DoesNotExist:
pass
error = 'Bad Username or Password'
return render_template(request, 'password/login', {'form': form, 'error': error})
示例3: create_user
# 需要导入模块: from helios_auth.models import User [as 别名]
# 或者: from helios_auth.models.User import get_by_type_and_id [as 别名]
def create_user(username, password, name = None):
from helios_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: create_user
# 需要导入模块: from helios_auth.models import User [as 别名]
# 或者: from helios_auth.models.User import get_by_type_and_id [as 别名]
def create_user(username, password, name = None):
from helios_auth.models import User
from django.db import models
try:
user = User.get_by_type_and_id('password', username)
raise Exception('user exists')
except User.DoesNotExist:
pass
info = {'password' : password, 'name': name}
user = User.update_or_create(user_type='password', user_id=username, info = info)
user.save()
示例5: password_forgotten_view
# 需要导入模块: from helios_auth.models import User [as 别名]
# 或者: from helios_auth.models.User import get_by_type_and_id [as 别名]
def password_forgotten_view(request):
"""
forgotten password view and submit.
includes return_url
"""
from helios_auth.view_utils import render_template
from helios_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)
示例6: get_user_info_after_auth
# 需要导入模块: from helios_auth.models import User [as 别名]
# 或者: from helios_auth.models.User import get_by_type_and_id [as 别名]
def get_user_info_after_auth(request):
from helios_auth.models import User
user = User.get_by_type_and_id('password', request.session['password_user_id'])
del request.session['password_user_id']
return {'type': 'password', 'user_id' : user.user_id, 'name': user.name, 'info': user.info, 'token': None}