コード例 #1
0
def custom_create_user(backend,
                       details,
                       response,
                       uid,
                       username,
                       user=None,
                       *args,
                       **kwargs):
    """Create user. Depends on get_username pipeline."""
    if user:
        return {'user': user}
    if not username:
        return None

    #set a random password
    password = str(uuid4())
    # NOTE: not return None because Django raises exception of strip email
    email = details.get('email') or ''
    if email == '':
        email = 'auto-register@' + backend.name + '.com'
    user = interface.register_user(username,
                                   password,
                                   email,
                                   affiliation='auto-register@' + backend.name)
    return {'user': user, 'is_new': True}
コード例 #2
0
    def test_seattlegeni_generates_user_keypair(self):

        # We expect a single keypair to be generated directly through the keygen
        # api (specifically, the user keys).
        user_pubkey = "3 4"
        user_privkey = "2 3 3"
        mocklib.mock_keygen_generate_keypair([(user_pubkey, user_privkey)])

        # We expect a single key to be generated directly through the backed api
        # (specifically, the donor key).
        donor_pubkey = "1 2"
        mocklib.mock_backend_generate_key([donor_pubkey])

        provided_pubkey = None
        interface.register_user(good_username, good_password, good_email,
                                good_affiliation, provided_pubkey)

        user_from_db = maindb.get_user(good_username)

        assert (user_from_db.user_pubkey == user_pubkey)
        assert (user_from_db.user_privkey == user_privkey)
        assert (user_from_db.donor_pubkey == donor_pubkey)
コード例 #3
0
  def test_seattlegeni_generates_user_keypair(self):
    
    # We expect a single keypair to be generated directly through the keygen
    # api (specifically, the user keys).
    user_pubkey = "3 4"
    user_privkey = "2 3 3"
    mocklib.mock_keygen_generate_keypair([(user_pubkey, user_privkey)])
    
    # We expect a single key to be generated directly through the backed api
    # (specifically, the donor key).
    donor_pubkey = "1 2"
    mocklib.mock_backend_generate_key([donor_pubkey])
    
    provided_pubkey=None
    interface.register_user(good_username, good_password, good_email, 
                                           good_affiliation, provided_pubkey)

    user_from_db = maindb.get_user(good_username)

    assert(user_from_db.user_pubkey == user_pubkey)
    assert(user_from_db.user_privkey == user_privkey)
    assert(user_from_db.donor_pubkey == donor_pubkey)
コード例 #4
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)
                        })
コード例 #5
0
 def _create_user_expect_success(self, username, password=good_password, email=good_email, 
                                 affiliation=good_affiliation, pubkey=good_pubkey):
   
   # We expect a single key to be generated through the backed (the donor key)
   mocklib.mock_backend_generate_key(["1 2"])
   
   created_user = interface.register_user(username, password, email, affiliation, pubkey)
 
   user_from_db = maindb.get_user(username)
   assert(user_from_db.username == created_user.username)
   assert(user_from_db.email == created_user.email)
   assert(user_from_db.affiliation == created_user.affiliation)
   assert(user_from_db.user_pubkey == created_user.user_pubkey)
   assert(user_from_db.user_privkey == created_user.user_privkey)
   assert(user_from_db.donor_pubkey == created_user.donor_pubkey)
コード例 #6
0
 def _create_user_expect_success(self, username, password=good_password, email=good_email, 
                                 affiliation=good_affiliation, pubkey=good_pubkey):
   
   # We expect a single key to be generated through the backed (the donor key)
   mocklib.mock_backend_generate_key(["1 2"])
   
   created_user = interface.register_user(username, password, email, affiliation, pubkey)
 
   user_from_db = maindb.get_user(username)
   assert(user_from_db.username == created_user.username)
   assert(user_from_db.email == created_user.email)
   assert(user_from_db.affiliation == created_user.affiliation)
   assert(user_from_db.user_pubkey == created_user.user_pubkey)
   assert(user_from_db.user_privkey == created_user.user_privkey)
   assert(user_from_db.donor_pubkey == created_user.donor_pubkey)
コード例 #7
0
ファイル: views.py プロジェクト: choksi81/clearinghouse
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)})
コード例 #8
0
def custom_create_user(backend, details, response, uid, username, user=None, *args,
                **kwargs):
    """Create user. Depends on get_username pipeline."""
    if user:
        return {'user': user}
    if not username:
        return None
    
    #set a random password
    password=str(uuid4())
    # NOTE: not return None because Django raises exception of strip email
    email = details.get('email') or ''
    if email == '':
      email= 'auto-register@'+ backend.name +'.com'
    user = interface.register_user(username, password, email, affiliation='auto-register@'+ backend.name)
    return {
        'user': user,
        'is_new': True
    }