Beispiel #1
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 #2
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 #3
0
def follow_view(request):
    if request.method == "GET":
        from heliosauth.view_utils import render_template
        from heliosauth.views import after

        return render_template(request, 'twitter/follow', {
            'user_to_follow': USER_TO_FOLLOW,
            'reason_to_follow': REASON_TO_FOLLOW
        })

    if request.method == "POST":
        follow_p = bool(request.POST.get('follow_p', False))

        if follow_p:
            from heliosauth.security import get_user

            user = get_user(request)
            twitter_client = _get_client_by_token(user.token)
            result = twitter_client.oauth_request(
                'http://api.twitter.com/1/friendships/create.json',
                args={'screen_name': USER_TO_FOLLOW},
                method='POST')

        from heliosauth.views import after_intervention
        return HttpResponseRedirect(reverse(after_intervention))
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 password_login_view(request):
    from heliosauth.view_utils import render_template
    from heliosauth.views import after
    from heliosauth.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:
                try:
                    ecount_user = User.objects.get(user_id=username,
                                                   ecounting_account=True)
                    user = get_ecounting_user(username, password)
                except User.DoesNotExist:
                    try:
                        user = User.objects.get(user_id=username,
                                                ecounting_account=False)
                    except User.DoesNotExist:
                        user = get_ecounting_user(username, password)
                        if not user:
                            raise User.DoesNotExist

                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
    })
Beispiel #6
0
def follow_view(request):
  if request.method == "GET":
    from heliosauth.view_utils import render_template
    from heliosauth.views import after

    return render_template(request, 'twitter/follow', {'user_to_follow': USER_TO_FOLLOW, 'reason_to_follow' : REASON_TO_FOLLOW})

  if request.method == "POST":
    follow_p = bool(request.POST.get('follow_p',False))

    if follow_p:
      from heliosauth.security import get_user

      user = get_user(request)
      twitter_client = _get_client_by_token(user.token)
      result = twitter_client.oauth_request('http://api.twitter.com/1/friendships/create.json', args={'screen_name': USER_TO_FOLLOW}, method='POST')

    from heliosauth.views import after_intervention
    return HttpResponseRedirect(reverse(after_intervention))
Beispiel #7
0
def password_login_view(request):
  from heliosauth.view_utils import render_template
  from heliosauth.views import after
  from heliosauth.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:
        try:
            ecount_user = User.objects.get(user_id=username, ecounting_account=True)
            user = get_ecounting_user(username, password)
        except User.DoesNotExist:
            try:
                user = User.objects.get(user_id=username, ecounting_account=False)
            except User.DoesNotExist:
                user = get_ecounting_user(username, password)
                if not user:
                    raise User.DoesNotExist

        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})