oa-core 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/omniauth/core.rb +30 -14
  2. data/lib/omniauth/form.rb +145 -0
  3. metadata +4 -3
data/lib/omniauth/core.rb CHANGED
@@ -1,16 +1,27 @@
1
1
  require 'rack'
2
2
  require 'singleton'
3
3
 
4
+ require 'omniauth/form'
5
+
4
6
  module OmniAuth
5
7
  class Configuration
6
8
  include Singleton
7
9
 
8
- def initialize
9
- @path_prefix = '/auth'
10
- @on_failure = Proc.new do |env, message_key|
10
+ @@defaults = {
11
+ :path_prefix => '/auth',
12
+ :on_failure => Proc.new do |env, message_key|
11
13
  new_path = "#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
12
14
  [302, {'Location' => "#{new_path}"}, []]
13
- end
15
+ end,
16
+ :form_css => Form::DEFAULT_CSS
17
+ }
18
+
19
+ def self.defaults
20
+ @@defaults
21
+ end
22
+
23
+ def initialize
24
+ @@defaults.each_pair{|k,v| self.send("#{k}=",v)}
14
25
  end
15
26
 
16
27
  def on_failure(&block)
@@ -21,7 +32,8 @@ module OmniAuth
21
32
  end
22
33
  end
23
34
 
24
- attr_accessor :path_prefix
35
+ attr_writer :on_failure
36
+ attr_accessor :path_prefix, :form_css
25
37
  end
26
38
 
27
39
  def self.config
@@ -33,7 +45,19 @@ module OmniAuth
33
45
  end
34
46
 
35
47
  module Utils
36
- extend self
48
+ CAMELIZE_SPECIAL = {
49
+ 'oauth' => 'OAuth',
50
+ 'oauth2' => 'OAuth2',
51
+ 'openid' => 'OpenID',
52
+ 'open_id' => 'OpenID',
53
+ 'github' => 'GitHub'
54
+ }
55
+
56
+ module_function
57
+
58
+ def form_css
59
+ "<style type='text/css'>#{OmniAuth.config.form_css}</style>"
60
+ end
37
61
 
38
62
  def deep_merge(hash, other_hash)
39
63
  target = hash.dup
@@ -50,14 +74,6 @@ module OmniAuth
50
74
  target
51
75
  end
52
76
 
53
- CAMELIZE_SPECIAL = {
54
- 'oauth' => 'OAuth',
55
- 'oauth2' => 'OAuth2',
56
- 'openid' => 'OpenID',
57
- 'open_id' => 'OpenID',
58
- 'github' => 'GitHub'
59
- }
60
-
61
77
  def camelize(word, first_letter_in_uppercase = true)
62
78
  return CAMELIZE_SPECIAL[word.to_s] if CAMELIZE_SPECIAL[word.to_s]
63
79
 
@@ -0,0 +1,145 @@
1
+ module OmniAuth
2
+ class Form
3
+ DEFAULT_CSS = <<-CSS
4
+ body {
5
+ background: #ccc;
6
+ font-family: "Lucida Grande", "Lucida Sans", Helvetica, Arial, sans-serif;
7
+ }
8
+
9
+ h1 {
10
+ text-align: center;
11
+ margin: 30px auto 0px;
12
+ font-size: 18px;
13
+ padding: 10px 10px 15px;
14
+ background: #555;
15
+ color: white;
16
+ width: 320px;
17
+ border: 10px solid #444;
18
+ border-bottom: 0;
19
+ -moz-border-radius-topleft: 10px;
20
+ -moz-border-radius-topright: 10px;
21
+ -webkit-border-top-left-radius: 10px;
22
+ -webkit-border-top-right-radius: 10px;
23
+ border-top-left-radius: 10px;
24
+ border-top-right-radius: 10px;
25
+ }
26
+
27
+ h1, form {
28
+ -moz-box-shadow: 2px 2px 7px rgba(0,0,0,0.3);
29
+ -webkit-box-shadow: 2px 2px 7px rgba(0,0,0,0.3);
30
+ }
31
+
32
+ form {
33
+ background: white;
34
+ border: 10px solid #eee;
35
+ border-top: 0;
36
+ padding: 20px;
37
+ margin: 0px auto 40px;
38
+ width: 300px;
39
+ -moz-border-radius-bottomleft: 10px;
40
+ -moz-border-radius-bottomright: 10px;
41
+ -webkit-border-bottom-left-radius: 10px;
42
+ -webkit-border-bottom-right-radius: 10px;
43
+ border-bottom-left-radius: 10px;
44
+ border-bottom-right-radius: 10px;
45
+ }
46
+
47
+ label {
48
+ display: block;
49
+ font-weight: bold;
50
+ margin-bottom: 5px;
51
+ }
52
+
53
+ input {
54
+ font-size: 18px;
55
+ padding: 4px 8px;
56
+ display: block;
57
+ margin-bottom: 10px;
58
+ width: 280px;
59
+ }
60
+
61
+ button {
62
+ font-size: 22px;
63
+ padding: 4px 8px;
64
+ display: block;
65
+ margin: 20px auto 0;
66
+ }
67
+ CSS
68
+
69
+ def initialize(title=nil)
70
+ title ||= "Authentication Info Required"
71
+ @html = ""
72
+ header(title)
73
+ end
74
+
75
+ def self.build(title=nil, &block)
76
+ form = OmniAuth::Form.new(title)
77
+ form.instance_eval(&block)
78
+ end
79
+
80
+ def label_field(text, target)
81
+ @html << "\n<label for='#{target}'>#{text}:</label>"
82
+ self
83
+ end
84
+
85
+ def input_field(type, name)
86
+ @html << "\n<input type='#{type}' id='#{name}' name='#{name}'/>"
87
+ self
88
+ end
89
+
90
+ def text_field(label, name)
91
+ label_field(label, name)
92
+ input_field('text', name)
93
+ self
94
+ end
95
+
96
+ def password_field(label, name)
97
+ label_field(label, name)
98
+ input_field('password', name)
99
+ self
100
+ end
101
+
102
+ def header(title)
103
+ @html << <<-HTML
104
+ <!DOCTYPE html>
105
+ <html>
106
+ <head>
107
+ <title>#{title}</title>
108
+ #{css}
109
+ </head>
110
+ <body>
111
+ <h1>#{title}</h1>
112
+ <form method='post'>
113
+ HTML
114
+ self
115
+ end
116
+
117
+ def footer
118
+ return self if @footer
119
+ @html << <<-HTML
120
+ <button type='submit'>Connect</button>
121
+ </form>
122
+ </body>
123
+ </html>
124
+ HTML
125
+ @footer = true
126
+ self
127
+ end
128
+
129
+ def to_html
130
+ footer
131
+ @html
132
+ end
133
+
134
+ def to_response
135
+ footer
136
+ Rack::Response.new(@html).finish
137
+ end
138
+
139
+ protected
140
+
141
+ def css
142
+ "\n<style type='text/css'>#{OmniAuth.config.form_css}</style>"
143
+ end
144
+ end
145
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Bleigh
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-29 00:00:00 -04:00
17
+ date: 2010-05-01 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -90,6 +90,7 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - lib/omniauth/builder.rb
92
92
  - lib/omniauth/core.rb
93
+ - lib/omniauth/form.rb
93
94
  - lib/omniauth/password.rb
94
95
  - lib/omniauth/strategies/password.rb
95
96
  - lib/omniauth/strategy.rb