Class: PhraseApp::Auth::AuthHandler

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/auth.rb

Instance Method Summary collapse

Instance Method Details

#load_configObject



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

def load_config
  path = self.config
  tmpA = AuthHandler.new

  puts path
  if path && File.exists?(path)
    content = File.read(path)
    tmpA = AuthHandler.new(JSON.load(content))
  end

  # Only set token if username not specified on commandline.
  if tmpA.token && tmpA.token != "" && self.token.nil? && self.username.nil?
    self.token = tmpA.token
  elsif tmpA.username && tmpA.username != "" && self.username.nil?
    self.username = tmpA.username
  elsif tmpA.password && tmpA.password != "" && self.password.nil?
    self.password = tmpA.password
  end

  if tmpA.tfa && self.tfa == ""
    self.tfa = tmpA.tfa
  end

  return nil
end

#validateObject



5
6
7
8
9
10
11
# File 'lib/auth.rb', line 5

def validate
  if self.username == "" && self.token == ""
    return raise("either username or token must be given")
  else
    return nil
  end
end