seivan-generators 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/features/seivan_authentication.feature +2 -0
- data/features/seivan_config.feature +1 -0
- data/lib/generators/seivan/authentication/templates/user.rb +27 -10
- data/lib/generators/seivan/config/templates/config.yml +2 -0
- data/lib/generators/seivan/html5/templates/_head.html.haml +1 -6
- data/lib/generators/seivan/html5/templates/_javascripts.html.haml +1 -1
- metadata +3 -3
@@ -22,6 +22,8 @@ Feature: Seivan Authentication Generator
|
|
22
22
|
| match 'signup' => 'users#new', :as => :signup |
|
23
23
|
| match 'user/edit' => 'users#edit', :as => :edit_user |
|
24
24
|
And I should see "include ControllerAuthentication" in file "app/controllers/application_controller.rb"
|
25
|
+
And I should see "conditions = ['username = ? or email = ?', login, login]" in file "app/models/user.rb"
|
26
|
+
And I should see "user = User.where(conditions).first" in file "app/models/user.rb"
|
25
27
|
And I should see "gem "mocha", :group => :test" in file "Gemfile"
|
26
28
|
And I should see "gem "bcrypt-ruby", :require => "bcrypt"" in file "Gemfile"
|
27
29
|
|
@@ -14,4 +14,5 @@ Feature: Seivan Config Generator
|
|
14
14
|
When I run "rails g seivan:config FooBar"
|
15
15
|
Then I should see "FOO_BAR_CONFIG" in file "config/initializers/load_foo_bar_config.rb"
|
16
16
|
And I should see "config/foo_bar_config.yml" in file "config/initializers/load_foo_bar_config.rb"
|
17
|
+
And I should see "default: &default" in file "config/foo_bar_config.yml"
|
17
18
|
And I should see file "config/foo_bar_config.yml"
|
@@ -8,18 +8,35 @@ class <%= user_class_name %> < ActiveRecord::Base
|
|
8
8
|
attr_accessor :password
|
9
9
|
before_save :prepare_password
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
validates :email,
|
12
|
+
:format => {:with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i,
|
13
|
+
:allow_blank => true,
|
14
|
+
:allow_nil => true },
|
15
|
+
:presence => { :if => lambda {self.username.nil?} },
|
16
|
+
:uniqueness => true
|
17
|
+
|
18
|
+
validates :username,
|
19
|
+
:format => {:with => /[A-Za-z0-9]+/, :allow_blank => true, :allow_nil => true},
|
20
|
+
:presence => { :if => lambda {self.email.nil?} },
|
21
|
+
:length => {:minimum => 3, :allow_blank => true},
|
22
|
+
:uniqueness => true
|
23
|
+
|
24
|
+
validates :role,
|
25
|
+
:inclusion => { :in => %w(admin moderator writer user guest) }
|
26
|
+
|
27
|
+
validates :password,
|
28
|
+
:length => {:minimum => 3},
|
29
|
+
:presence => true
|
30
|
+
|
31
|
+
|
32
|
+
|
18
33
|
|
19
34
|
# login can be either username or email address
|
20
|
-
def self.authenticate(
|
21
|
-
|
22
|
-
|
35
|
+
def self.authenticate(params)
|
36
|
+
login = params[:login]
|
37
|
+
conditions = ['username = ? or email = ?', login, login]
|
38
|
+
<%= user_singular_name %> = <%= user_class_name %>.where(conditions).first
|
39
|
+
return <%= user_singular_name %> if <%= user_singular_name %> && <%= user_singular_name %>.matching_password?(params[:password])
|
23
40
|
end
|
24
41
|
|
25
42
|
def matching_password?(pass)
|
@@ -1,9 +1,6 @@
|
|
1
1
|
%head
|
2
2
|
%meta{ :charset => "utf-8" }/
|
3
3
|
|
4
|
-
-#
|
5
|
-
Always force latest IE rendering engine (even in intranet) & Chrome Frame
|
6
|
-
Remove this if you use the .htaccess
|
7
4
|
%meta{ :content => "IE=edge,chrome=1", "http-equiv" => "X-UA-Compatible" }/
|
8
5
|
|
9
6
|
%title
|
@@ -20,8 +17,6 @@
|
|
20
17
|
-# %link{ :href => "/apple-touch-icon.png", :rel => "apple-touch-icon" }/
|
21
18
|
|
22
19
|
= render :partial => 'layouts/stylesheets'
|
23
|
-
|
24
|
-
-# All JavaScript at the bottom, except for Modernizr which enables HTML5 elements & feature detects
|
25
|
-
= javascript_include_tag 'modernizr-1.5.min'
|
20
|
+
|
26
21
|
|
27
22
|
= csrf_meta_tag
|
@@ -6,7 +6,7 @@
|
|
6
6
|
-# asynchronous google analytics: mathiasbynens.be/notes/async-analytics-snippet
|
7
7
|
-# Generate a rails g seivan:config google and write the credentials in config/google.yml
|
8
8
|
:javascript
|
9
|
-
var _gaq = [['_setAccount', '#{
|
9
|
+
var _gaq = [['_setAccount', '#{APP_CONFIG[:account_id]}'], ['_trackPageview']];
|
10
10
|
(function(d, t) {
|
11
11
|
var g = d.createElement(t),
|
12
12
|
s = d.getElementsByTagName(t)[0];
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
version: "0.
|
7
|
+
- 4
|
8
|
+
version: "0.4"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Seivan Heidari
|
@@ -13,7 +13,7 @@ autorequire:
|
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2010-10-
|
16
|
+
date: 2010-10-31 00:00:00 +02:00
|
17
17
|
default_executable:
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|