Class: GitAuth::ApacheAuthentication

Inherits:
Object
  • Object
show all
Defined in:
lib/gitauth/apache_authentication.rb

Constant Summary collapse

PUBLIC_DIR =
GitAuth::BASE_DIR.join("public")

Class Method Summary collapse

Class Method Details

.removeObject



42
43
44
45
46
# File 'lib/gitauth/apache_authentication.rb', line 42

def remove
  PUBLIC_DIR.join(".htaccess").delete
  PUBLIC_DIR.join(".htpasswd").delete
rescue Errno::ENOENT
end

.setupObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitauth/apache_authentication.rb', line 14

def setup
  GitAuth::WebApp.check_auth
  puts "To continue, we require you re-enter the password you wish to use."
  raw_password  = ''
  password_hash = ''
  existing_hash = GitAuth::Settings.web_password_hash
  while raw_password.blank? && password_hash != existing_hash
    raw_password  = read_password('GitAuth Password: ')
    password_hash = sha256_password(raw_password)
    if raw_password.blank?
      puts "You need to provide a password, please try again"
    elsif password_hash != existing_hash
      puts "Your password doesn't match the stored password. Please try again."
    end
  end
  raw_username = GitAuth::Settings.web_username
  encoded_password = "{SHA}#{[Digest::SHA1.digest(raw_password)].pack('m').strip}"
  File.open(PUBLIC_DIR.join(".htpasswd"), "w+") do |file|
    file.puts "#{raw_username}:#{encoded_password}"
  end
  File.open(PUBLIC_DIR.join(".htaccess"), "w+") do |file|
    file.puts "AuthType Basic"
    file.puts "AuthName \"GitAuth\""
    file.puts "AuthUserFile #{PUBLIC_DIR.join(".htpasswd").expand_path}"
    file.puts "Require valid-user"
  end
end

.setup?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/gitauth/apache_authentication.rb', line 10

def setup?
  PUBLIC_DIR.join(".htaccess").file? && PUBLIC_DIR.join(".htpasswd").file?
end