basic-initial-rails4 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +127 -1
- data/lib/basic/initial/rails4/version.rb +1 -1
- data/lib/generators/binstall/binstall_generator.rb +9 -0
- data/spec/factories/user.rb +8 -0
- data/spec/features/login_spec.rb +33 -0
- metadata +4 -3
- data/app/models/user.rb +0 -11
data/README.md
CHANGED
@@ -8,6 +8,20 @@ Add this line to your application's Gemfile:
|
|
8
8
|
|
9
9
|
gem 'basic-initial-rails4'
|
10
10
|
|
11
|
+
Add permited omniauth gem in you Gemfile:
|
12
|
+
|
13
|
+
gem 'omniauth-facebook'
|
14
|
+
gem 'omniauth-twitter'
|
15
|
+
gem 'omniauth-linkedin'
|
16
|
+
gem 'omniauth-github'
|
17
|
+
|
18
|
+
You can view documentation for each omniauth gem in:
|
19
|
+
|
20
|
+
- [omniauth-facebook](https://github.com/mkdynamic/omniauth-facebook)
|
21
|
+
- [omniauth-twitter](https://github.com/arunagw/omniauth-twitter)
|
22
|
+
- [omniauth-linkedin](https://github.com/skorks/omniauth-linkedin)
|
23
|
+
- [omniauth-github](https://github.com/intridea/omniauth-github)
|
24
|
+
|
11
25
|
And then execute:
|
12
26
|
|
13
27
|
$ bundle
|
@@ -18,7 +32,119 @@ Or install it yourself as:
|
|
18
32
|
|
19
33
|
## Usage
|
20
34
|
|
21
|
-
|
35
|
+
execute:
|
36
|
+
|
37
|
+
$ rails generate model user name email password_digest id_facebook id_twitter id_linkedin id_github
|
38
|
+
$ rails generate binstall
|
39
|
+
|
40
|
+
### This proccess write and create an important methods and files
|
41
|
+
|
42
|
+
- config/initializers/mail.rb
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
ActionMailer::Base.smtp_settings = {
|
46
|
+
user_name: 'example@example.com', #use the smtp user account
|
47
|
+
password: 'example', #put a password
|
48
|
+
address: 'smtp_settings', #use a smtp url smtp.gmail.com, smtp.live.com, etc.
|
49
|
+
port: 587, #use a port to smtp settings
|
50
|
+
enable_starttls: true #use a tls (Transport Layer Security)
|
51
|
+
}
|
52
|
+
```
|
53
|
+
|
54
|
+
[Transport Layer Security](http://en.wikipedia.org/wiki/Transport_Layer_Security)
|
55
|
+
|
56
|
+
- [config/initializers/omniauth.rb](../master/lib/generators/binstall/templates/config/initializers/omniauth.rb)
|
57
|
+
|
58
|
+
- app/mailers/notifier.rb
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
class Notifier < ActionMailer::Base
|
62
|
+
from_address = ActionMailer::Base.smtp_settings[:user_name]
|
63
|
+
default from: "App Name <#{from_address}"
|
64
|
+
|
65
|
+
def mail_method(mail)
|
66
|
+
subject = "#{mail.subject} from App name"
|
67
|
+
mail(to: mail.email, subject: subject)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
```
|
71
|
+
- config/environments/development.rb
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
config.action_mailer.delivery_method = :smtp
|
75
|
+
config.action_mailer.perform_deliveries = true
|
76
|
+
```
|
77
|
+
|
78
|
+
This file have a:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
config.action_mailer.raise_delivery_errors = false
|
82
|
+
```
|
83
|
+
|
84
|
+
Change to true
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
config.action_mailer.raise_delivery_errors = true
|
88
|
+
```
|
89
|
+
|
90
|
+
- app/notifier/mail_method.html.rb
|
91
|
+
|
92
|
+
Empty file represent the theme for mail send
|
93
|
+
|
94
|
+
- app/controllers/application_controller.rb
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
before_filter :load_initial
|
98
|
+
def load_initial
|
99
|
+
@init_twitter = nil #change nil to anithing valor to view = link_to 'Twitter', '/auth/twitter'
|
100
|
+
@init_github = nil #this load a = link_to 'Github', '/auth/github'
|
101
|
+
@init_facebook = nil #this load a = link_to 'Facebook', '/auth/facebook'
|
102
|
+
@init_linkedin = nil #this load a = link_to 'Linked_in', '/auth/linked_in'
|
103
|
+
end
|
104
|
+
|
105
|
+
def is_login!
|
106
|
+
if session[:user_id].nil?
|
107
|
+
redirect_to sessions_new_path, notice: 'You need login to load this section'
|
108
|
+
elsif $current_user.nil?
|
109
|
+
$current_user = User.find_by_id(session[:user_id])
|
110
|
+
end
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
- config/routes.rb
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
get 'sessions/new'
|
118
|
+
post 'sessions/new', to: 'sessions#create'
|
119
|
+
get 'sessions/destroy', to: 'sessions#logout'
|
120
|
+
resources :users, only: [:index, :create, :new]
|
121
|
+
get '/auth/:provider/callback', to: 'sessions#create'
|
122
|
+
get '/auth/failure', to: 'sessions#failure'
|
123
|
+
```
|
124
|
+
|
125
|
+
- app/models/user.rb
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
has_secure_password
|
129
|
+
validates :name, presence: true, uniqueness: true, length: { minimum: 5, maximum: 18}, format: {with: /[a-zA-Z\s]/}
|
130
|
+
validates :password, presence: true, length: { minimum: 8, maximum: 24}
|
131
|
+
validates :email, presence: true, uniqueness: true, format: {with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
|
132
|
+
```
|
133
|
+
|
134
|
+
## Notes of usage
|
135
|
+
|
136
|
+
### Your need a root to in routes.rb file
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
root to: 'controller_name#method_name'
|
140
|
+
```
|
141
|
+
## spec notes
|
142
|
+
|
143
|
+
So test a controller with is_login! before_filter you need include
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
session[:user_id] = user.id #where user is a instance of User model (factory)
|
147
|
+
```
|
22
148
|
|
23
149
|
## Contributing
|
24
150
|
|
@@ -54,4 +54,13 @@ class BinstallGenerator < Rails::Generators::Base
|
|
54
54
|
get '/auth/failure', to: 'sessions#failure'"
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
def load_user_validates
|
59
|
+
inject_into_file 'app/models/user.rb', after: 'Base' do
|
60
|
+
"\n has_secure_password
|
61
|
+
validates :name, presence: true, uniqueness: true, length: { minimum: 5, maximum: 18}, format: {with: /[a-zA-Z\\s]/}
|
62
|
+
validates :password, presence: true, length: { minimum: 8, maximum: 24}
|
63
|
+
validates :email, presence: true, uniqueness: true, format: {with: /\\A([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,})\\Z/i}"
|
64
|
+
end
|
65
|
+
end
|
57
66
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'login in site' do
|
4
|
+
let!(:oscar){FactoryGirl.create(:user)}
|
5
|
+
|
6
|
+
scenario 'login' do
|
7
|
+
visit sessions_new_path
|
8
|
+
fill_in 'email', with: 'oscar@oscar.com'
|
9
|
+
fill_in 'password', with: '12345678'
|
10
|
+
fill_in 'password_confirmation', with: '12345678'
|
11
|
+
click_button 'Sign in'
|
12
|
+
page.should have_content('Logout')
|
13
|
+
end
|
14
|
+
|
15
|
+
scenario 'not login' do
|
16
|
+
visit sessions_new_path
|
17
|
+
fill_in 'email', with: 'oscar@oscar.co'
|
18
|
+
fill_in 'password', with: '12345678'
|
19
|
+
fill_in 'password_confirmation', with: '12345678'
|
20
|
+
click_button 'Sign in'
|
21
|
+
page.should have_content('User or password error')
|
22
|
+
end
|
23
|
+
|
24
|
+
scenario 'created a user' do
|
25
|
+
visit new_user_path
|
26
|
+
fill_in 'name', with: 'Oscar'
|
27
|
+
fill_in 'email', with: 'oscar@oscar.com'
|
28
|
+
fill_in 'password', with: '12345678'
|
29
|
+
fill_in 'password_confirmation', with: '12345678'
|
30
|
+
click_button 'Sign up'
|
31
|
+
page.should have_content('Sign in successfull')
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basic-initial-rails4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -189,7 +189,6 @@ files:
|
|
189
189
|
- app/controllers/users_controller.rb
|
190
190
|
- app/models/.keep
|
191
191
|
- app/models/session_user.rb
|
192
|
-
- app/models/user.rb
|
193
192
|
- app/views/sessions/new.html.haml
|
194
193
|
- app/views/users/new.html.haml
|
195
194
|
- basic-initial-rails4.gemspec
|
@@ -200,6 +199,8 @@ files:
|
|
200
199
|
- lib/generators/binstall/templates/config/initializers/omniauth.rb
|
201
200
|
- lib/generators/binstall/templates/layouts/application.html.haml
|
202
201
|
- lib/generators/binstall/templates/mailers/notifier.rb
|
202
|
+
- spec/factories/user.rb
|
203
|
+
- spec/features/login_spec.rb
|
203
204
|
homepage: ''
|
204
205
|
licenses:
|
205
206
|
- MIT
|
data/app/models/user.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
class User < ActiveRecord::Base
|
2
|
-
has_secure_password
|
3
|
-
validates_presence_of :name
|
4
|
-
validates_presence_of :email
|
5
|
-
validates_uniqueness_of :name
|
6
|
-
validates_uniqueness_of :email
|
7
|
-
validates_length_of :name, minimum: 5, maximum: 18
|
8
|
-
validates_length_of :password, minimum: 8, maximum: 24
|
9
|
-
validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,on: :create
|
10
|
-
validates_format_of :name, with: /[a-zA-Z]/
|
11
|
-
end
|