Пример #1
0
def login(request):
  try:
    # check to see if a user is already logged in. if so, redirect them to profile.
    user = interface.get_logged_in_user(request)
  except DoesNotExistError:
    pass
  else:
    return HttpResponseRedirect(reverse("profile"))

  ltemplate = 'accounts/login.html'
  if request.method == 'POST':
    form = AuthenticationForm(request.POST)
    
    if not request.session.test_cookie_worked():
      request.session.set_test_cookie()
      return _show_login(request, ltemplate, {'err' : "Please enable your cookies and try again."}, form)

    if request.POST.has_key('jsenabled') and request.POST['jsenabled'] == 'false':
      return _show_login(request, ltemplate, {'err' : "Please enable javascript and try again."}, form)

    try:
      interface.login_user(request, request.POST['username'], request.POST['password'])
    except DoesNotExistError:
      return _show_login(request, ltemplate, {'err' : "Wrong username or password."}, form)
      
    # only clear out the cookie if we actually authenticate and login ok
    request.session.delete_test_cookie()
    
    return HttpResponseRedirect(reverse("profile"))
    
  # request type is GET, show a fresh login page
  return _show_login(request, ltemplate, {})
Пример #2
0
def _validate_and_get_geniuser(request):
  try:
    user = interface.get_logged_in_user(request)
  except DoesNotExistError:
    # Failed to get GeniUser record, but user is logged in
    raise LoggedInButFailedGetGeniUserError
  return user
Пример #3
0
def login(request):
  try:
    # check to see if a user is already logged in. if so, redirect them to profile.
    user = interface.get_logged_in_user(request)
  except DoesNotExistError:
    pass
  else:
    return HttpResponseRedirect(reverse("profile"))

  ltemplate = 'accounts/login.html'
  if request.method == 'POST':
    form = AuthenticationForm(request.POST)
    
    if not request.session.test_cookie_worked():
      request.session.set_test_cookie()
      return _show_login(request, ltemplate, {'err' : "Please enable your cookies and try again."}, form)

    if request.POST.has_key('jsenabled') and request.POST['jsenabled'] == 'false':
      return _show_login(request, ltemplate, {'err' : "Please enable javascript and try again."}, form)

    try:
      interface.login_user(request, request.POST['username'], request.POST['password'])
    except DoesNotExistError:
      return _show_login(request, ltemplate, {'err' : "Wrong username or password."}, form)
      
    # only clear out the cookie if we actually authenticate and login ok
    request.session.delete_test_cookie()
    
    return HttpResponseRedirect(reverse("profile"))
    
  # request type is GET, show a fresh login page
  return _show_login(request, ltemplate, {})
Пример #4
0
def _validate_and_get_geniuser(request):
  try:
    user = interface.get_logged_in_user(request)
  except DoesNotExistError:
    # Failed to get GeniUser record, but user is logged in
    raise LoggedInButFailedGetGeniUserError
  return user
Пример #5
0
def register(request):
    try:
        # check to see if a user is already logged in. if so, redirect them to profile.
        user = interface.get_logged_in_user(request)
    except DoesNotExistError:
        pass
    else:
        return HttpResponseRedirect(reverse("profile"))

    page_top_errors = []
    if request.method == 'POST':

        #TODO: what if the form data isn't in the POST request? we need to check for this.
        form = forms.GeniUserCreationForm(request.POST, request.FILES)
        # Calling the form's is_valid() function causes all form "clean_..." methods to be checked.
        # If this succeeds, then the form input data is validated per field-specific cleaning checks. (see forms.py)
        # However, we still need to do some checks which aren't doable from inside the form class.
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            affiliation = form.cleaned_data['affiliation']
            email = form.cleaned_data['email']
            pubkey = form.cleaned_data['pubkey']

            try:
                validations.validate_username_and_password_different(
                    username, password)
            except ValidationError, err:
                page_top_errors.append(str(err))

            # NOTE: gen_upload_choice turns out to be a *string* when retrieved, hence '2'
            if form.cleaned_data['gen_upload_choice'] == '2' and pubkey == None:
                page_top_errors.append("Please select a public key to upload.")

            # only proceed with registration if there are no validation errors
            if page_top_errors == []:
                try:
                    # we should never error here, since we've already finished validation at this point.
                    # but, just to be safe...
                    user = interface.register_user(username, password, email,
                                                   affiliation, pubkey)
                except ValidationError, err:
                    page_top_errors.append(str(err))
                else:
                    return _show_login(
                        request, 'accounts/login.html', {
                            'msg':
                            "Username %s has been successfully registered." %
                            (user.username)
                        })
Пример #6
0
def register(request):
  try:
    # check to see if a user is already logged in. if so, redirect them to profile.
    user = interface.get_logged_in_user(request)
  except DoesNotExistError:
    pass
  else:
    return HttpResponseRedirect(reverse("profile"))
  
  page_top_errors = []
  if request.method == 'POST':
    
    #TODO: what if the form data isn't in the POST request? we need to check for this.
    form = forms.GeniUserCreationForm(request.POST, request.FILES)
    # Calling the form's is_valid() function causes all form "clean_..." methods to be checked.
    # If this succeeds, then the form input data is validated per field-specific cleaning checks. (see forms.py)
    # However, we still need to do some checks which aren't doable from inside the form class.
    if form.is_valid():
      username = form.cleaned_data['username']
      password = form.cleaned_data['password1']
      affiliation = form.cleaned_data['affiliation']
      email = form.cleaned_data['email']
      pubkey = form.cleaned_data['pubkey']
      
      try:
        validations.validate_username_and_password_different(username, password)
      except ValidationError, err:
        page_top_errors.append(str(err))
      
      # NOTE: gen_upload_choice turns out to be a *string* when retrieved, hence '2'
      if form.cleaned_data['gen_upload_choice'] == '2' and pubkey == None:
        page_top_errors.append("Please select a public key to upload.")
      
      # only proceed with registration if there are no validation errors
      if page_top_errors == []:
        try:
          # we should never error here, since we've already finished validation at this point.
          # but, just to be safe...
          user = interface.register_user(username, password, email, affiliation, pubkey)
        except ValidationError, err:
          page_top_errors.append(str(err))
        else:
          return _show_login(request, 'accounts/login.html',
                             {'msg' : "Username %s has been successfully registered." % (user.username)})