hero_generator 0.0.1.beta4 → 0.0.1.beta5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/generators/hero/authentication/authentication_generator.rb +1 -0
- data/lib/generators/hero/authentication/templates/controllers/confirmation_controller.rb +3 -3
- data/lib/generators/hero/authentication/templates/controllers/sessions_controller.rb +2 -2
- data/lib/generators/hero/authentication/templates/controllers/settings_controller.rb +2 -2
- data/lib/generators/hero/authentication/templates/mailers/confirmation_mailer.rb +1 -1
- data/lib/generators/hero/authentication/templates/migrations/create_users.rb +1 -2
- data/lib/generators/hero/authentication/templates/models/user.rb +3 -17
- data/lib/generators/hero/authentication/templates/tests/spec/factories.rb +1 -1
- data/lib/generators/hero/authentication/templates/tests/spec/models/user_spec.rb +4 -15
- data/lib/generators/hero/authentication/templates/tests/spec/routing/confirmation_mailer_spec.rb +1 -1
- metadata +8 -8
@@ -75,6 +75,7 @@ module Hero
|
|
75
75
|
|
76
76
|
|
77
77
|
def create_routes
|
78
|
+
route "default_url_options :host => 'localhost:3000'"
|
78
79
|
route "resources #{user_plural_name.to_sym.inspect}"
|
79
80
|
route "resources #{session_plural_name.to_sym.inspect}"
|
80
81
|
route "get 'log_out' => '#{session_plural_name.to_sym.inspect}#destroy', :as => 'log_out'"
|
@@ -8,12 +8,12 @@ class ConfirmationController < ApplicationController
|
|
8
8
|
redirect_to log_in_path, :notice => t( 'fe.confirmation.registration.flash.success' )
|
9
9
|
end
|
10
10
|
|
11
|
-
flash[:
|
11
|
+
flash[:notice] = t( 'fe.confirmation.registration.flash.error') if params[:token]
|
12
12
|
end
|
13
13
|
|
14
14
|
def resend_signup_token
|
15
|
-
@user = User.
|
16
|
-
if @user
|
15
|
+
@user = User.find_by_email(params[:email])
|
16
|
+
if @user && @user.authenticate(params[:password])
|
17
17
|
if @user.resend_signup_token
|
18
18
|
flash[:notice] = t( 'fe.confirmation.resend_signup_token.flash.success' )
|
19
19
|
else
|
@@ -3,8 +3,8 @@ class SessionsController < ApplicationController
|
|
3
3
|
end
|
4
4
|
|
5
5
|
def create
|
6
|
-
@user = User.
|
7
|
-
if @user
|
6
|
+
@user = User.find_by_email params[:email]
|
7
|
+
if @user && @user.authenticate(params[:password])
|
8
8
|
if @user.confirmed?
|
9
9
|
session[:user_id] = @user.id
|
10
10
|
redirect_to root_url, :notice => t( 'fe.session.create.flash.success' )
|
@@ -9,8 +9,8 @@ class SettingsController < ApplicationController
|
|
9
9
|
@user = current_user
|
10
10
|
|
11
11
|
flash.now[:notice] = t( 'fe.settings.change_user_email.flash_error' )
|
12
|
-
|
13
|
-
if
|
12
|
+
|
13
|
+
if @user.authenticate( params[:user][:password] )
|
14
14
|
current_user.set_new_email = true
|
15
15
|
current_user.new_email = params[:user][:new_email]
|
16
16
|
current_user.new_email_confirmation = params[:user][:new_email_confirmation]
|
@@ -6,7 +6,7 @@ class ConfirmationMailer < ActionMailer::Base
|
|
6
6
|
|
7
7
|
def registration( user )
|
8
8
|
@user = user
|
9
|
-
@confirmation_url = confirm_url( user.signup_token )
|
9
|
+
@confirmation_url = confirm_url( :registration, @user.signup_token )
|
10
10
|
mail( :to => user.email, :subject => t( 'confirmation_mailer.registration.subject' ))
|
11
11
|
end
|
12
12
|
|
@@ -1,8 +1,9 @@
|
|
1
1
|
class User < ActiveRecord::Base
|
2
|
+
has_secure_password
|
3
|
+
|
2
4
|
attr_accessible :email, :password, :password_confirmation, :new_email_confirmation, :set_new_email
|
3
5
|
|
4
|
-
attr_accessor :
|
5
|
-
before_save :encrypt_password
|
6
|
+
attr_accessor :update_password, :new_email_confirmation, :set_new_email
|
6
7
|
|
7
8
|
validates_format_of :email, :with => /^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i
|
8
9
|
validates_presence_of :email
|
@@ -84,21 +85,6 @@ class User < ActiveRecord::Base
|
|
84
85
|
update_password || new_record?
|
85
86
|
end
|
86
87
|
|
87
|
-
def self.authenticate(email, password)
|
88
|
-
user = find_by_email(email)
|
89
|
-
if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
|
90
|
-
user
|
91
|
-
else
|
92
|
-
nil
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def encrypt_password
|
97
|
-
if password.present?
|
98
|
-
self.password_salt = BCrypt::Engine.generate_salt
|
99
|
-
self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
|
100
|
-
end
|
101
|
-
end
|
102
88
|
|
103
89
|
|
104
90
|
def send_password_reset
|
@@ -51,24 +51,13 @@ describe User do
|
|
51
51
|
@other_user.should be_valid
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
same_password = 'secret'
|
56
|
-
@user.password = same_password
|
57
|
-
@user.save
|
58
|
-
|
59
|
-
@other_user = Factory.build( :user, :password => same_password )
|
60
|
-
@other_user.save
|
61
|
-
|
62
|
-
@user.password_hash.should_not == @other_user.password_hash
|
63
|
-
@user.password_salt.should_not == @other_user.password_salt
|
64
|
-
end
|
54
|
+
|
65
55
|
|
66
56
|
it 'should authenticate valid user' do
|
67
57
|
@user.save
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
User.authenticate( @user.email, '' ).should == nil
|
58
|
+
|
59
|
+
@user.authenticate( @user.password ).should be @user
|
60
|
+
@user.authenticate( '' ).should be false
|
72
61
|
end
|
73
62
|
|
74
63
|
it 'should be confirmable' do
|
data/lib/generators/hero/authentication/templates/tests/spec/routing/confirmation_mailer_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe ConfirmationMailer do
|
|
20
20
|
it "send user confirmation url" do
|
21
21
|
mail.subject.should eq( I18n.t( 'confirmation_mailer.registration.subject' ))
|
22
22
|
mail.to.should eq([user.email])
|
23
|
-
mail.body.encoded.should match(confirm_url(user.signup_token))
|
23
|
+
mail.body.encoded.should match(confirm_url( :registration, user.signup_token ))
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hero_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.beta5
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &82459840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *82459840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bcrypt-ruby
|
27
|
-
requirement: &
|
27
|
+
requirement: &82459580 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.1.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *82459580
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &82459310 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 3.0.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *82459310
|
47
47
|
description: Write a gem description
|
48
48
|
email:
|
49
49
|
- guido@boyke.de
|