devise_latcheable 0.0.2
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/Gemfile +3 -0
- data/app/controllers/devise_latcheable/registrations_controller.rb +9 -0
- data/app/views/devise_latcheable/registrations/new.html.erb +32 -0
- data/devise_latcheable.gemspec +29 -0
- data/lib/devise_latcheable.rb +13 -0
- data/lib/devise_latcheable/adapter.rb +34 -0
- data/lib/devise_latcheable/engine.rb +4 -0
- data/lib/devise_latcheable/model.rb +50 -0
- data/lib/devise_latcheable/strategy.rb +19 -0
- data/lib/devise_latcheable/version.rb +3 -0
- data/lib/generators/active_record/devise_latcheable_generator.rb +19 -0
- data/lib/generators/devise_latcheable/devise_latcheable_generator.rb +16 -0
- data/lib/generators/templates/README +15 -0
- data/lib/generators/templates/latch.yml +3 -0
- data/lib/generators/templates/migration.rb +6 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac3d2d79ef58d64be02863357e9918e77306d069
|
4
|
+
data.tar.gz: d7d0d3776541db5329a5b447347ee64a64c54acc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d73534e4516d884c987d0c496427283c0437c5fde09014e581bf6b3e124f8be4afc2f4747a38bf915b0ec000207bb1cea8873e242fe26764d56f4a90949e421
|
7
|
+
data.tar.gz: d70bf7d306e4dc8bedaa57ed621351133b2ac2f46413fd30c82c1e876f0f43da24ccdc12237fa538b2e19ce07d02724c26fbf15e9ee9b31fd55238a0dfc91c67
|
data/Gemfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
class DeviseLatcheable::RegistrationsController < Devise::RegistrationsController
|
2
|
+
before_filter :configure_permitted_parameters, :only => [:create]
|
3
|
+
|
4
|
+
protected
|
5
|
+
|
6
|
+
def configure_permitted_parameters
|
7
|
+
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :password_confirmation, :pair_code) }
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<h2>Sign up</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<div class="field">
|
7
|
+
<%= f.label :email %><br />
|
8
|
+
<%= f.email_field :email, autofocus: true %>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div class="field">
|
12
|
+
<%= f.label :password %>
|
13
|
+
<% if @minimum_password_length %>
|
14
|
+
<em>(<%= @minimum_password_length %> characters minimum)</em>
|
15
|
+
<% end %><br />
|
16
|
+
<%= f.password_field :password, autocomplete: "off" %>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class="field">
|
20
|
+
<%= f.label :password_confirmation %><br />
|
21
|
+
<%= f.password_field :password_confirmation, autocomplete: "off" %>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div class="field">
|
25
|
+
<%= f.label :pair_code %><br />
|
26
|
+
<%= f.text_field :pair_code, autocomplete: "off" %>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div class="actions">
|
30
|
+
<%= f.submit "Sign up" %>
|
31
|
+
</div>
|
32
|
+
<% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "devise_latcheable/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'devise_latcheable'
|
7
|
+
s.version = DeviseLatcheable::VERSION.dup
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.summary = 'Devise extension that checks Latch status to log users in the app'
|
10
|
+
s.email = 'crresse@gmail.com'
|
11
|
+
# s.homepage = ''
|
12
|
+
s.description = s.summary
|
13
|
+
s.authors = ['Carlos Rodriguez']
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency('devise', '>= 3.0')
|
22
|
+
s.add_dependency('latchsdk', '>= 1.1')
|
23
|
+
|
24
|
+
# s.add_development_dependency('rake', '>= 0.9')
|
25
|
+
# s.add_development_dependency('rdoc', '>= 3')
|
26
|
+
s.add_development_dependency('rails', '>= 4.0')
|
27
|
+
# s.add_development_dependency('sqlite3')
|
28
|
+
# s.add_development_dependency('rspec-rails')
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'latchsdk'
|
2
|
+
require 'devise'
|
3
|
+
require 'devise_latcheable/adapter'
|
4
|
+
require 'devise_latcheable/model'
|
5
|
+
require 'devise_latcheable/strategy'
|
6
|
+
require 'devise_latcheable/engine'
|
7
|
+
|
8
|
+
module DeviseLatcheable
|
9
|
+
end
|
10
|
+
|
11
|
+
Devise.add_module :latcheable,
|
12
|
+
route: :session, strategy: true,
|
13
|
+
controller: :sessions, model: 'devise_latcheable/model'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Devise
|
2
|
+
module Latch
|
3
|
+
@yaml_config = YAML.load(File.read("config/latch.yml"))
|
4
|
+
@latch_instance = ::Latch.new @yaml_config['app_id'], @yaml_config['app_secret']
|
5
|
+
|
6
|
+
# => Pairs an user with the server.
|
7
|
+
# @returns Account ID on success and nil on failure
|
8
|
+
def self.pair(code)
|
9
|
+
res = @latch_instance.pair code
|
10
|
+
return nil if res.data.nil?
|
11
|
+
res.data['accountId']
|
12
|
+
end
|
13
|
+
|
14
|
+
# => Checks if the app lock is open
|
15
|
+
def self.unlocked?(account_id)
|
16
|
+
res = @latch_instance.status account_id
|
17
|
+
return false unless res.error.nil?
|
18
|
+
|
19
|
+
key = res.data['operations'].keys.first
|
20
|
+
status = res.data['operations'][key]['status']
|
21
|
+
status == 'on'
|
22
|
+
end
|
23
|
+
|
24
|
+
# => Removes the pairing from lath
|
25
|
+
def self.unpair(account_id)
|
26
|
+
res = @latch_instance.unpair account_id
|
27
|
+
res.error.nil? ? true : false
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.config
|
31
|
+
@yaml_config
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Devise
|
2
|
+
module Models
|
3
|
+
module Latcheable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
# We only use pair code to pair the user with latch. Once it is
|
8
|
+
# paired, we dont need the pair code anymore, so we wont save
|
9
|
+
# it on the database
|
10
|
+
attr_accessor :pair_code
|
11
|
+
|
12
|
+
after_initialize :latch_enable
|
13
|
+
|
14
|
+
before_create :latch_pair!
|
15
|
+
before_destroy :latch_unpair!
|
16
|
+
end
|
17
|
+
|
18
|
+
def latch_enabled?
|
19
|
+
latch_enabled
|
20
|
+
end
|
21
|
+
|
22
|
+
def latch_unlocked?
|
23
|
+
return true unless latch_enabled?
|
24
|
+
return false if latch_account_id.nil?
|
25
|
+
Devise::Latch.unlocked? latch_account_id
|
26
|
+
end
|
27
|
+
|
28
|
+
def latch_unpair!
|
29
|
+
return true unless latch_enabled?
|
30
|
+
return true if latch_account_id.nil?
|
31
|
+
Devise::Latch.unpair latch_account_id
|
32
|
+
end
|
33
|
+
|
34
|
+
def latch_pair!
|
35
|
+
return true unless latch_enabled?
|
36
|
+
|
37
|
+
self.latch_account_id = Devise::Latch.pair pair_code
|
38
|
+
|
39
|
+
if latch_account_id.nil?
|
40
|
+
errors.add(:base, 'Invalid latch pair code')
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def latch_enable
|
46
|
+
self.latch_enabled = true if Devise::Latch.config['always_enabled'] == true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'devise/strategies/authenticatable'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Strategies
|
5
|
+
class Latcheable < Authenticatable
|
6
|
+
def authenticate!
|
7
|
+
resource = mapping.to.find_by(authentication_hash)
|
8
|
+
|
9
|
+
if resource && validate(resource) { resource.latch_unlocked? }
|
10
|
+
success! resource
|
11
|
+
else
|
12
|
+
fail 'Latch is locked. Unlock and try again.'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Warden::Strategies.add :latcheable, Devise::Strategies::Latcheable
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module Generators
|
5
|
+
class DeviseLatcheableGenerator < ActiveRecord::Generators::Base
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
desc 'Creates a migration'
|
8
|
+
class_option :orm
|
9
|
+
|
10
|
+
def copy_devise_latcheable_migration
|
11
|
+
migration_template "migration.rb", "db/migrate/add_devise_latcheable_to_#{table_name}.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
def copy_config
|
15
|
+
template "latch.yml", "config/latch.yml"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
3
|
+
module DeviseLatcheable
|
4
|
+
module Generators
|
5
|
+
class DeviseLatcheableGenerator < Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
namespace "devise_latcheable"
|
8
|
+
|
9
|
+
hook_for :orm
|
10
|
+
|
11
|
+
def show_readme
|
12
|
+
readme "README"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
======================================
|
3
|
+
Only two more steps to go:
|
4
|
+
|
5
|
+
1. Run rake db:migrate
|
6
|
+
|
7
|
+
2. Modify config/latch.yml
|
8
|
+
Paste your app id and your app secret code there
|
9
|
+
|
10
|
+
Latch is enabled by default in all instances.
|
11
|
+
|
12
|
+
If you want to use it only in certain instances, set 'always_enabled' to false
|
13
|
+
on your latch.yml file and set latch_enabled to true in the instance
|
14
|
+
that should be checked against Latch
|
15
|
+
======================================
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise_latcheable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carlos Rodriguez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: devise
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: latchsdk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
description: Devise extension that checks Latch status to log users in the app
|
56
|
+
email: crresse@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- Gemfile
|
62
|
+
- app/controllers/devise_latcheable/registrations_controller.rb
|
63
|
+
- app/views/devise_latcheable/registrations/new.html.erb
|
64
|
+
- devise_latcheable.gemspec
|
65
|
+
- lib/devise_latcheable.rb
|
66
|
+
- lib/devise_latcheable/adapter.rb
|
67
|
+
- lib/devise_latcheable/engine.rb
|
68
|
+
- lib/devise_latcheable/model.rb
|
69
|
+
- lib/devise_latcheable/strategy.rb
|
70
|
+
- lib/devise_latcheable/version.rb
|
71
|
+
- lib/generators/active_record/devise_latcheable_generator.rb
|
72
|
+
- lib/generators/devise_latcheable/devise_latcheable_generator.rb
|
73
|
+
- lib/generators/templates/README
|
74
|
+
- lib/generators/templates/latch.yml
|
75
|
+
- lib/generators/templates/migration.rb
|
76
|
+
homepage:
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.5
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Devise extension that checks Latch status to log users in the app
|
100
|
+
test_files: []
|