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}
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)
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)
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) })
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)
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)})
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 }
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)
# Modules to make available for convenience so the names are available in the # ipython shell. Just a lazy way to not have to execute these lines individually # in a new shell. from seattlegeni.common.api import maindb from seattlegeni.common.exceptions import * from seattlegeni.website.control import interface import random def testfailed(reason): raise Exception("Test failed: " + reason) username = '******' + str(random.randint(0, 1000000)) # Create a user. geniuser = interface.register_user(username, 'mypass', '*****@*****.**', 'myaffiliation') # Get the user. geniuser = interface.get_user_with_password(username, 'mypass') # Make sure the private key was created because we didn't provide a pubkey when # creating the user. privkey = interface.get_private_key(geniuser) if privkey is None: testfailed("private key wasn't created") # Delete the private key and make sure it gets deleted. interface.delete_private_key(geniuser) privkey = interface.get_private_key(geniuser)