Created
January 14, 2011 23:20
-
-
Save meineerde/780481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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