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


Python User.get_by_type_and_id方法代码示例

本文整理汇总了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)
开发者ID:stanley89,项目名称:helios-server,代码行数:36,代码来源:password.py

示例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})
开发者ID:stanley89,项目名称:helios-server,代码行数:33,代码来源:password.py

示例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()
开发者ID:EM6Holdings,项目名称:helios-server,代码行数:12,代码来源:password.py

示例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()
开发者ID:stanley89,项目名称:helios-server,代码行数:15,代码来源:password.py

示例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)
开发者ID:pirati-cz,项目名称:helios-server,代码行数:50,代码来源:password.py

示例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}
开发者ID:stanley89,项目名称:helios-server,代码行数:8,代码来源:password.py


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