instant_login 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/MIT-LICENSE +20 -0
- data/Rakefile +24 -0
- data/app/assets/javascripts/instant_login/application.js +13 -0
- data/app/assets/javascripts/instant_login/instant_login.js +2 -0
- data/app/assets/javascripts/instant_login/instant_login_controller.js +2 -0
- data/app/assets/stylesheets/instant_login/application.css +15 -0
- data/app/assets/stylesheets/instant_login/instant_login.css +4 -0
- data/app/assets/stylesheets/instant_login/instant_login_controller.css +4 -0
- data/app/controllers/instant_login/application_controller.rb +4 -0
- data/app/controllers/instant_login/instant_login_controller.rb +26 -0
- data/app/mailers/instant_login/user_mailer.rb +10 -0
- data/app/views/instant_login/user_mailer/token.text.erb +3 -0
- data/config/routes.rb +4 -0
- data/lib/generators/instant_login/install_generator.rb +42 -0
- data/lib/generators/instant_login/templates/initializer.rb +4 -0
- data/lib/generators/instant_login/templates/migration.rb +8 -0
- data/lib/instant_login/adapters/active_record.rb +36 -0
- data/lib/instant_login/engine.rb +14 -0
- data/lib/instant_login/version.rb +3 -0
- data/lib/instant_login.rb +25 -0
- data/lib/tasks/instant_login_tasks.rake +4 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 63d9881efedbd05d9c96ca87756e435a89f65352
|
4
|
+
data.tar.gz: 6e7636bae15eaa0a401c3d37ea726d35581cbd80
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6113a118a8e03b2a97666d0cb559853486b278632f5658f5df1ac4c1c809c5b2a64bdaacc95bd1d69fb9684caf4d56adb8d1c9855ae2580afb5a5823e4df4f79
|
7
|
+
data.tar.gz: ecc87df45e8292d907a609a18119ebfc435b4ae9504a184327c63cae96b3a7588879c852c163453963a5fcdf25aea83ba2be7f8ebac415fcd7f66785c6c2d0b2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'InstantLogin'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rspec/core/rake_task'
|
23
|
+
task :default => :spec
|
24
|
+
RSpec::Core::RakeTask.new
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_dependency 'instant_login/application_controller'
|
2
|
+
|
3
|
+
module InstantLogin
|
4
|
+
class InstantLoginController < ApplicationController
|
5
|
+
def generate_token
|
6
|
+
user = InstantLogin.config.user_class.find_by(email: params[:email])
|
7
|
+
if user
|
8
|
+
user.generate_instant_login_token
|
9
|
+
InstantLogin.config.mailer_class.token(user).deliver
|
10
|
+
redirect_to '/', notice: 'Login email sent'
|
11
|
+
else
|
12
|
+
redirect_to '/', alert: 'User not found'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def login
|
17
|
+
user = InstantLogin.config.user_class.authenticate_with_instant_login_token(params[:token])
|
18
|
+
if user.present?
|
19
|
+
session[InstantLogin.config.session_key] = user.id
|
20
|
+
redirect_to InstantLogin.config.success_path, notice: 'Logged in'
|
21
|
+
else
|
22
|
+
redirect_to InstantLogin.config.failure_path, alert: 'Login failed'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module InstantLogin
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
class_option :model, :optional => true, :type => :string, :banner => "model",
|
11
|
+
:desc => "Specify the model class name if you will use anything other than 'User'"
|
12
|
+
class_option :migration, :optional => true, :type => :boolean, :banner => "no-migration", :default => true,
|
13
|
+
:desc => "Specify if you do not want to generate a migration file"
|
14
|
+
|
15
|
+
def copy_initializer_files
|
16
|
+
template "initializer.rb", "config/initializers/instant_login.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_migration_files
|
20
|
+
migration_template "migration.rb", "db/migrate/instant_login.rb" if options["migration"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.next_migration_number(dirname)
|
24
|
+
if ActiveRecord::Base.timestamped_migrations
|
25
|
+
sleep 1 # make sure each time we get a different timestamp
|
26
|
+
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
27
|
+
else
|
28
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def model_class_name
|
34
|
+
options[:model] ? options[:model].classify : "User"
|
35
|
+
end
|
36
|
+
|
37
|
+
def model_path
|
38
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class InstantLoginMigration < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :<%= model_class_name.tableize %>, :instant_login_token, :string
|
4
|
+
add_column :<%= model_class_name.tableize %>, :instant_login_token_created_at, :string
|
5
|
+
|
6
|
+
add_index :<%= model_class_name.tableize %>, :instant_login_token, unique: true
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'securerandom'
|
3
|
+
module InstantLogin
|
4
|
+
module Adapters
|
5
|
+
module ActiveRecord
|
6
|
+
module Setup
|
7
|
+
def uses_instant_login!
|
8
|
+
self.send(:include, Methods)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Methods
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
included do
|
15
|
+
scope :valid_tokens, -> { where('instant_login_token_created_at >= ?', 15.minutes.ago) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate_instant_login_token
|
19
|
+
update(instant_login_token: SecureRandom.uuid, instant_login_token_created_at: Time.now)
|
20
|
+
end
|
21
|
+
|
22
|
+
def reset_instant_login
|
23
|
+
update(instant_login_token: nil, instant_login_token_created_at: nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods
|
27
|
+
def authenticate_with_instant_login_token(token)
|
28
|
+
valid_tokens.find_by(instant_login_token: token).tap do |user|
|
29
|
+
user.reset_instant_login unless user.nil?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module InstantLogin
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace InstantLogin
|
4
|
+
config.generators do |g|
|
5
|
+
g.test_framework :rspec, :view_specs => false
|
6
|
+
end
|
7
|
+
initializer 'instant_login.initialize' do |app|
|
8
|
+
ActiveSupport.on_load :active_record do
|
9
|
+
ActiveRecord::Base.extend InstantLogin::Adapters::ActiveRecord::Setup
|
10
|
+
InstantLogin.config.user_class = InstantLogin.config.user_class.constantize
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "instant_login/engine"
|
2
|
+
require "instant_login/adapters/active_record"
|
3
|
+
|
4
|
+
module InstantLogin
|
5
|
+
include ActiveSupport::Configurable
|
6
|
+
|
7
|
+
config_accessor(:user_class) { }
|
8
|
+
config_accessor(:mailer_class) { }
|
9
|
+
|
10
|
+
# Redirect destination after successful or failed login
|
11
|
+
config_accessor(:success_path) { '/' }
|
12
|
+
config_accessor(:failure_path) { '/' }
|
13
|
+
|
14
|
+
# By default we store the signed in user id in this session key
|
15
|
+
config_accessor(:session_key) { 'current_user_id' }
|
16
|
+
|
17
|
+
# Convenience method to reset configuration
|
18
|
+
def self.reset_configuration!
|
19
|
+
config.user_class = nil
|
20
|
+
config.user_mailer = nil
|
21
|
+
config.success_path = '/'
|
22
|
+
config.failure_path = '/'
|
23
|
+
config.session_key = 'current_user_id'
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: instant_login
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephan Pavlovic
|
8
|
+
- Max Schulz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '4'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '4'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sqlite3
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec-rails
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: capybara
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: Instant Login is a Rails engine that provides an login with e-mail functionality
|
71
|
+
to your app. It allows you to sned one-time login tokens to your users.
|
72
|
+
email:
|
73
|
+
- stephan@railslove.com
|
74
|
+
- max@railslove.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- MIT-LICENSE
|
80
|
+
- Rakefile
|
81
|
+
- app/assets/javascripts/instant_login/application.js
|
82
|
+
- app/assets/javascripts/instant_login/instant_login.js
|
83
|
+
- app/assets/javascripts/instant_login/instant_login_controller.js
|
84
|
+
- app/assets/stylesheets/instant_login/application.css
|
85
|
+
- app/assets/stylesheets/instant_login/instant_login.css
|
86
|
+
- app/assets/stylesheets/instant_login/instant_login_controller.css
|
87
|
+
- app/controllers/instant_login/application_controller.rb
|
88
|
+
- app/controllers/instant_login/instant_login_controller.rb
|
89
|
+
- app/mailers/instant_login/user_mailer.rb
|
90
|
+
- app/views/instant_login/user_mailer/token.text.erb
|
91
|
+
- config/routes.rb
|
92
|
+
- lib/generators/instant_login/install_generator.rb
|
93
|
+
- lib/generators/instant_login/templates/initializer.rb
|
94
|
+
- lib/generators/instant_login/templates/migration.rb
|
95
|
+
- lib/instant_login.rb
|
96
|
+
- lib/instant_login/adapters/active_record.rb
|
97
|
+
- lib/instant_login/engine.rb
|
98
|
+
- lib/instant_login/version.rb
|
99
|
+
- lib/tasks/instant_login_tasks.rake
|
100
|
+
homepage: https://railslove.com/instant_login
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.4.3
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Login by e-mail. bye bye passwords
|
124
|
+
test_files: []
|