authn-activation 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore
6
+
7
+ # Ignore all of the generated gem stuff
8
+ /pkg
9
+ /*.gem
10
+
11
+ # Ignore bundler config
12
+ /.bundle
13
+ /Gemfile.lock
14
+
15
+ # Ignore all bundler caching
16
+ /vendor/cache
17
+ /vendor/ruby
18
+
19
+ # Ignore all tempfiles
20
+ /tmp
21
+
22
+ # Ignores that should be in the global gitignore
23
+ # /*.rbc
24
+ # /.config
25
+ # /.yardoc
26
+ # /InstalledFiles
27
+ # /_yardoc
28
+ # /coverage/
29
+ # /doc/
30
+ # /lib/bundler/man/
31
+ # /rdoc/
32
+ # /spec/reports/
33
+ # /test/tmp/
34
+ # /test/version_tmp/
35
+
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@authn-activation"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.13.8 (master)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ - 1.9.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ CHANGELOG
2
+ ---------
3
+
4
+
5
+ 1.0.0 / YYYY-MM-DD
6
+ ==================
7
+
8
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in example.gemspec
4
+ gemspec
5
+
6
+ gem 'rails'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Kurtis Rainbolt-Greene
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,140 @@
1
+ AuthN Activation
2
+ ----------------
3
+
4
+ authn-activation is an extention of the AuthN library to allow for activation type business logic.
5
+ This means that AuthN-behaving models can be "activated" and "deactivated".
6
+ It would also be trivial to implement an invite business logic.
7
+
8
+
9
+ Using AuthN Activation
10
+ ======================
11
+
12
+ To start using authn-activation you simply need to install authn, authn-activation, and hook up to your existing "user" model:
13
+
14
+ ``` ruby
15
+ # create_table :accounts do |t|
16
+ # t.string :email
17
+ # t.binary :password_digest
18
+ #
19
+ # t.timestamps
20
+ # end
21
+ # add_index :accounts, :email
22
+ #
23
+
24
+ class Account < ActiveRecord::Base
25
+ include AuthN::Model
26
+
27
+ has_authentication
28
+ has_secure_password
29
+
30
+ validates :email, uniqueness: true, presence: true, length: 5..255
31
+ validates :password, length: 10..1024
32
+
33
+ attr_accessible :email
34
+ end
35
+ ```
36
+
37
+ See?
38
+ No muss, no fuss.
39
+ Now what about all those addons?
40
+ We'll you can see their own pages, but here's a taste:
41
+
42
+ ``` ruby
43
+ # create_table :accounts do |t|
44
+ # t.string :email
45
+ # t.binary :password_digest
46
+ #
47
+ # t.string :activation_token
48
+ # t.boolean :activation_state, default: false
49
+ # t.datetime :activation_expires_at
50
+ #
51
+ # t.string :password_recovery_token
52
+ # t.datetime :password_recovery_expires_at
53
+ #
54
+ # t.string :login_protection_token
55
+ # t.datetime :login_protection_expires_at
56
+ # t.integer :login_protection_attempts, default: 0
57
+ #
58
+ # t.timestamps
59
+ # end
60
+ # add_index :accounts, :email
61
+ # add_index :accounts, :activation_token
62
+ # add_index :accounts, :activation_state
63
+ # add_index :accounts, :password_recovery_token
64
+ # add_index :accounts, :login_protection_token
65
+ #
66
+
67
+ class Account < ActiveRecord::Base
68
+ include AuthN::Model
69
+
70
+ has_authentication
71
+ has_password_recovery mailer: "PasswordRecoveryMailer"
72
+ has_activation mailer: "ActivationMailer", on_create: false
73
+ has_login_protection maximum: 3, redirect: { controller: :accounts, action: :maximum_login_failure }
74
+ has_secure_password
75
+
76
+ validates :email, uniqueness: true, presence: true, length: 5..255
77
+ validates :password, length: 10..1024
78
+
79
+ attr_accessible :email
80
+ end
81
+ ```
82
+
83
+ You'll notice that there are options after some of the addon singleton methods.
84
+ These are used to overwrite the global configuration.
85
+ authn assumes quite a few things, but never stops you from changing how it works.
86
+ As above you can change how each of your "user" models functions (for say admin recovery emails vs support recovery emails).
87
+ In addition you can either programatically write the "global" configuration or have a `authn.yml` file ready to be loaded.
88
+
89
+ Installing AuthN Activation
90
+ ===========================
91
+
92
+ Add this line to your application's Gemfile:
93
+
94
+ gem 'authn-activation'
95
+
96
+ And then execute:
97
+
98
+ $ bundle
99
+
100
+ Or install it yourself as:
101
+
102
+ $ gem install authn-activation
103
+
104
+ You're all setup and can follow the examples above.
105
+
106
+
107
+ Contributing
108
+ ============
109
+
110
+ 1. Fork it
111
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
112
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
113
+ 4. Push to the branch (`git push origin my-new-feature`)
114
+ 5. Create new Pull Request
115
+
116
+ License
117
+ =======
118
+
119
+ Copyright (c) 2012 Kurtis Rainbolt-Greene
120
+
121
+ MIT License
122
+
123
+ Permission is hereby granted, free of charge, to any person obtaining
124
+ a copy of this software and associated documentation files (the
125
+ "Software"), to deal in the Software without restriction, including
126
+ without limitation the rights to use, copy, modify, merge, publish,
127
+ distribute, sublicense, and/or sell copies of the Software, and to
128
+ permit persons to whom the Software is furnished to do so, subject to
129
+ the following conditions:
130
+
131
+ The above copyright notice and this permission notice shall be
132
+ included in all copies or substantial portions of the Software.
133
+
134
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
135
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
136
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
137
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
138
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
139
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
140
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'yard'
6
+
7
+ begin
8
+ Bundler.setup :default, :development
9
+ rescue Bundler::BundlerError => error
10
+ $stderr.puts error.message
11
+ $stderr.puts "Run `bundle install` to install missing gems"
12
+ exit error.status_code
13
+ end
14
+
15
+ Bundler::GemHelper.install_tasks
16
+
17
+ desc "Run all of the tests"
18
+ Rake::TestTask.new do |config|
19
+ config.libs << 'test'
20
+ config.pattern = 'test/**/*_test*'
21
+ config.verbose = true
22
+ config.warning = true
23
+ end
24
+
25
+ desc "Generate all of the docs"
26
+ YARD::Rake::YardocTask.new do |config|
27
+ config.files = Dir['lib/**/*.rb']
28
+ end
29
+
30
+ desc 'Default: run tests, and generate docs'
31
+ task :default => [ :test, :yard ]
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'authn/activation/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "authn-activation"
8
+ gem.version = AuthN::Activation::VERSION
9
+ gem.authors = ["Kurtis Rainbolt-Greene"]
10
+ gem.email = ["me@kurtisrainboltgreene.name"]
11
+ gem.summary = %q{The plugin library for AuthN and Rails}
12
+ gem.description = gem.summary
13
+ gem.homepage = "http://krainboltgreene.github.com/authn-activation"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency 'authn', '~> 2.0'
21
+ gem.add_development_dependency 'yard'
22
+ gem.add_development_dependency 'kramdown'
23
+ # gem.add_runtime_dependency 'gemname', '~> 1.0'
24
+ # gem.add_development_dependency 'gemname', '~> 1.0'
25
+ end
@@ -0,0 +1,9 @@
1
+ require 'authn'
2
+ require_relative 'authn/activation/version'
3
+ require_relative 'authn/model'
4
+
5
+ module AuthN
6
+ module Activation
7
+
8
+ end
9
+ end
@@ -0,0 +1,52 @@
1
+ module AuthN
2
+ module Activation
3
+ module Model
4
+ def activate(token)
5
+ activate_instance if token_matches(token) && can_activate?
6
+ end
7
+
8
+ def activate!
9
+ activate_instance
10
+ end
11
+
12
+ def activated?
13
+ send_activation_state
14
+ end
15
+
16
+ def deactivate!
17
+ activate_instance false
18
+ end
19
+
20
+ private
21
+
22
+ def send_activation_token
23
+ send config.activation_token_method
24
+ end
25
+
26
+ def send_activation_state(value = nil)
27
+ send config.activation_state_method, value
28
+ end
29
+
30
+ def send_activation_expires_at
31
+ send config.activation_expires_at_method
32
+ end
33
+
34
+ def activate_instance(value = true)
35
+ send_activation_state value
36
+ send_activation_mail if method_defined?(send_activation_mail)
37
+ end
38
+
39
+ def token_matches(token)
40
+ send_activation_token != token
41
+ end
42
+
43
+ def can_activate?
44
+ !send_activation_state && activation_expired?
45
+ end
46
+
47
+ def activation_expired?
48
+ send_activation_expires_at >= DateTime.now
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ module AuthN
2
+ module Activation
3
+ VERSION = "1.7.0"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module AuthN
2
+ class Config
3
+ @@defaults.merge!(
4
+ mailer_klass: "ActivationMailer",
5
+ activation_state_method: :activation_state,
6
+ activation_token_method: :activation_token,
7
+ activation_expires_at_method: :activation_expires_at)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'activation/model'
2
+
3
+ module AuthN
4
+ module Model
5
+ module ClassMethods
6
+ extend AuthN::Activation::Model
7
+ end
8
+ end
9
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'authn-activation'
2
+
3
+ module ActiveModel::Model
4
+ def self.included(base)
5
+ base.class_eval do
6
+ extend ActiveModel::Naming
7
+ extend ActiveModel::Translation
8
+ include ActiveModel::Validations
9
+ include ActiveModel::Conversion
10
+ include ActiveModel::SecurePassword
11
+ end
12
+ end
13
+
14
+ def initialize(params={})
15
+ params.each do |attr, value|
16
+ self.public_send("#{attr}=", value)
17
+ end if params
18
+ end
19
+
20
+ def persisted?
21
+ false
22
+ end
23
+ end
24
+
25
+
26
+ class Account
27
+ include ActiveModel::Model
28
+ include AuthN::Model
29
+
30
+ has_authentication
31
+ has_activation
32
+ has_secure_password
33
+
34
+ attr_accessor :password_digest
35
+
36
+ def self.password(password=nil)
37
+ if password
38
+ @password = password
39
+ else
40
+ @password
41
+ end
42
+ end
43
+
44
+ def self.where(hash)
45
+ account = if hash[:email] == "kurtis@example.com"
46
+ Account.new(password: password, password_confirmation: password)
47
+ end
48
+ [account]
49
+ end
50
+
51
+ def id
52
+ @id ||= rand(100000)
53
+ end
54
+ end
@@ -0,0 +1,12 @@
1
+ require 'minitest/autorun'
2
+ require 'helper'
3
+
4
+ class TestAuthNActivation < MiniTest::Unit::TestCase
5
+ def test_that_things_work
6
+ assert true
7
+ end
8
+
9
+ def test_that_AuthN_is_defined
10
+ assert(defined?(AuthN::Activation))
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ require 'minitest/autorun'
2
+ require 'helper'
3
+
4
+ class TestAuthNActivationModel < MiniTest::Unit::TestCase
5
+ def test_that_things_work
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../../helper'
3
+
4
+ class TestAuthNActivationVersion < MiniTest::Unit::TestCase
5
+ def test_that_version_is_latest
6
+ assert_equal "1.7.0", AuthN::Activation::VERSION
7
+ end
8
+ end
File without changes
File without changes
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: authn-activation
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.7.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kurtis Rainbolt-Greene
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: authn
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: yard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: kramdown
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: The plugin library for AuthN and Rails
63
+ email:
64
+ - me@kurtisrainboltgreene.name
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rvmrc
71
+ - .travis.yml
72
+ - CHANGELOG.md
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - authn-activation.gemspec
78
+ - lib/authn-activation.rb
79
+ - lib/authn/activation/model.rb
80
+ - lib/authn/activation/version.rb
81
+ - lib/authn/config.rb
82
+ - lib/authn/model.rb
83
+ - test/helper.rb
84
+ - test/lib/authn-activation_test.rb
85
+ - test/lib/authn/activation/model_test.rb
86
+ - test/lib/authn/activation/version_test.rb
87
+ - test/lib/authn/config_test.rb
88
+ - test/lib/authn/model_test.rb
89
+ homepage: http://krainboltgreene.github.com/authn-activation
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ segments:
102
+ - 0
103
+ hash: -2462880146099724815
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ segments:
111
+ - 0
112
+ hash: -2462880146099724815
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.24
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: The plugin library for AuthN and Rails
119
+ test_files:
120
+ - test/helper.rb
121
+ - test/lib/authn-activation_test.rb
122
+ - test/lib/authn/activation/model_test.rb
123
+ - test/lib/authn/activation/version_test.rb
124
+ - test/lib/authn/config_test.rb
125
+ - test/lib/authn/model_test.rb
126
+ has_rdoc: