- username = self.email.partition('@')[0] if self.email
-
- blacklisted_usernames = Rails.configuration.auto_setup_name_blacklist.split(', ')
-
- if !Rails.configuration.auto_setup_new_users ||
- !(/^[_.A-Za-z0-9][-\@_.A-Za-z0-9]*\$?$/.match(self.email)) ||
- blacklisted_usernames.include?(username)
- return true
- else
- # Derive repo name and username using the string before @ in user's email
- # If a repo or vm login link with this prefix exists, generate unique string by appending a random number
- username = derive_unique_username username
-
- # setup user
- setup_repo_vm_links(username, Rails.configuration.auto_setup_new_users_with_vm_uuid, Rails.configuration.default_openid_prefix)
- end
- end
-
- # Derive repo name and username using the string before @ in user's email
- # If a repo or vm login link with this prefix exists, generate unique string by appending a random number
- def derive_unique_username username
- # no need to verify if vm login link or repo exists, if they both are not being created
- vm_uuid = Rails.configuration.auto_setup_new_users_with_vm_uuid
- if !vm_uuid && !Rails.configuration.auto_setup_new_users_with_repository
- return username
- end
-
- # need a unique username
- found_unique_username = false
- while !found_unique_username
- repo = Repository.where(name: username).first
-
- if repo
- username = username + SecureRandom.random_number(1000000).to_s
- elsif vm_uuid
- login_props = {"username" => username}
-
- vm_login_perms = Link.where(head_uuid: vm_uuid,
- link_class: 'permission',
- name: 'can_login')
- perm_exists = false
- vm_login_perms.each do |perm|
- if perm.properties['username'] == username
- perm_exists = true
- break
- end
- end
-
- if perm_exists
- username = username + SecureRandom.random_number(1000000).to_s
- else
- found_unique_username = true
- end
- else
- found_unique_username = true
- end
+ setup_repo_vm_links(nil, nil, Rails.configuration.default_openid_prefix)
+ if username
+ create_vm_login_permission_link(Rails.configuration.auto_setup_new_users_with_vm_uuid,
+ username)
+ repo_name = "#{username}/#{username}"
+ if Rails.configuration.auto_setup_new_users_with_repository and
+ Repository.where(name: repo_name).first.nil?
+ repo = Repository.create!(name: repo_name, owner_uuid: uuid)
+ Link.create!(tail_uuid: uuid, head_uuid: repo.uuid,
+ link_class: "permission", name: "can_manage")