easy_auth-password 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # EasyAuth-Password #
2
+
3
+ [![Build Status](http://travis-ci.org/dockyard/easy_auth-password.png)](http://travis-ci.org/dockyard/easy_auth-password)
4
+ [![Dependency Status](https://gemnasium.com/dockyard/easy_auth-password.png?travis)](https://gemnasium.com/dockyard/easy_auth-password)
5
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/dockyard/easy_auth-password)
6
+
7
+ Dead simple drop in authentication for Rails
8
+
9
+ ## Installation ##
10
+
11
+ In your Gemfile add the following:
12
+
13
+ ```ruby
14
+ gem 'easy_auth-password'
15
+ ```
16
+
17
+ After running Bundler you'll need to install the migrations
18
+
19
+ ```ruby
20
+ rake easy_auth-password:install:migrations
21
+ ```
22
+
23
+ Then run your migrations.
24
+
25
+ ## Authors ##
26
+
27
+ [Brian Cardarella](http://twitter.com/bcardarella)
28
+
29
+ ## Versioning ##
30
+
31
+ This gem follows [Semantic Versioning](http://semver.org)
32
+
33
+ ## Want to help? ##
34
+
35
+ Stable branches are created based upon each minor version. Please make
36
+ pull requests to specific branches rather than master.
37
+
38
+ Please make sure you include tests!
39
+
40
+ Unles Rails drops support for Ruby 1.8.7 we will continue to use the
41
+ hash-rocket syntax. Please respect this.
42
+
43
+ Don't use tabs to indent, two spaces are the standard.
44
+
45
+ ## Legal ##
46
+
47
+ [DockYard](http://dockyard.com), LLC © 2012
48
+
49
+ [@dockyard](http://twitter.com/dockyard)
50
+
51
+ [Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ require 'rspec/core/rake_task'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ RSpec::Core::RakeTask.new('default') do |t|
6
+ t.pattern = FileList['spec/**/*_spec.rb']
7
+ end
8
+
9
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
10
+ load 'rails/tasks/engine.rake'
@@ -0,0 +1,3 @@
1
+ class PasswordResetController < ApplicationController
2
+ include EasyAuth::Controllers::PasswordReset
3
+ end
@@ -0,0 +1,4 @@
1
+ class PasswordResetMailer < ActionMailer::Base
2
+ include EasyAuth::Mailers::PasswordReset
3
+ default :from => 'from@example.com'
4
+ end
@@ -0,0 +1,3 @@
1
+ class EasyAuth::Identities::Password < EasyAuth::Identity
2
+ include EasyAuth::Models::Identities::Password
3
+ end
@@ -0,0 +1,13 @@
1
+ <%= form_for @identity, :url => main_app.edit_password_path(params[:reset_token]) do |f| %>
2
+ <p>
3
+ <%= f.label :password %>
4
+ <%= f.text_field :password %>
5
+ </p>
6
+ <p>
7
+ <%= f.label :password_confirmation %>
8
+ <%= f.text_field :password_confirmation %>
9
+ </p>
10
+ <p>
11
+ <%= f.submit 'Submit' %>
12
+ </p>
13
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <%= form_for @identity, :url => main_app.password_reset_path, :method => :post do |f| %>
2
+ <p>
3
+ <%= f.label :username %>
4
+ <%= f.text_field :username %>
5
+ </p>
6
+ <p>
7
+ <%= f.submit 'Submit' %>
8
+ </p>
9
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= link_to 'Reset password', @url %>
@@ -0,0 +1 @@
1
+ Reset password: <%= @url %>
@@ -0,0 +1,17 @@
1
+ <%= form_for @identity, :url => main_app.sign_in_path do |f| %>
2
+ <p>
3
+ <%= f.label :username %>
4
+ <%= f.text_field :username %>
5
+ </p>
6
+ <p>
7
+ <%= f.label :password %>
8
+ <%= f.password_field :password %>
9
+ </p>
10
+ <p>
11
+ <%= f.label :remember, "Remember for #{@identity.remember_time.inspect}" %>
12
+ <%= f.check_box :remember %>
13
+ </p>
14
+ <p>
15
+ <%= f.submit 'Submit' %>
16
+ </p>
17
+ <% end %>
@@ -0,0 +1,14 @@
1
+ en:
2
+ easy_auth:
3
+ sessions:
4
+ create:
5
+ notice: 'You have been signed in.'
6
+ error: 'Could not sign you in. Please check your credentials.'
7
+ delete:
8
+ notice: 'You have been signed out.'
9
+ password_reset:
10
+ create:
11
+ notice: 'Please check your email for your password reset link.'
12
+ update:
13
+ notice: 'Your password has been updated.'
14
+ error: 'There was an issue updating your password.'
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ EasyAuth::Engine.routes.draw do
2
+ end
@@ -0,0 +1,57 @@
1
+ module EasyAuth::Controllers::PasswordReset
2
+ def self.included(base)
3
+ base.instance_eval do
4
+ before_filter :find_identity_from_reset_token, :only => [:edit, :update]
5
+ end
6
+ end
7
+
8
+ def new
9
+ @identity = EasyAuth.password_identity_model.new
10
+ end
11
+
12
+ def create
13
+ if @identity = EasyAuth.password_identity_model.where(:username => params[:identities_password][:username]).first
14
+ @identity.generate_reset_token!
15
+ PasswordResetMailer.reset(@identity.id).deliver
16
+ else
17
+ @identity = EasyAuth.password_identity_model.new(params[:identities_password])
18
+ end
19
+
20
+ flash.now[:notice] = I18n.t('easy_auth.password_reset.create.notice')
21
+ render :new
22
+ end
23
+
24
+ def update
25
+ if @identity.update_attributes(scope_to_password_params(:identities_password))
26
+ after_successful_password_reset(@identity)
27
+ else
28
+ after_failed_password_reset(@identity)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def scope_to_password_params(key)
35
+ { :password => params[key][:password], :password_confirmation => params[key][:password_confirmation] }
36
+ end
37
+
38
+ def find_identity_from_reset_token
39
+ @identity = EasyAuth.password_identity_model.where(:reset_token => params[:reset_token].to_s).first
40
+ @identity.password_reset = true
41
+ end
42
+
43
+ def after_successful_password_reset(identity)
44
+ identity.set_account_session(session)
45
+ identity.update_column(:reset_token, nil)
46
+ redirect_to after_successful_password_reset_url(identity), :notice => I18n.t('easy_auth.password_reset.update.notice')
47
+ end
48
+
49
+ def after_successful_password_reset_url(identity)
50
+ identity.account
51
+ end
52
+
53
+ def after_failed_password_reset(identity)
54
+ flash.now[:error] = I18n.t('easy_auth.password_reset.update.error')
55
+ render :edit
56
+ end
57
+ end
@@ -0,0 +1,11 @@
1
+ module EasyAuth::Mailers::PasswordReset
2
+ def self.included(base)
3
+ base.clear_action_methods!
4
+ end
5
+
6
+ def reset(id)
7
+ @identity = EasyAuth.identity_model.find(id)
8
+ @url = edit_password_url(@identity.reset_token)
9
+ mail :to => @identity.account.email, :subject => 'Password reset'
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ module EasyAuth::Models::Identities::Password
2
+ include EasyAuth::TokenGenerator
3
+
4
+ def self.included(base)
5
+ base.class_eval do
6
+ has_secure_password
7
+
8
+ # Attributes
9
+ attr_accessor :password_reset
10
+ attr_accessible :username, :password, :password_confirmation, :remember
11
+ alias_attribute :password_digest, :token
12
+
13
+ # Relationships
14
+ belongs_to :account, :polymorphic => true
15
+
16
+ # Validations
17
+ validates :username, :uniqueness => { :case_sensitive => false }, :presence => true
18
+ validates :password, :presence => { :on => :create }
19
+ validates :password, :presence => { :if => :password_reset }
20
+
21
+ def self.authenticate(controller)
22
+ attributes = controller.params[:identities_password]
23
+ return nil if attributes.nil?
24
+ where(arel_table[:username].matches(attributes[:username].try(&:strip))).first.try(:authenticate, attributes[:password])
25
+ end
26
+
27
+ end
28
+ end
29
+
30
+ def generate_reset_token!
31
+ update_column(:reset_token, URI.escape(_generate_token(:reset).gsub(/[\.|\\\/]/,'')))
32
+ reset_token
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ module EasyAuth::Password::Controllers::Sessions
2
+ extend EasyAuth::ReverseConcern
3
+
4
+ reverse_included do
5
+ before_filter :no_authentication, :only => :new, :if => Proc.new { params[:identity] == :password }
6
+ end
7
+
8
+ private
9
+
10
+ def after_successful_sign_in_with_password(identity)
11
+ end
12
+
13
+ def after_successful_sign_in_url_with_password(identity)
14
+ end
15
+
16
+ def after_failed_sign_in_with_password(identity)
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module EasyAuth::Password::Controllers
2
+ extend ActiveSupport::Autoload
3
+ autoload :Sessions
4
+ end
@@ -0,0 +1,14 @@
1
+ module EasyAuth::Password
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace EasyAuth::Password
4
+
5
+ initializer 'filter_parameters' do |app|
6
+ app.config.filter_parameters += [:password]
7
+ app.config.filter_parameters.uniq!
8
+ end
9
+
10
+ config.generators do |g|
11
+ g.test_framework :rspec, :view_specs => false
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ module EasyAuth::Password::Models::Account
2
+ extend EasyAuth::ReverseConcern
3
+
4
+ reverse_included do
5
+ # Attributes
6
+ attr_accessor :password
7
+ attr_accessible :password, :password_confirmation
8
+
9
+ # Validations
10
+ validates :password, :presence => { :on => :create, :if => :run_password_identity_validations? }, :confirmation => true
11
+ validates identity_username_attribute, :presence => true, :if => :run_password_identity_validations?
12
+
13
+ # Callbacks
14
+ before_create :setup_password_identity, :if => :run_password_identity_validations?
15
+ before_update :update_password_identity, :if => :run_password_identity_validations?
16
+
17
+ # Associations
18
+ has_one :password_identity, :class_name => 'EasyAuth::Identities::Password', :foreign_key => :account_id
19
+ end
20
+
21
+ def run_password_identity_validations?
22
+ (self.new_record? && self.password.present?) || self.password_identity.present?
23
+ end
24
+
25
+ private
26
+
27
+ def setup_password_identity
28
+ self.identities << EasyAuth.password_identity_model.new(password_identity_attributes)
29
+ end
30
+
31
+ def update_password_identity
32
+ self.password_identity.update_attributes(password_identity_attributes)
33
+ end
34
+
35
+ def password_identity_attributes
36
+ { :username => self.identity_username_attribute, :password => self.password, :password_confirmation => self.password_confirmation }
37
+ end
38
+ end
@@ -0,0 +1,4 @@
1
+ module EasyAuth::Password::Models
2
+ extend ActiveSupport::Autoload
3
+ autoload :Account
4
+ end
@@ -0,0 +1,11 @@
1
+ module EasyAuth::Password::Routes
2
+ def easy_auth_password_routes
3
+ get '/sign_in' => 'sessions#new', :as => :sign_in, :defaults => { :identity => :password }
4
+ post '/sign_in' => 'sessions#create', :defaults => { :identity => :password }
5
+
6
+ get '/password_reset' => 'password_reset#new', :as => :password_reset, :defaults => { :identity => :password }
7
+ post '/password_reset' => 'password_reset#create', :defaults => { :identity => :password }
8
+ get '/password_reset/:reset_token' => 'password_reset#edit', :as => :edit_password, :defaults => { :identity => :password }
9
+ put '/password_reset/:reset_token' => 'password_reset#update', :defaults => { :identity => :password }
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module EasyAuth
2
+ module Password
3
+ VERSION = '0.0.5'
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ require 'easy_auth'
2
+ require 'easy_auth/password/engine'
3
+ require 'easy_auth/password/version'
4
+ require 'easy_auth/password/routes'
5
+
6
+ module EasyAuth
7
+
8
+ module Password
9
+ extend ActiveSupport::Autoload
10
+ autoload :Controllers
11
+ autoload :Models
12
+ end
13
+
14
+ def self.password_identity_model(controller = nil)
15
+ EasyAuth::Identities::Password
16
+ end
17
+
18
+ module Controllers
19
+ autoload :PasswordReset
20
+
21
+ module Sessions
22
+ include EasyAuth::Password::Controllers::Sessions
23
+ end
24
+ end
25
+
26
+ module Mailers
27
+ autoload :PasswordReset
28
+ end
29
+
30
+ module Models
31
+ module Account
32
+ include EasyAuth::Password::Models::Account
33
+ end
34
+
35
+ module Identities
36
+ autoload :Password
37
+ end
38
+ end
39
+ end
40
+
41
+ ActionDispatch::Routing::Mapper.send(:include, EasyAuth::Password::Routes)
@@ -0,0 +1 @@
1
+ require 'easy_auth/password'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :easy_auth do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,253 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy_auth-password
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian Cardarella
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: easy_auth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.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: 0.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
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: rspec-rails
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
+ - !ruby/object:Gem::Dependency
63
+ name: capybara
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: capybara-email
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: database_cleaner
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: valid_attribute
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
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
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: factory_girl_rails
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 1.7.0
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 1.7.0
142
+ - !ruby/object:Gem::Dependency
143
+ name: factory_girl
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 2.6.0
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 2.6.0
158
+ - !ruby/object:Gem::Dependency
159
+ name: bourne
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: launchy
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ description: EasyAuth-Password
191
+ email:
192
+ - brian@dockyard.com
193
+ - bcardarella@gmail.com
194
+ executables: []
195
+ extensions: []
196
+ extra_rdoc_files: []
197
+ files:
198
+ - app/controllers/password_reset_controller.rb
199
+ - app/mailers/password_reset_mailer.rb
200
+ - app/models/easy_auth/identities/password.rb
201
+ - app/views/password_reset/edit.html.erb
202
+ - app/views/password_reset/new.html.erb
203
+ - app/views/password_reset_mailer/reset.html.erb
204
+ - app/views/password_reset_mailer/reset.text.erb
205
+ - app/views/sessions/new.html.erb
206
+ - config/locales/en.yml
207
+ - config/routes.rb
208
+ - lib/easy_auth/controllers/password_reset.rb
209
+ - lib/easy_auth/mailers/password_reset.rb
210
+ - lib/easy_auth/models/identities/password.rb
211
+ - lib/easy_auth/password/controllers/sessions.rb
212
+ - lib/easy_auth/password/controllers.rb
213
+ - lib/easy_auth/password/engine.rb
214
+ - lib/easy_auth/password/models/account.rb
215
+ - lib/easy_auth/password/models.rb
216
+ - lib/easy_auth/password/routes.rb
217
+ - lib/easy_auth/password/version.rb
218
+ - lib/easy_auth/password.rb
219
+ - lib/easy_auth-password.rb
220
+ - lib/tasks/easy_auth_tasks.rake
221
+ - Rakefile
222
+ - README.md
223
+ homepage: https://github.com/dockyard/easy_auth-password
224
+ licenses: []
225
+ post_install_message:
226
+ rdoc_options: []
227
+ require_paths:
228
+ - lib
229
+ required_ruby_version: !ruby/object:Gem::Requirement
230
+ none: false
231
+ requirements:
232
+ - - ! '>='
233
+ - !ruby/object:Gem::Version
234
+ version: '0'
235
+ segments:
236
+ - 0
237
+ hash: 3669041279694489791
238
+ required_rubygems_version: !ruby/object:Gem::Requirement
239
+ none: false
240
+ requirements:
241
+ - - ! '>='
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ segments:
245
+ - 0
246
+ hash: 3669041279694489791
247
+ requirements: []
248
+ rubyforge_project:
249
+ rubygems_version: 1.8.23
250
+ signing_key:
251
+ specification_version: 3
252
+ summary: EasyAuth-Password
253
+ test_files: []