Skip to content

Instantly share code, notes, and snippets.

@meineerde
Created January 14, 2011 23:20
Show Gist options
  • Select an option

  • Save meineerde/780481 to your computer and use it in GitHub Desktop.

Select an option

Save meineerde/780481 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby /path/to/redmine/script/runner
login = ARGV[0]
if User.find_by_login(login)
puts "User #{login} already exists"
exit(1)
end
# Try all LDAP auth sources
AuthSourceLdap.all.find do |auth_source|
attrs = auth_source.send(:get_user_dn, login)
attrs.include?(:auth_source_id) ? attrs : nil
end
# no user found
unless attrs
puts "User #{login} not found in LDAP."
exit(1)
end
# create the user in the database
user = User.new(attrs)
user.login = login
user.language = Setting.default_language
if user.save
puts "Successfully created user #{login}."
else
puts "An error occured during creation of user #{login}."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment