Beispiel #1
0
def get_ecounting_user(username, password):
  from heliosauth.models import User

  is_valid, user_data = check_ecounting_credentials(username, password)
  user = None
  if not is_valid:
    return user

  try:
    user = User.get_by_type_and_id('password', username)
    user.institution = get_institution(user_data)
    user.info['name'] = username
    user.info['password'] = make_password(password)
    user.ecounting_account = True
    user.save()
  except User.DoesNotExist:
    if is_valid:
      user = create_user(username, password)
      user.admin_p = True
      user.info['name'] = user.user_id
      user.info['password'] = make_password(password)
      user.ecounting_account = True
      user.institution = get_institution(user_data)
      user.save()

  return user
Beispiel #2
0
def get_ecounting_user(username, password):
    from heliosauth.models import User

    is_valid, user_data = check_ecounting_credentials(username, password)
    user = None
    if not is_valid:
        return user

    try:
        user = User.get_by_type_and_id('password', username)
        user.institution = get_institution(user_data)
        user.info['name'] = username
        user.info['password'] = make_password(password)
        user.ecounting_account = True
        user.save()
    except User.DoesNotExist:
        if is_valid:
            user = create_user(username, password)
            user.admin_p = True
            user.info['name'] = user.user_id
            user.info['password'] = make_password(password)
            user.ecounting_account = True
            user.institution = get_institution(user_data)
            user.save()

    return user
Beispiel #3
0
def password_forgotten_view(request):
  """
  forgotten password view and submit.
  includes return_url
  """
  from heliosauth.view_utils import render_template
  from heliosauth.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)
Beispiel #4
0
def password_forgotten_view(request):
    """
  forgotten password view and submit.
  includes return_url
  """
    from heliosauth.view_utils import render_template
    from heliosauth.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)
Beispiel #5
0
def create_user(username, password, name = None, extra_info={}):
  from heliosauth.models import User

  try:
    user = User.get_by_type_and_id('password', username)
  except User.DoesNotExist:
    user = None

  if user:
    raise Exception('user exists')

  info = {'password' : make_password(password), 'name': name}
  info.update(extra_info)
  user = User.update_or_create(user_type='password', user_id=username, info=info)
  user.save()
  return user
Beispiel #6
0
def create_user(username, password, name=None, extra_info={}):
    from heliosauth.models import User

    try:
        user = User.get_by_type_and_id('password', username)
    except User.DoesNotExist:
        user = None

    if user:
        raise Exception('user exists')

    info = {'password': make_password(password), 'name': name}
    info.update(extra_info)
    user = User.update_or_create(user_type='password',
                                 user_id=username,
                                 info=info)
    user.save()
    return user
Beispiel #7
0
def password_forgotten_view(request):
    """
  forgotten password view and submit.
  includes return_url
  """
    from heliosauth.view_utils import render_template
    from heliosauth.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)