tenzing 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +10 -0
- data/lib/tenzing.rb +7 -0
- data/lib/tenzing/localizer.rb +28 -0
- data/lib/tenzing/oauth_extract.rb +48 -0
- data/lib/tenzing/oauth_registration.rb +45 -0
- data/lib/tenzing/version.rb +3 -0
- data/spec/localizer_spec.rb +11 -0
- data/spec/oauth_extract_spec.rb +23 -0
- data/spec/oauth_registration_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/tenzing_spec.rb +5 -0
- data/tenzing.gemspec +32 -0
- metadata +208 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1deb6db0d08df1f8a07d5326d36eb6214519f893
|
4
|
+
data.tar.gz: 3681b32fc774e36ef124a91b782d37525a00bd12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c43e707999dbd14704ae92295b0595234ebfdf12e7eab055b538b2e0f8631f5632bb08a2cbed297be9cb80693e0cc4e1f0254144f9958cce4b3861e5fa31e1be
|
7
|
+
data.tar.gz: 2e4fb442391ebef6d22bb39b8ace142cb2ac6ce128a161c26f455d12b4400db97fba7fcd4272c1f6b0dc4b9b44f7ba8031af263305cc87eff84966b9e06296cd
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.idea/
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Alvaro Naveda
|
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,29 @@
|
|
1
|
+
# Tenzing
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tenzing'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tenzing
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/tenzing/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
task.rspec_opts = ['--color', '--format', 'nested']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :spec
|
data/lib/tenzing.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Tenzing
|
4
|
+
module Localizer
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
before_filter :set_locale
|
9
|
+
rescue_from I18n::InvalidLocale, with: :invalid_locale
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_locale
|
13
|
+
locale = params[:lang]
|
14
|
+
locale ||= session[:locale]
|
15
|
+
locale ||= ((lang = request.env['HTTP_ACCEPT_LANGUAGE']) && lang[/^[a-z]{2}/])
|
16
|
+
locale ||= I18n.default_locale
|
17
|
+
|
18
|
+
I18n.locale = locale
|
19
|
+
session[:locale] = I18n.locale
|
20
|
+
end
|
21
|
+
|
22
|
+
def invalid_locale(e)
|
23
|
+
flash[:error] = e.message
|
24
|
+
redirect_to root_url
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Tenzing
|
2
|
+
module OauthExtract
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_filter :parse_request
|
7
|
+
before_filter :get_oauth_data
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse_request
|
11
|
+
@oauth = request.env['omniauth.auth']
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_oauth_data
|
15
|
+
return nil unless @oauth.present?
|
16
|
+
@oauth_data = {
|
17
|
+
user: {
|
18
|
+
email: @oauth.info['email'],
|
19
|
+
name: @oauth.info['name'],
|
20
|
+
image: @oauth.info['image'],
|
21
|
+
},
|
22
|
+
auth: {
|
23
|
+
provider: @oauth.provider,
|
24
|
+
uid: @oauth.uid,
|
25
|
+
username: @oauth.info['nickname'],
|
26
|
+
auth_token: @oauth.credentials['token'],
|
27
|
+
auth_secret: @oauth.credentials['secret'],
|
28
|
+
expires_at: parse_expiration_date(@oauth),
|
29
|
+
}
|
30
|
+
}
|
31
|
+
raise 'Unable to get OAuth2 data' if @oauth_data.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def parse_expiration_date(data)
|
36
|
+
expires_at = data.credentials['expires_at']
|
37
|
+
return expires_at if expires_at.present?
|
38
|
+
|
39
|
+
# LinkedIn only indicates expires_in attribute
|
40
|
+
expires_in = data.extra.access_token.params['oauth_expires_in']
|
41
|
+
expires_at = Time.now.to_i + expires_in.to_i
|
42
|
+
return expires_at if expires_at.present?
|
43
|
+
|
44
|
+
raise 'Unable to parse OAuth2 expires_at attribute'
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Tenzing
|
2
|
+
module OauthRegistration
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
# TODO: Revisar login desde Google eligiendo otra cuenta ya teniendo una añadida
|
6
|
+
def register_user(data)
|
7
|
+
auth = Authentication.where(
|
8
|
+
uid: data[:auth][:uid], provider: data[:auth][:provider]
|
9
|
+
).first_or_initialize
|
10
|
+
|
11
|
+
if auth.user.present?
|
12
|
+
# Sign in the authentication user
|
13
|
+
flash[:notice] = I18n.t('logged', scope: %w(users auth register), provider: @provider)
|
14
|
+
sign_in_and_redirect(auth.user, :event => :authentication)
|
15
|
+
else
|
16
|
+
# NO EXISTE AUTHENTICATION -> COMPROBAR EMAIL
|
17
|
+
if user = User.find_by_email(data[:user][:email])
|
18
|
+
# SI EXISTE EMAIL -> SE AÑADE AUTHENTICATION
|
19
|
+
status = user.add_account(@oauth_data)
|
20
|
+
flash[:notice] = I18n.t(status, scope: %w(users auth register login), provider: @provider)
|
21
|
+
sign_in_and_redirect(user, :event => :authentication)
|
22
|
+
else
|
23
|
+
# NO EXISTE EMAIL -> SE REGISTRA
|
24
|
+
auth.auth_token = data[:auth][:auth_token]
|
25
|
+
auth.auth_secret = data[:auth][:auth_token]
|
26
|
+
auth.build_user(
|
27
|
+
email: data[:user][:email],
|
28
|
+
name: data[:user][:name],
|
29
|
+
password: (temp_pass = SecureRandom.hex(10)),
|
30
|
+
password_confirmation: temp_pass,
|
31
|
+
terms: '1', # Acceptance terms
|
32
|
+
# TODO: Fix SSL problem in development
|
33
|
+
avatar: (open(data[:user][:image], allow_redirections: :safe) rescue nil)
|
34
|
+
)
|
35
|
+
auth.user.skip_confirmation!
|
36
|
+
auth.user.save!
|
37
|
+
auth.save!
|
38
|
+
flash[:notice] = I18n.t('registered', scope: %w(users auth register), provider: @provider)
|
39
|
+
sign_in_and_redirect(auth.user, :event => :authentication)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tenzing::OauthExtract do
|
4
|
+
|
5
|
+
describe 'parse_request' do
|
6
|
+
it 'parse request omniauth data' do
|
7
|
+
pending
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'get_oauth_data' do
|
12
|
+
it 'get oauth data from parsed request' do
|
13
|
+
pending
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'parse_expiration_date' do
|
18
|
+
it 'parses expiration date for oauth process' do
|
19
|
+
pending
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tenzing.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tenzing/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'tenzing'
|
8
|
+
spec.version = Tenzing::VERSION
|
9
|
+
spec.authors = ['Alvaro Naveda']
|
10
|
+
spec.email = ['alvaro.naveda@urbegi.com']
|
11
|
+
spec.summary = 'Include code that is used in most projects'
|
12
|
+
spec.description = 'Include code that is used in most projects, such as OAuth2 identification or language changes'
|
13
|
+
spec.homepage = 'http://tenzing.urbegi.com'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'rspec-nc'
|
25
|
+
spec.add_development_dependency 'guard'
|
26
|
+
spec.add_development_dependency 'guard-rspec'
|
27
|
+
spec.add_development_dependency 'pry'
|
28
|
+
spec.add_development_dependency 'pry-remote'
|
29
|
+
spec.add_development_dependency 'pry-nav'
|
30
|
+
|
31
|
+
spec.add_dependency 'activesupport'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tenzing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alvaro Naveda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-nc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-remote
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-nav
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: activesupport
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Include code that is used in most projects, such as OAuth2 identification
|
154
|
+
or language changes
|
155
|
+
email:
|
156
|
+
- alvaro.naveda@urbegi.com
|
157
|
+
executables: []
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- ".gitignore"
|
162
|
+
- ".travis.yml"
|
163
|
+
- Gemfile
|
164
|
+
- Guardfile
|
165
|
+
- LICENSE.txt
|
166
|
+
- README.md
|
167
|
+
- Rakefile
|
168
|
+
- lib/tenzing.rb
|
169
|
+
- lib/tenzing/localizer.rb
|
170
|
+
- lib/tenzing/oauth_extract.rb
|
171
|
+
- lib/tenzing/oauth_registration.rb
|
172
|
+
- lib/tenzing/version.rb
|
173
|
+
- spec/localizer_spec.rb
|
174
|
+
- spec/oauth_extract_spec.rb
|
175
|
+
- spec/oauth_registration_spec.rb
|
176
|
+
- spec/spec_helper.rb
|
177
|
+
- spec/tenzing_spec.rb
|
178
|
+
- tenzing.gemspec
|
179
|
+
homepage: http://tenzing.urbegi.com
|
180
|
+
licenses:
|
181
|
+
- MIT
|
182
|
+
metadata: {}
|
183
|
+
post_install_message:
|
184
|
+
rdoc_options: []
|
185
|
+
require_paths:
|
186
|
+
- lib
|
187
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
requirements: []
|
198
|
+
rubyforge_project:
|
199
|
+
rubygems_version: 2.2.2
|
200
|
+
signing_key:
|
201
|
+
specification_version: 4
|
202
|
+
summary: Include code that is used in most projects
|
203
|
+
test_files:
|
204
|
+
- spec/localizer_spec.rb
|
205
|
+
- spec/oauth_extract_spec.rb
|
206
|
+
- spec/oauth_registration_spec.rb
|
207
|
+
- spec/spec_helper.rb
|
208
|
+
- spec/tenzing_spec.rb
|