hector-identity-ee 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/hector/ee_identity_adapter.rb +29 -21
  2. metadata +30 -50
@@ -1,8 +1,7 @@
1
- require "digest/sha1"
2
1
  require "yaml"
3
2
 
4
3
  begin
5
- require "sequel"
4
+ require "mysql2"
6
5
  rescue LoadError => e
7
6
  if require "rubygems"
8
7
  retry
@@ -11,19 +10,17 @@ rescue LoadError => e
11
10
  end
12
11
  end
13
12
 
14
-
15
13
  module Hector
16
14
  class ExpressionEngineIdentityAdapter
17
- attr_reader :filename, :config, :db
15
+ attr_reader :config, :database
18
16
 
19
17
  def initialize(filename = nil)
20
- @filename = filename || Hector.root.join("config/expression_engine.yml")
21
- load_config
18
+ load_config(filename || Hector.root.join("config/expression_engine.yml"))
22
19
  load_database
23
20
  end
24
21
 
25
22
  def authenticate(username, password)
26
- yield identity(normalize(username)) == hash(password)
23
+ yield normalize(identity(normalize(username))) == normalize(password)
27
24
  end
28
25
 
29
26
  def remember(username, password)
@@ -36,37 +33,48 @@ module Hector
36
33
  false
37
34
  end
38
35
 
39
- def normalize(username)
40
- username.strip.downcase
41
- end
42
-
43
36
  protected
44
- def load_config
37
+ def load_config(filename)
45
38
  @config = YAML.load_file(filename)
46
39
  rescue => e
47
- Hector.logger.fatal "Could not load #{filename} (#{e.class.name})"
40
+ Hector.logger.fatal "#{e.class.name} while loading #{filename}: #{e.message}"
48
41
  exit 1
49
42
  end
50
43
 
51
44
  def load_database
52
- @db = Sequel.mysql2(config["database"])
45
+ @database = Mysql2::Client.new(connection_params)
53
46
  rescue => e
54
- Hector.logger.fatal "Could not connect to ExpressionEngine database: #{e.message} (#{e.class.name})"
47
+ Hector.logger.fatal "#{e.class.name} while connecting to ExpressionEngine database: #{e.message}"
55
48
  exit 1
56
49
  end
57
50
 
51
+ def connection_params
52
+ config["database"].inject({}) do |hash, (key, value)|
53
+ hash[key.to_sym] = value; hash
54
+ end
55
+ end
56
+
58
57
  def identity(username)
59
- query = { :hector_username => username }
60
- query[:group_id] = config["groups"] if config["groups"]
61
- (table(:members).select(:password).first(query) || {})[:password]
58
+ sql = "SELECT hector_password FROM #{table(:members)} WHERE hector_username = '#{escape(username)}'"
59
+ sql << " AND group_id IN (#{config["groups"].join(",")})" if config["groups"]
60
+ (query(sql).first || {})["hector_password"]
62
61
  end
63
62
 
64
63
  def table(name)
65
- db["#{(config["prefix"] || "exp")}_#{name}"]
64
+ "#{config["prefix"] || "exp"}_#{name}"
65
+ end
66
+
67
+ def escape(input)
68
+ database.escape(input)
69
+ end
70
+
71
+ def query(sql)
72
+ Hector.logger.debug(sql.inspect)
73
+ database.query(sql)
66
74
  end
67
75
 
68
- def hash(password)
69
- Digest::SHA1.hexdigest(password)
76
+ def normalize(input)
77
+ input.strip.downcase
70
78
  end
71
79
  end
72
80
  end
metadata CHANGED
@@ -1,78 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hector-identity-ee
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
4
5
  prerelease:
5
- version: 2.0.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Ross Paffett
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-08-07 00:00:00 -04:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: sequel
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
20
- none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: 3.26.0
25
- type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
12
+ date: 2011-08-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
28
15
  name: mysql2
29
- prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
16
+ requirement: &70292475371600 !ruby/object:Gem::Requirement
31
17
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: 0.3.6
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.7
36
22
  type: :runtime
37
- version_requirements: *id002
38
- description: An identity adapter which allows users to log into a Hector IRC server using their ExpressionEngine credentials.
39
- email:
23
+ prerelease: false
24
+ version_requirements: *70292475371600
25
+ description: An identity adapter which allows users to log into a Hector IRC server
26
+ using their ExpressionEngine credentials.
27
+ email:
40
28
  - ross@rosspaffett.com
41
29
  executables: []
42
-
43
30
  extensions: []
44
-
45
31
  extra_rdoc_files: []
46
-
47
- files:
32
+ files:
48
33
  - lib/hector/ee_identity_adapter.rb
49
- has_rdoc: true
50
34
  homepage: http://github.com/raws/hector-identity-ee
51
35
  licenses: []
52
-
53
36
  post_install_message:
54
37
  rdoc_options: []
55
-
56
- require_paths:
38
+ require_paths:
57
39
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
40
+ required_ruby_version: !ruby/object:Gem::Requirement
59
41
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
47
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
70
52
  requirements: []
71
-
72
53
  rubyforge_project:
73
- rubygems_version: 1.6.2
54
+ rubygems_version: 1.8.7
74
55
  signing_key:
75
56
  specification_version: 3
76
57
  summary: ExpressionEngine identity adapter for Hector
77
58
  test_files: []
78
-