simple_login 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +21 -6
- data/lib/simple_login/version.rb +1 -1
- metadata +19 -25
- data/lib/rails/generators/simple_login/USAGE +0 -6
- data/lib/rails/generators/simple_login/simple_login_generator.rb +0 -49
- data/lib/rails/generators/simple_login/templates/application_controller.rb +0 -15
- data/lib/rails/generators/simple_login/templates/controllers/password_resets_controller.rb +0 -25
- data/lib/rails/generators/simple_login/templates/controllers/sessions_controller.rb +0 -25
- data/lib/rails/generators/simple_login/templates/controllers/users_controller.rb +0 -17
- data/lib/rails/generators/simple_login/templates/create_users.rb +0 -13
- data/lib/rails/generators/simple_login/templates/mailers/user_mailer.rb +0 -18
- data/lib/rails/generators/simple_login/templates/models/user.rb +0 -32
- data/lib/rails/generators/simple_login/templates/views/password_resets/edit.html.erb +0 -35
- data/lib/rails/generators/simple_login/templates/views/password_resets/new.html.erb +0 -20
- data/lib/rails/generators/simple_login/templates/views/sessions/new.html.erb +0 -31
- data/lib/rails/generators/simple_login/templates/views/user_mailer/account_confirmation.text.erb +0 -5
- data/lib/rails/generators/simple_login/templates/views/user_mailer/password_reset.text.erb +0 -5
- data/lib/rails/generators/simple_login/templates/views/users/new.html.erb +0 -40
data/README.md
CHANGED
@@ -20,13 +20,13 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
Once you've added the gem into your Gemfile, you only need to run the following command:
|
22
22
|
|
23
|
-
rails g simple_login
|
23
|
+
rails g simple_login
|
24
24
|
|
25
25
|
Rails will generate the login and view files.
|
26
26
|
|
27
27
|
Then run:
|
28
28
|
|
29
|
-
rake db:migrate
|
29
|
+
rake db:migrate
|
30
30
|
|
31
31
|
The user table will be created.
|
32
32
|
|
@@ -34,10 +34,25 @@ I also recommend activating the root_path.
|
|
34
34
|
|
35
35
|
To add the links to your app just add the following paths:
|
36
36
|
|
37
|
-
signup_path
|
38
|
-
login_path
|
39
|
-
logout_path
|
40
|
-
password_reset_path
|
37
|
+
signup_path
|
38
|
+
login_path
|
39
|
+
logout_path
|
40
|
+
password_reset_path
|
41
|
+
|
42
|
+
## Out of the box use
|
43
|
+
|
44
|
+
You can run
|
45
|
+
|
46
|
+
rails s
|
47
|
+
|
48
|
+
Open your browser and access http://localhost:3000
|
49
|
+
|
50
|
+
Then you can access the following routes:
|
51
|
+
|
52
|
+
http://localhost:3000/signup
|
53
|
+
http://localhost:3000/login
|
54
|
+
http://localhost:3000/logout
|
55
|
+
http://localhost:3000/password_reset
|
41
56
|
|
42
57
|
## Contributing
|
43
58
|
|
data/lib/simple_login/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_login
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,39 +10,33 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-05-03 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: simple-login
|
16
|
+
requirement: &70107449673020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70107449673020
|
25
|
+
description: This is going to route to simple-login latest version.
|
26
|
+
email: designium+simple@gmail.com
|
18
27
|
executables: []
|
19
28
|
extensions: []
|
20
29
|
extra_rdoc_files: []
|
21
30
|
files:
|
22
|
-
- lib/rails/generators/simple_login/simple_login_generator.rb
|
23
|
-
- lib/rails/generators/simple_login/templates/application_controller.rb
|
24
|
-
- lib/rails/generators/simple_login/templates/controllers/password_resets_controller.rb
|
25
|
-
- lib/rails/generators/simple_login/templates/controllers/sessions_controller.rb
|
26
|
-
- lib/rails/generators/simple_login/templates/controllers/users_controller.rb
|
27
|
-
- lib/rails/generators/simple_login/templates/create_users.rb
|
28
|
-
- lib/rails/generators/simple_login/templates/mailers/user_mailer.rb
|
29
|
-
- lib/rails/generators/simple_login/templates/models/user.rb
|
30
|
-
- lib/rails/generators/simple_login/templates/views/password_resets/edit.html.erb
|
31
|
-
- lib/rails/generators/simple_login/templates/views/password_resets/new.html.erb
|
32
|
-
- lib/rails/generators/simple_login/templates/views/sessions/new.html.erb
|
33
|
-
- lib/rails/generators/simple_login/templates/views/user_mailer/account_confirmation.text.erb
|
34
|
-
- lib/rails/generators/simple_login/templates/views/user_mailer/password_reset.text.erb
|
35
|
-
- lib/rails/generators/simple_login/templates/views/users/new.html.erb
|
36
|
-
- lib/rails/generators/simple_login/USAGE
|
37
31
|
- lib/simple_login/version.rb
|
38
32
|
- lib/simple_login.rb
|
39
33
|
- Gemfile
|
40
34
|
- LICENSE
|
41
35
|
- Rakefile
|
42
36
|
- README.md
|
43
|
-
homepage:
|
37
|
+
homepage: https://github.com/designium/simple-login
|
44
38
|
licenses: []
|
45
|
-
post_install_message:
|
39
|
+
post_install_message: ! '***************************************'
|
46
40
|
rdoc_options: []
|
47
41
|
require_paths:
|
48
42
|
- lib
|
@@ -63,6 +57,6 @@ rubyforge_project:
|
|
63
57
|
rubygems_version: 1.8.11
|
64
58
|
signing_key:
|
65
59
|
specification_version: 3
|
66
|
-
summary:
|
67
|
-
the following command 'rails g
|
60
|
+
summary: simple-login can be used easily by adding the gem into your Gemfile and type
|
61
|
+
the following command 'rails g simple-login'.
|
68
62
|
test_files: []
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module SimpleLogin
|
2
|
-
module Generators
|
3
|
-
class SimpleLoginGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path('../templates', __FILE__)
|
5
|
-
|
6
|
-
|
7
|
-
def generate_user
|
8
|
-
# Copy the controllers for user, sessions and password_reset
|
9
|
-
directory "controllers", "app/controllers/"
|
10
|
-
directory "mailers", "app/mailers/"
|
11
|
-
directory "models", "app/models/"
|
12
|
-
directory "views", "app/views/"
|
13
|
-
end
|
14
|
-
|
15
|
-
def insert_general_methods
|
16
|
-
inject_into_file "app/controllers/application_controller.rb", after: "protect_from_forgery" do
|
17
|
-
a = "\n\n private\n\n def current_user\n"
|
18
|
-
b = " @current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]\n"
|
19
|
-
c = " end\n"
|
20
|
-
d = "\n helper_method :current_user\n\n"
|
21
|
-
e = " def authorize\n"
|
22
|
-
f = " redirect_to login_url, alert: 'Not authorized. Please login.' if current_user.nil?\n"
|
23
|
-
g = " end\n"
|
24
|
-
a+b+c+d+e+f+g
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def insert_routes
|
29
|
-
route("match 'signup', to: 'users#new', as: 'signup'")
|
30
|
-
route("match 'login', to: 'sessions#new', as: 'login'")
|
31
|
-
route("match 'logout', to: 'sessions#destroy', as: 'logout'")
|
32
|
-
route("resources :users")
|
33
|
-
route("resources :sessions")
|
34
|
-
route("resources :password_resets")
|
35
|
-
end
|
36
|
-
|
37
|
-
def create_user
|
38
|
-
generate("model", "users email:string password_digest:string auth_token:string password_reset_token:string password_reset_sent_at:datetime")
|
39
|
-
rake("db:migrate")
|
40
|
-
end
|
41
|
-
|
42
|
-
def add_gems
|
43
|
-
gem("bcrypt-ruby")
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class ApplicationController < ActionController::Base
|
2
|
-
protect_from_forgery
|
3
|
-
|
4
|
-
private #PRIVATE PRIVATE PRIVATE
|
5
|
-
|
6
|
-
def current_user
|
7
|
-
@current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
|
8
|
-
end
|
9
|
-
|
10
|
-
helper_method :current_user
|
11
|
-
|
12
|
-
def authorize
|
13
|
-
redirect_to login_url, alert: "Not authorized. Please login." if current_user.nil?
|
14
|
-
end
|
15
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
class PasswordResetsController < ApplicationController
|
2
|
-
def new
|
3
|
-
end
|
4
|
-
|
5
|
-
def create
|
6
|
-
user = User.find_by_email(params[:email])
|
7
|
-
user.send_password_reset if user
|
8
|
-
redirect_to root_url, :notice => "Email sent with password reset instructions."
|
9
|
-
end
|
10
|
-
|
11
|
-
def edit
|
12
|
-
@user = User.find_by_password_reset_token!(params[:id])
|
13
|
-
end
|
14
|
-
|
15
|
-
def update
|
16
|
-
@user = User.find_by_password_reset_token!(params[:id])
|
17
|
-
if @user.password_reset_sent_at < 2.hours.ago
|
18
|
-
redirect_to new_password_reset_path, :alert => "Password reset has expired."
|
19
|
-
elsif @user.update_attributes(params[:user])
|
20
|
-
redirect_to root_url, :notice => "Password has been reset!"
|
21
|
-
else
|
22
|
-
render :edit
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
class SessionsController < ApplicationController
|
2
|
-
def new
|
3
|
-
end
|
4
|
-
|
5
|
-
def create
|
6
|
-
user = User.find_by_email(params[:email])
|
7
|
-
if user && user.authenticate(params[:password])
|
8
|
-
if params[:remember_me]
|
9
|
-
cookies.permanent[:auth_token] = user.auth_token
|
10
|
-
else
|
11
|
-
cookies[:auth_token] = user.auth_token
|
12
|
-
end
|
13
|
-
redirect_to root_url, :notice => "Logged in!"
|
14
|
-
else
|
15
|
-
flash.now.alert = "Invalid email or password"
|
16
|
-
render "new"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def destroy
|
21
|
-
cookies.delete(:auth_token)
|
22
|
-
redirect_to root_url, :notice => "Logged out!"
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class UsersController < ApplicationController
|
2
|
-
|
3
|
-
def new
|
4
|
-
@user = User.new
|
5
|
-
end
|
6
|
-
|
7
|
-
def create
|
8
|
-
@user = User.new(params[:user])
|
9
|
-
if @user.save
|
10
|
-
cookies[:auth_token] = @user.auth_token
|
11
|
-
redirect_to root_url
|
12
|
-
else
|
13
|
-
render "new"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class CreateUsers < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :users do |t|
|
4
|
-
t.string :email
|
5
|
-
t.string :password_digest
|
6
|
-
t.string :auth_token
|
7
|
-
t.string :password_reset_token
|
8
|
-
t.datetime :password_reset_sent_at
|
9
|
-
|
10
|
-
t.timestamps
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class UserMailer < ActionMailer::Base
|
2
|
-
default from: "your_email@example.com"
|
3
|
-
|
4
|
-
# Subject can be set in your I18n file at config/locales/en.yml
|
5
|
-
# with the following lookup:
|
6
|
-
#
|
7
|
-
# en.user_mailer.password_reset.subject
|
8
|
-
#
|
9
|
-
def password_reset(user)
|
10
|
-
@user = user
|
11
|
-
mail to: user.email, subject: "Password Reset"
|
12
|
-
end
|
13
|
-
|
14
|
-
def account_confirmation(user)
|
15
|
-
@user = user
|
16
|
-
mail to: @user.email, subject: "Welcome!"
|
17
|
-
end
|
18
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
class User < ActiveRecord::Base
|
2
|
-
|
3
|
-
has_secure_password
|
4
|
-
|
5
|
-
attr_accessible :email, :password, :password_confirmation
|
6
|
-
|
7
|
-
has_many :posts
|
8
|
-
|
9
|
-
validates_uniqueness_of :email
|
10
|
-
validates_presence_of :email
|
11
|
-
|
12
|
-
before_create { generate_token(:auth_token) }
|
13
|
-
after_create { send_account_confirmation }
|
14
|
-
|
15
|
-
def send_password_reset
|
16
|
-
generate_token(:password_reset_token)
|
17
|
-
self.password_reset_sent_at = Time.zone.now
|
18
|
-
save!
|
19
|
-
UserMailer.password_reset(self).deliver
|
20
|
-
end
|
21
|
-
|
22
|
-
def send_account_confirmation
|
23
|
-
UserMailer.account_confirmation(self).deliver
|
24
|
-
end
|
25
|
-
|
26
|
-
def generate_token(column)
|
27
|
-
begin
|
28
|
-
self[column] = SecureRandom.urlsafe_base64
|
29
|
-
end while User.exists?(column => self[column])
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
<!-- Edit password Non Modal -->
|
2
|
-
<div class="container">
|
3
|
-
<div class="row center">
|
4
|
-
<h1 style="margin-bottom: 20px;">Change Password</h1>
|
5
|
-
</div>
|
6
|
-
<div class="row">
|
7
|
-
<div class="span4 offset4 well">
|
8
|
-
<%= form_for @user, :url => password_reset_path(params[:id]), html: {class: "form"} do |f| %>
|
9
|
-
<% if @user.errors.any? %>
|
10
|
-
<div class="alert alert-error">
|
11
|
-
<h2>Form is invalid</h2>
|
12
|
-
<ul>
|
13
|
-
<% for message in @user.errors.full_messages %>
|
14
|
-
<li><%= message %></li>
|
15
|
-
<% end %>
|
16
|
-
</ul>
|
17
|
-
</div>
|
18
|
-
<% end %>
|
19
|
-
<fieldset>
|
20
|
-
<legend>Change Password</legend>
|
21
|
-
<div class="control-group">
|
22
|
-
<%= f.label :password, nil ,class: "control-label" %>
|
23
|
-
<div class="controls"><%= f.password_field :password %></div>
|
24
|
-
</div>
|
25
|
-
<div class="control-group">
|
26
|
-
<%= f.label :password_confirmation, nil ,class: "control-label" %>
|
27
|
-
<div class="controls"><%= f.password_field :password_confirmation %></div>
|
28
|
-
</div>
|
29
|
-
<div class="actions"><%= f.submit "Update Password", class: "btn btn-large btn-primary" %></div>
|
30
|
-
</fieldset>
|
31
|
-
<% end %>
|
32
|
-
</div>
|
33
|
-
</div>
|
34
|
-
</div>
|
35
|
-
<!-- End of Edit Password Non Modal -->
|
@@ -1,20 +0,0 @@
|
|
1
|
-
<!-- Reset Non Modal -->
|
2
|
-
|
3
|
-
<div class="container">
|
4
|
-
<div class="row">
|
5
|
-
<div class="span4 offset4 well">
|
6
|
-
<%= form_tag password_resets_path, :method => :post do %>
|
7
|
-
<fieldset>
|
8
|
-
<legend>Reset Password</legend>
|
9
|
-
<div class="control-group">
|
10
|
-
<%= label_tag :email, nil, class: "control-label" %>
|
11
|
-
<div class="controls"><%= text_field_tag :email, params[:email] %></div>
|
12
|
-
</div>
|
13
|
-
<div class="actions"><%= submit_tag t("user.reset_password", default: "Reset password"), class: "btn btn-large btn-primary" %></div>
|
14
|
-
</fieldset>
|
15
|
-
<% end %>
|
16
|
-
</div>
|
17
|
-
</div>
|
18
|
-
</div>
|
19
|
-
|
20
|
-
<!-- End of Reset Non Modal -->
|
@@ -1,31 +0,0 @@
|
|
1
|
-
<!-- Login Non Modal -->
|
2
|
-
|
3
|
-
<div class="container">
|
4
|
-
<div class="row">
|
5
|
-
<div class="span4 offset4 well">
|
6
|
-
<%= form_tag (sessions_path), class: "form" do %>
|
7
|
-
<fieldset>
|
8
|
-
<legend>Login</legend>
|
9
|
-
<div class="control-group">
|
10
|
-
<%= label_tag :email, nil ,class: "control-label" %>
|
11
|
-
<div class="controls"><%= text_field_tag :email, params[:email], class: "input-xlarge" %></div>
|
12
|
-
</div>
|
13
|
-
<div class="control-group">
|
14
|
-
<%= label_tag :password, nil, class: "control-label" %>
|
15
|
-
<div class="controls"><%= password_field_tag (:password), nil ,class: "input-xlarge" %></div>
|
16
|
-
</div>
|
17
|
-
<div class="control-group">
|
18
|
-
<%= label_tag :remember_me, nil, class: "control-label" %>
|
19
|
-
<%= check_box_tag :remember_me, 1, params[:remember_me] %>
|
20
|
-
</div>
|
21
|
-
<div class="actions"><%= submit_tag t("user.log_in", default: "Log in"), class: "btn btn-large btn-primary" %></div>
|
22
|
-
</fieldset>
|
23
|
-
<% end %>
|
24
|
-
<%= link_to t("user.forgotten_password", default: "Forgotten password?"), new_password_reset_path %> - <%= link_to t("user.sign_up", default: "Sign Up"), new_user_path %>
|
25
|
-
|
26
|
-
|
27
|
-
</div>
|
28
|
-
</div>
|
29
|
-
</div>
|
30
|
-
|
31
|
-
<!-- End of Login Non Modal -->
|
@@ -1,40 +0,0 @@
|
|
1
|
-
<!-- Sign UP Non Modal -->
|
2
|
-
<div class="container">
|
3
|
-
<div class="row center">
|
4
|
-
<h1 style="margin-bottom: 20px;">Sign Up</h1>
|
5
|
-
</div>
|
6
|
-
<div class="row">
|
7
|
-
<div class="span4 offset4 well">
|
8
|
-
<%= form_for @user, html: {class: "form"} do |f| %>
|
9
|
-
<% if @user.errors.any? %>
|
10
|
-
<div class="alert alert-error">
|
11
|
-
<h2>Form is invalid</h2>
|
12
|
-
<ul>
|
13
|
-
<% @user.errors.full_messages.each do |message| %>
|
14
|
-
<li><%= message %></li>
|
15
|
-
<% end %>
|
16
|
-
</ul>
|
17
|
-
</div>
|
18
|
-
<% end %>
|
19
|
-
<fieldset>
|
20
|
-
<legend>Sign Up</legend>
|
21
|
-
<div class="control-group">
|
22
|
-
<%= f.label :email, nil ,class: "control-label" %>
|
23
|
-
<div class="controls"><%= f.text_field :email, class: "input-xlarge" %></div>
|
24
|
-
</div>
|
25
|
-
<div class="control-group">
|
26
|
-
<%= f.label :password, nil ,class: "control-label" %>
|
27
|
-
<div class="controls"><%= f.password_field :password, class: "input-xlarge" %></div>
|
28
|
-
</div>
|
29
|
-
<div class="control-group">
|
30
|
-
<%= f.label :password_confirmation, nil ,class: "control-label" %>
|
31
|
-
<div class="controls"><%= f.password_field :password_confirmation, class: "input-xlarge" %></div>
|
32
|
-
</div>
|
33
|
-
|
34
|
-
<div class="actions"><%= f.submit t("user.sign_up", default: "Sign Up"), class: "btn btn-large btn-primary" %></div>
|
35
|
-
</fieldset>
|
36
|
-
<% end %>
|
37
|
-
</div>
|
38
|
-
</div>
|
39
|
-
</div>
|
40
|
-
<!-- End of Sing UP Non Modal -->
|