i0n_rails3_generators 0.2.13 → 0.2.14
Sign up to get free protection for your applications and to get access to all the features.
- data/config/version.yml +1 -1
- data/lib/generators/i0n/authentication/authentication_generator.rb +10 -4
- data/lib/generators/i0n/authentication/templates/app/controllers/{_sessions_controller.rb → _user_sessions_controller.rb} +4 -6
- data/lib/generators/i0n/authentication/templates/app/models/_user.rb +25 -0
- data/lib/generators/i0n/authentication/templates/app/views/user_sessions/new.haml +3 -12
- data/lib/generators/i0n/authentication/templates/app/views/users/edit.haml +5 -2
- data/lib/generators/i0n/authentication/templates/app/views/users/index.haml +4 -1
- data/lib/generators/i0n/authentication/templates/app/views/users/new.haml +5 -2
- data/lib/generators/i0n/authentication/templates/lib/tasks/create_default_user.rake +8 -0
- data/lib/generators/i0n/layout/templates/app/views/layouts/application.haml +1 -4
- metadata +5 -5
- data/lib/generators/i0n/authentication/templates/app/models/user.rb +0 -46
- data/lib/generators/i0n/authentication/templates/lib/tasks/populate.rake +0 -16
data/config/version.yml
CHANGED
@@ -5,7 +5,7 @@ module I0n
|
|
5
5
|
source_root File.expand_path('../templates', __FILE__)
|
6
6
|
|
7
7
|
def gemfile
|
8
|
-
gem("bcrypt-ruby")
|
8
|
+
gem("bcrypt-ruby", :require => 'bcrypt')
|
9
9
|
end
|
10
10
|
|
11
11
|
def setup_application
|
@@ -21,7 +21,7 @@ module I0n
|
|
21
21
|
|
22
22
|
def create_authentication_lib_and_include_in_application_helper
|
23
23
|
copy_file "lib/authentication.rb", "#{Rails.root}/lib/authentication.rb"
|
24
|
-
inject_into_class("app/controllers/application_controller.rb", "include Authentication")
|
24
|
+
inject_into_class("app/controllers/application_controller.rb", ApplicationController, "include Authentication\n")
|
25
25
|
end
|
26
26
|
|
27
27
|
def create_routes
|
@@ -34,17 +34,23 @@ module I0n
|
|
34
34
|
|
35
35
|
def create_models
|
36
36
|
generate("model", "user email:string password_hash:string password_salt:string")
|
37
|
+
inject_into_class("app/models/user.rb", User, IO.read("#{AuthenticationGenerator.source_root}/app/models/_user.rb"))
|
37
38
|
end
|
38
39
|
|
39
40
|
def create_controllers
|
40
41
|
generate("controller", "user_sessions")
|
41
42
|
generate("controller", "users")
|
42
|
-
inject_into_class("app/controllers/users_controller.rb", IO.read("#{AuthenticationGenerator.source_root}/app/controllers/_users_controller.rb"))
|
43
|
+
inject_into_class("app/controllers/users_controller.rb", UsersController, IO.read("#{AuthenticationGenerator.source_root}/app/controllers/_users_controller.rb"))
|
44
|
+
inject_into_class("app/controllers/user_sessions_controller.rb", UserSessionsController, IO.read("#{AuthenticationGenerator.source_root}/app/controllers/_user_sessions_controller.rb"))
|
43
45
|
end
|
44
46
|
|
45
47
|
def create_views
|
46
48
|
directory "app/views/users", "#{Rails.root}/app/views/users"
|
47
|
-
directory "app/
|
49
|
+
directory "app/views/user_sessions", "#{Rails.root}/app/views/user_sessions"
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_rake_tasks
|
53
|
+
copy_file "lib/tasks/create_default_user.rake", "#{Rails.root}/lib/tasks/create_default_user.rake"
|
48
54
|
end
|
49
55
|
|
50
56
|
end
|
@@ -5,19 +5,17 @@
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def create
|
8
|
-
user = User.authenticate(params[:
|
8
|
+
user = User.authenticate(params[:email], params[:password])
|
9
9
|
if user
|
10
10
|
session[:user_id] = user.id
|
11
|
-
|
12
|
-
redirect_to_target_or_default("/")
|
11
|
+
redirect_to root_url, :notice => "Logged in!"
|
13
12
|
else
|
14
13
|
flash.now[:error] = "Invalid login or password."
|
15
|
-
render
|
14
|
+
render 'new'
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
19
18
|
def destroy
|
20
19
|
session[:user_id] = nil
|
21
|
-
|
22
|
-
redirect_to "/"
|
20
|
+
redirect_to "root_url"
|
23
21
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
attr_accessor :password
|
2
|
+
before_save :encrypt_password
|
3
|
+
|
4
|
+
validates_presence_of :email
|
5
|
+
validates_uniqueness_of :email
|
6
|
+
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
|
7
|
+
validates_presence_of :password, :on => :create
|
8
|
+
validates_confirmation_of :password
|
9
|
+
validates_length_of :password, :minimum => 4
|
10
|
+
|
11
|
+
def self.authenticate(email, password)
|
12
|
+
user = find(:first, :conditions => {:email => email})
|
13
|
+
if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
|
14
|
+
user
|
15
|
+
else
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def encrypt_password
|
21
|
+
if password.present?
|
22
|
+
self.password_salt = BCrypt::Engine.generate_salt
|
23
|
+
self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
|
24
|
+
end
|
25
|
+
end
|
@@ -2,22 +2,13 @@
|
|
2
2
|
Log in
|
3
3
|
|
4
4
|
- content_for :description do
|
5
|
-
|
5
|
+
description goes here
|
6
6
|
|
7
|
-
- content_for :keywords do
|
8
|
-
web design,website design,web development,website development,user experience design,usability
|
9
|
-
|
10
|
-
- content_for :body_id do
|
11
|
-
form_layout
|
12
|
-
|
13
|
-
- content_for :h1 do
|
14
|
-
Login
|
15
|
-
|
16
7
|
%article
|
17
8
|
= form_tag user_sessions_path do
|
18
9
|
.field
|
19
|
-
= label_tag :
|
20
|
-
= text_field_tag :
|
10
|
+
= label_tag :email, "Email Address"
|
11
|
+
= text_field_tag :email, params[:email], :autofocus => true
|
21
12
|
.field
|
22
13
|
= label_tag :password
|
23
14
|
= password_field_tag :password
|
@@ -3,7 +3,6 @@
|
|
3
3
|
%head
|
4
4
|
%meta{ :content => "text/html;charset=UTF-8", "http-equiv" => "content-type" }
|
5
5
|
%meta{:name => 'description', :content => "#{yield :description}"}
|
6
|
-
%meta{:name => 'keywords', :content => "#{yield :keywords}"}
|
7
6
|
= csrf_meta_tag
|
8
7
|
%title
|
9
8
|
#{yield :title}
|
@@ -12,11 +11,9 @@
|
|
12
11
|
= stylesheet_link_tag 'ie', :media => 'screen, projection'
|
13
12
|
/[if lt IE 9]
|
14
13
|
%script{ :src => "http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js" }
|
15
|
-
%body
|
14
|
+
%body
|
16
15
|
.container
|
17
16
|
%header
|
18
|
-
%h1
|
19
|
-
#{yield :h1}
|
20
17
|
- if flash[:notice] != nil
|
21
18
|
%p{:class => "flash_notice"}
|
22
19
|
= flash[:notice]
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: i0n_rails3_generators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.14
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ian Alexander Wood (i0n)
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-20 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -64,16 +64,16 @@ files:
|
|
64
64
|
- lib/generators/authlogic/complete/templates/users_controller.rb
|
65
65
|
- lib/generators/authlogic/complete/templates/users_controller_test.rb
|
66
66
|
- lib/generators/i0n/authentication/authentication_generator.rb
|
67
|
-
- lib/generators/i0n/authentication/templates/app/controllers/
|
67
|
+
- lib/generators/i0n/authentication/templates/app/controllers/_user_sessions_controller.rb
|
68
68
|
- lib/generators/i0n/authentication/templates/app/controllers/_users_controller.rb
|
69
|
-
- lib/generators/i0n/authentication/templates/app/models/
|
69
|
+
- lib/generators/i0n/authentication/templates/app/models/_user.rb
|
70
70
|
- lib/generators/i0n/authentication/templates/app/views/user_sessions/new.haml
|
71
71
|
- lib/generators/i0n/authentication/templates/app/views/users/_form.haml
|
72
72
|
- lib/generators/i0n/authentication/templates/app/views/users/edit.haml
|
73
73
|
- lib/generators/i0n/authentication/templates/app/views/users/index.haml
|
74
74
|
- lib/generators/i0n/authentication/templates/app/views/users/new.haml
|
75
75
|
- lib/generators/i0n/authentication/templates/lib/authentication.rb
|
76
|
-
- lib/generators/i0n/authentication/templates/lib/tasks/
|
76
|
+
- lib/generators/i0n/authentication/templates/lib/tasks/create_default_user.rake
|
77
77
|
- lib/generators/i0n/authentication/USAGE
|
78
78
|
- lib/generators/i0n/i0n.rb
|
79
79
|
- lib/generators/i0n/layout/layout_generator.rb
|
@@ -1,46 +0,0 @@
|
|
1
|
-
class User
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Timestamps
|
4
|
-
field :username, :type => String
|
5
|
-
field :email, :type => String
|
6
|
-
field :password_salt, :type => String
|
7
|
-
field :password_hash, :type => String
|
8
|
-
|
9
|
-
# new columns need to be added here to be writable through mass assignment
|
10
|
-
attr_accessible :username, :email, :password, :password_confirmation
|
11
|
-
|
12
|
-
attr_accessor :password
|
13
|
-
before_save :prepare_password
|
14
|
-
|
15
|
-
validates_presence_of :username
|
16
|
-
validates_uniqueness_of :username, :email, :allow_blank => true
|
17
|
-
validates_format_of :username, :with => /^[-\w\._@]+$/i, :allow_blank => true, :message => "should only contain letters, numbers, or .-_@"
|
18
|
-
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
|
19
|
-
validates_presence_of :password, :on => :create
|
20
|
-
validates_confirmation_of :password
|
21
|
-
validates_length_of :password, :minimum => 4, :allow_blank => true
|
22
|
-
|
23
|
-
# login can be either username or email address
|
24
|
-
def self.authenticate(login, pass)
|
25
|
-
user = find(:first, :conditions => {:username => login}) || find(:first, :conditions => {:email => login})
|
26
|
-
return user if user && user.matching_password?(pass)
|
27
|
-
end
|
28
|
-
|
29
|
-
def matching_password?(pass)
|
30
|
-
self.password_hash == encrypt_password(pass)
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def prepare_password
|
36
|
-
unless password.blank?
|
37
|
-
self.password_salt = Digest::SHA1.hexdigest([Time.now, rand].join)
|
38
|
-
self.password_hash = encrypt_password(password)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def encrypt_password(pass)
|
43
|
-
Digest::SHA1.hexdigest([pass, password_salt].join)
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
namespace :db do
|
2
|
-
|
3
|
-
desc "Erase and fill database"
|
4
|
-
task :populate => :environment do
|
5
|
-
require 'faker'
|
6
|
-
[Contact].each(&:delete_all)
|
7
|
-
10.times do
|
8
|
-
contact = Contact.create(:name => Faker::Name.name,
|
9
|
-
:email => (rand(10000).to_s + Faker::Internet.email),
|
10
|
-
:message => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|