user_authentication 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/application_controller.rb +4 -4
- data/app/controllers/users_controller.rb +12 -6
- data/app/views/{users → shared}/_login.html.erb +3 -0
- data/app/views/shared/_signup.html.erb +18 -0
- data/app/views/users/login.html.erb +1 -0
- data/app/views/users/signup.html.erb +1 -0
- data/config/routes.rb +9 -4
- data/lib/user_authentication/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17f2717aefc439f9917b101b30ba05ad47a4beae
|
4
|
+
data.tar.gz: 8f5836d3a23da681d90d6967929275f036e2e82c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aab8a8a433b7b7dd6e1919de7233f7e59755049b269b98d1aea019aa3fdf3a2fea9a0554787f799aa6ddc39205d2d4fe0b76dc4fefc5edd06e57d42d697fe4b
|
7
|
+
data.tar.gz: 45d750a8beddee8285497e2c3ee3af5e8c4d23d63c23bd95b55caeeaf019c401eaea040926a2d206a3d8f5c4eb4d1f6e79e5e13c2ed01ce4a60f18f245e05af4
|
@@ -4,9 +4,9 @@ class ApplicationController < ActionController::Base
|
|
4
4
|
# private
|
5
5
|
|
6
6
|
def authorize
|
7
|
-
# Not using skip_before_filter, since main app could inadvertently override that
|
8
|
-
# by using a before_filter in its application_controller.
|
9
|
-
if params[:controller] ==
|
7
|
+
# Not using skip_before_filter, since main app could inadvertently override that
|
8
|
+
# by using a before_filter :authorize in its application_controller.
|
9
|
+
if params[:controller] == "users" && ["login", "logout", "signup"].include?(params[:action])
|
10
10
|
return true
|
11
11
|
end
|
12
12
|
|
@@ -31,4 +31,4 @@ class ApplicationController < ActionController::Base
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
require File.join Rails.root,
|
34
|
+
require File.join Rails.root, "app/controllers/application_controller"
|
@@ -2,6 +2,12 @@ class UsersController < ApplicationController
|
|
2
2
|
before_filter :authorize, only: [:set_password]
|
3
3
|
|
4
4
|
def login
|
5
|
+
end
|
6
|
+
|
7
|
+
def signup
|
8
|
+
end
|
9
|
+
|
10
|
+
def do_login
|
5
11
|
user = User.find_by_email params[:email]
|
6
12
|
if user && user.authenticate(params[:password])
|
7
13
|
session[:user_id] = user.id
|
@@ -10,25 +16,25 @@ class UsersController < ApplicationController
|
|
10
16
|
if respond_to? :on_login
|
11
17
|
on_login
|
12
18
|
else
|
13
|
-
redirect_to :back
|
19
|
+
redirect_to params[:redirect] || :back
|
14
20
|
end
|
15
21
|
else
|
16
22
|
redirect_to :back, alert: 'Please check email and password.'
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
20
|
-
def
|
26
|
+
def do_logout
|
21
27
|
session.delete :user_id
|
22
28
|
set_current_user
|
23
29
|
|
24
30
|
if respond_to? :on_logout
|
25
31
|
on_logout
|
26
32
|
else
|
27
|
-
redirect_to
|
33
|
+
redirect_to root_path
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
31
|
-
def
|
37
|
+
def do_signup
|
32
38
|
user = User.new
|
33
39
|
user.email = params[:email]
|
34
40
|
user.password = params[:password]
|
@@ -40,7 +46,7 @@ class UsersController < ApplicationController
|
|
40
46
|
if respond_to? :on_signup
|
41
47
|
on_signup
|
42
48
|
else
|
43
|
-
redirect_to :back
|
49
|
+
redirect_to params[:redirect] || :back
|
44
50
|
end
|
45
51
|
else
|
46
52
|
redirect_to :back, alert: 'Please check email and password.'
|
@@ -54,7 +60,7 @@ class UsersController < ApplicationController
|
|
54
60
|
if respond_to? :on_set_password
|
55
61
|
on_set_password
|
56
62
|
else
|
57
|
-
redirect_to :back
|
63
|
+
redirect_to params[:redirect] || :back
|
58
64
|
end
|
59
65
|
end
|
60
66
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%= form_tag signup_path do %>
|
2
|
+
<% if local_assigns.include?(:redirect) %>
|
3
|
+
<%= hidden_field_tag :redirect, redirect %>
|
4
|
+
<% end %>
|
5
|
+
<%= label_tag :email, "Your email" %>
|
6
|
+
<br>
|
7
|
+
<%= text_field_tag :email, params[:email] %>
|
8
|
+
<br>
|
9
|
+
<%= label_tag :email_confirmation, "Confirm your email" %>
|
10
|
+
<br>
|
11
|
+
<%= text_field_tag :email_confirmation, params[:email_confirmation] %>
|
12
|
+
<br>
|
13
|
+
<%= label_tag :password, "Choose a password" %>
|
14
|
+
<br>
|
15
|
+
<%= password_field_tag :password %>
|
16
|
+
<br>
|
17
|
+
<%= submit_tag "Sign Up" %>
|
18
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render "shared/login" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render "shared/signup" %>
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
match
|
3
|
-
match
|
4
|
-
|
5
|
-
match
|
2
|
+
match "login" => "users#login", :via => :get
|
3
|
+
match "login" => "users#do_login", :via => :post
|
4
|
+
|
5
|
+
match "logout" => "users#do_logout", :via => :get
|
6
|
+
|
7
|
+
match "signup" => "users#signup", :via => :get
|
8
|
+
match "signup" => "users#do_signup", :via => :post
|
9
|
+
|
10
|
+
match "set_password" => "users#set_password", :via => :post
|
6
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: user_authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sujoy Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -162,7 +162,10 @@ files:
|
|
162
162
|
- app/helpers/application_helper.rb
|
163
163
|
- app/models/user.rb
|
164
164
|
- app/validators/email_validator.rb
|
165
|
-
- app/views/
|
165
|
+
- app/views/shared/_login.html.erb
|
166
|
+
- app/views/shared/_signup.html.erb
|
167
|
+
- app/views/users/login.html.erb
|
168
|
+
- app/views/users/signup.html.erb
|
166
169
|
- config/routes.rb
|
167
170
|
- db/migrate/20121009010000_create_users.rb
|
168
171
|
- lib/random.rb
|