Class: GitAuth::WebApp
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- GitAuth::WebApp
- Includes:
- Loggable
- Defined in:
- lib/gitauth/web_app.rb
Class Method Summary collapse
- .check_auth ⇒ Object
- .has_auth? ⇒ Boolean
- .run(options = {}) ⇒ Object
- .stop ⇒ Object
- .update_auth ⇒ Object
Instance Method Summary collapse
-
#root_with_message(message) ⇒ Object
Misc Helpers.
Class Method Details
.check_auth ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gitauth/web_app.rb', line 60 def self.check_auth GitAuth.prepare if !has_auth? if $stderr.tty? logger.verbose = true puts "For gitauth to continue, you need to provide a username and password." update_auth else logger.fatal "You need to provide a username and password for GitAuth to function; Please run 'gitauth webapp` once" exit! end end end |
.has_auth? ⇒ Boolean
29 30 31 32 33 |
# File 'lib/gitauth/web_app.rb', line 29 def self.has_auth? username = GitAuth::Settings["web_username"] password = GitAuth::Settings["web_password_hash"] !(username.blank? || password.blank?) end |
.run(options = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gitauth/web_app.rb', line 74 def self.run( = {}) check_auth set handler = detect_rack_handler handler_name = handler.name.gsub(/.*::/, '') logger.info "Starting up web server on #{port}" handler.run self, :Port => port do |server| GitAuth::WebApp.current_server = server set :running, true end rescue Errno::EADDRINUSE => e logger.fatal "Server is already running on port #{port}" end |
.stop ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/gitauth/web_app.rb', line 88 def self.stop if current_server.present? current_server.respond_to?(:stop!) ? current_server.stop! : current_server.stop end exit! logger.debug "Stopped Server." end |
.update_auth ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gitauth/web_app.rb', line 35 def self.update_auth raw_username = Readline.readline('GitAuth Username (default is \'gitauth\'): ') raw_username = 'gitauth' if raw_username.blank? raw_password = '' while raw_password.blank? system "stty -echo" raw_password = Readline.readline('GitAuth Password: ') system "stty echo" print "\n" puts "You need to provide a password, please try again" if raw_password.blank? end password_confirmation = nil while password_confirmation != raw_password system "stty -echo" password_confirmation = Readline.readline('Confirm Password: ') system "stty echo" print "\n" puts "The confirmation doesn't match your password, please try again" if raw_password != password_confirmation end GitAuth::Settings.update!({ :web_username => raw_username, :web_password_hash => Digest::SHA256.hexdigest(raw_password) }) end |
Instance Method Details
#root_with_message(message) ⇒ Object
Misc Helpers
309 310 311 |
# File 'lib/gitauth/web_app.rb', line 309 def () u("/?message=#{URI.encode(message)}") end |