Example #1
0
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)
Example #2
0
def ldap_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'] = 'ldap'
    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()
      user = auth_user_ldap(username, password)
      logging.info(user)
      if user:
        request.session['ldap_user'] = user
        return HttpResponseRedirect(reverse(after))
      else:
        error = 'Bad Username or Password'
  return render_template(request, 'password/login', {'form': form, 'error': error})
Example #3
0
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})
Example #4
0
def follow_view(request):
  if request.method == "GET":
    from auth.view_utils import render_template
    from auth.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 auth.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 auth.views import after_intervention
    return HttpResponseRedirect(reverse(after_intervention))