omniauth-registrar 0.0.2.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d049a4535878eaa2ae9047bfd23d23a973747b3
4
+ data.tar.gz: c2044bcb8215d4bfa01c24336d35ea84daca9c7c
5
+ SHA512:
6
+ metadata.gz: e3a211eaa6b8fe2be165d3a93f7716b94c72738421972d63f7cabae6676b3f86933369ea7606ad645caf072856a1b48a127f771b7d2f7252853078d1c1888e5b
7
+ data.tar.gz: f540c5df40b88b54ab4ab5fd91c49e2de3f41a84f988e0323ec023964dbbb6306c163189ff7fd2f4b2a5b03fbfed3f0b2d48f8a79f4aac1ed4877300526f70f3
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-registrar.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jan Owiesniak
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # OmniAuth::Registrar
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omniauth-registrar'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniauth-registrar
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/omniauth-registrar/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:specs) do |t|
5
+ t.libs << "spec"
6
+ t.test_files = FileList['spec/*_spec.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :specs
@@ -0,0 +1 @@
1
+ require 'omniauth/registrar'
@@ -0,0 +1,2 @@
1
+ require "omniauth/registrar/version"
2
+ require "omniauth/strategies/registrar"
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Registrar
3
+ VERSION = "0.0.2.alpha"
4
+ end
5
+ end
@@ -0,0 +1,166 @@
1
+ require 'omniauth'
2
+ require 'digest'
3
+ require 'omniauth/strategies/registrar/form'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Registrar
8
+ include ::OmniAuth::Strategy
9
+ AuthenticationError = Class.new(RuntimeError)
10
+
11
+ option :name, 'registrar'
12
+ option :fields, [:name, :email]
13
+
14
+ uid do
15
+ generate_uid(request.params['email'], request.params['password'])
16
+ end
17
+
18
+ info do
19
+ options.fields.inject({}) do |hash, field|
20
+ hash[field] = request.params[field.to_s]
21
+ hash
22
+ end
23
+ end
24
+
25
+ def request_phase
26
+ sign_up? ? build_sign_up_form : build_sign_in_form
27
+ end
28
+
29
+ def callback_phase
30
+ try_to_register
31
+ super
32
+ end
33
+
34
+ private
35
+
36
+ def generate_uid(*args)
37
+ Digest::SHA256.hexdigest(args.join(''))[0..19]
38
+ end
39
+
40
+ def build_sign_up_form
41
+ SignUpForm.new(sign_up_fields, callback_path).render
42
+ end
43
+
44
+ def build_sign_in_form
45
+ SignInForm.new(sign_in_fields, callback_path).render
46
+ end
47
+
48
+ def sign_up_fields
49
+ options.fields << 'password' << 'password_confirmation'
50
+ end
51
+
52
+ def sign_in_fields
53
+ ['email', 'password']
54
+ end
55
+
56
+ def try_to_register
57
+ if sign_up?
58
+ ensure_password_confirmed
59
+ ensure_password_confirmation_exists
60
+ ensure_password_exists
61
+ ensure_email_exists
62
+ ensure_name_exists
63
+ end
64
+
65
+ if sign_in?
66
+ ensure_password_exists
67
+ ensure_email_exists
68
+ end
69
+
70
+ validate!
71
+ end
72
+
73
+ def validate!
74
+ raise error if error?
75
+ end
76
+
77
+ def sign_up?
78
+ @env['QUERY_STRING'].match(/sign_up/) ||
79
+ !!request.params['password_confirmation']
80
+ end
81
+
82
+ def sign_in?
83
+ @env['QUERY_STRING'].match(/sign_in/) ||
84
+ !sign_up?
85
+ end
86
+
87
+ def ensure_name_exists
88
+ unless name?
89
+ fail_with AuthenticationError.new(missing('name'))
90
+ end
91
+ end
92
+
93
+ def ensure_email_exists
94
+ unless email?
95
+ fail_with AuthenticationError.new(missing('email'))
96
+ end
97
+ end
98
+
99
+ def ensure_password_exists
100
+ unless password?
101
+ fail_with AuthenticationError.new(missing('password'))
102
+ end
103
+ end
104
+
105
+ def ensure_password_confirmation_exists
106
+ unless password_confirmation?
107
+ fail_with AuthenticationError.new(missing('password_confirmation'))
108
+ end
109
+ end
110
+
111
+ def ensure_password_confirmed
112
+ unless password_confirmed?
113
+ fail_with AuthenticationError.new(confirm('password'))
114
+ end
115
+ end
116
+
117
+ def name?
118
+ exist?('name')
119
+ end
120
+
121
+ def email?
122
+ exist?('email')
123
+ end
124
+
125
+ def password?
126
+ exist?('password')
127
+ end
128
+
129
+ def password_confirmation?
130
+ exist?('password_confirmation')
131
+ end
132
+
133
+ def password_confirmed?
134
+ same?('password', 'password_confirmation')
135
+ end
136
+
137
+ def exist?(attr)
138
+ !!request.params[attr] && !request.params[attr].blank?
139
+ end
140
+
141
+ def same?(first, second)
142
+ request.params[first] == request.params[second]
143
+ end
144
+
145
+ def fail_with(exception)
146
+ env['omniauth.error'] = exception
147
+ end
148
+
149
+ def missing(key)
150
+ "authentication.errors.#{key}.missing"
151
+ end
152
+
153
+ def confirm(key)
154
+ "authentication.errors.#{key}.unconfirmed"
155
+ end
156
+
157
+ def error
158
+ env['omniauth.error']
159
+ end
160
+
161
+ def error?
162
+ !!error
163
+ end
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,103 @@
1
+ require 'omniauth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Registrar
6
+ class Form
7
+ def initialize(fields, callback_path)
8
+ @fields = fields
9
+ @callback_path = callback_path
10
+ end
11
+
12
+ def render
13
+ add_fields_to_form
14
+ add_submit_button_to_form
15
+ add_opposite_auth_link
16
+ to_html
17
+ end
18
+
19
+ private
20
+
21
+ def to_html
22
+ form.to_response
23
+ end
24
+
25
+ def add_opposite_auth_link
26
+ form.instance_variable_set('@html', html << opposite_link_tag)
27
+ end
28
+
29
+ def html
30
+ form.instance_variable_get('@html')
31
+ end
32
+
33
+ def opposite_link_tag
34
+ "\n<div style='text-align:center; margin:20px auto 0;'>" \
35
+ "or <a href='?#{opposite_type}'>#{opposite_title}</a></div>"
36
+ end
37
+
38
+ def add_submit_button_to_form
39
+ form.button title
40
+ end
41
+
42
+ def add_fields_to_form
43
+ fields.each do |field|
44
+ form.text_field field.to_s.capitalize.gsub('_', ' '), field.to_s
45
+ end
46
+ end
47
+
48
+ def callback_path
49
+ @callback_path
50
+ end
51
+
52
+ def fields
53
+ @fields
54
+ end
55
+
56
+ def form
57
+ @form ||= OmniAuth::Form.new(:title => title, :url => callback_path)
58
+ end
59
+ end
60
+
61
+ class SignInForm < Form
62
+ private
63
+
64
+ def title
65
+ @title ||= "Sign In"
66
+ end
67
+
68
+ def opposite_title
69
+ @opposite_title ||= "Sign Up"
70
+ end
71
+
72
+ def type
73
+ @type ||= :sign_in
74
+ end
75
+
76
+ def opposite_type
77
+ @opposite_type ||= :sign_up
78
+ end
79
+ end
80
+
81
+ class SignUpForm < Form
82
+ private
83
+
84
+ def title
85
+ @title ||= "Sign Up"
86
+ end
87
+
88
+ def opposite_title
89
+ @opposite_title ||= "Sign In"
90
+ end
91
+
92
+ def type
93
+ @type ||= :sign_up
94
+ end
95
+
96
+ def opposite_type
97
+ @opposite_type ||= :sign_in
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth/registrar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-registrar"
8
+ spec.version = OmniAuth::Registrar::VERSION
9
+ spec.authors = ["Jan Owiesniak"]
10
+ spec.email = ["jan@featurefabrik.de"]
11
+ spec.summary = %q{OmniAuth strategy to simplify sign up / sign in process}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "omniauth"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-registrar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Jan Owiesniak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - jan@featurefabrik.de
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/omniauth-registrar.rb
68
+ - lib/omniauth/registrar.rb
69
+ - lib/omniauth/registrar/version.rb
70
+ - lib/omniauth/strategies/registrar.rb
71
+ - lib/omniauth/strategies/registrar/form.rb
72
+ - omniauth-registrar.gemspec
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">"
89
+ - !ruby/object:Gem::Version
90
+ version: 1.3.1
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: OmniAuth strategy to simplify sign up / sign in process
97
+ test_files: []