auth_easy 0.0.7.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/auth_easy.rb +5 -0
- data/lib/auth_easy/controller_additions.rb +36 -0
- data/lib/auth_easy/form_fields.rb +18 -0
- data/lib/auth_easy/form_helpers.rb +47 -0
- data/lib/auth_easy/registration_actions.rb +34 -0
- data/lib/auth_easy/sessions_actions.rb +25 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTIyODYyYTllNTVlN2RjZTE2ZmM0ZGI2YWM3OWQwZDFlNzcyYWExNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWVhOGRmMDg4YzRmYmFlMjY5N2EyOTdjYTQxOTEyNWVkYzA5ZWQ1OQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjYyYzE5NTU3ZTQ2YWE0MGNjNmQ1OTNkOTBjNWNjYzU3NDhlZTA3ZDZiOWNl
|
10
|
+
N2VmZTY5Mjg5ODRmMWE5MDY5ZWIzZTJhY2Q0ZTA5NDJlOTRlNjM1ZGY1MWRk
|
11
|
+
ZjNmY2RiNzZiNDU5ZDA2MTA2YWQ1ZTVjYzZlOGI2NzQ3OGFkYmQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjAyYjliMTMzZTU4ZDgwM2ExMjkxOGIxZTgxMDUxZDE3ZGZhMTA5MjI2Y2Yy
|
14
|
+
YWQzN2EzZTBlOGQzYmFlZjM3M2QxYWNlZjQ0NTY2ODJkZTk0ZTIwMTM4MWY0
|
15
|
+
NjdkM2RiMGJlNzVmZmQ2ZTkzODBhOGYwMmVhNmM0MTZkN2Q5NjI=
|
data/lib/auth_easy.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module AuthEasy
|
2
|
+
|
3
|
+
module ControllerAdditions
|
4
|
+
def login_required
|
5
|
+
redirect_to(login_path, :notice => "You're not logged in") if !logged_in?
|
6
|
+
end
|
7
|
+
|
8
|
+
def logged_in?
|
9
|
+
!!current_user
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_user
|
13
|
+
# raise session[:user_id].inspect
|
14
|
+
@current_user ||= User.find(session[:user_id]) if session[:user_id]
|
15
|
+
end
|
16
|
+
|
17
|
+
def login(user)
|
18
|
+
session[:user_id] = user.id
|
19
|
+
@current_user = user
|
20
|
+
end
|
21
|
+
|
22
|
+
def tester
|
23
|
+
"This is a test return!!!!!"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.included(base)
|
27
|
+
base.helper_method :current_user, :logged_in?, :tester
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if defined? ActionController::Base
|
33
|
+
ActionController::Base.class_eval do
|
34
|
+
include AuthEasy::ControllerAdditions
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module FormInputFields
|
2
|
+
def fields
|
3
|
+
"<input name='utf8' type='hidden' value='✓' /><input name='authenticity_token' type='hidden' value='bdFmr91W7R9zUskugsJD2IocJL0jurJ48eSZ0uKHloU=' /></div>
|
4
|
+
"+ email_field + password_field + submit_field
|
5
|
+
end
|
6
|
+
|
7
|
+
def email_field
|
8
|
+
"<label for='email'>Email</label><input id='email' name='user[email]' type='text' /><br>"
|
9
|
+
end
|
10
|
+
|
11
|
+
def password_field
|
12
|
+
"<label for='password'>Password</label>
|
13
|
+
<input id='password' name='user[password]' type='password' /><br>"
|
14
|
+
end
|
15
|
+
def submit_field
|
16
|
+
"<input name='commit' type='submit' value='submit' />"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module AuthEasy
|
2
|
+
module LoginFormHelpers
|
3
|
+
include FormInputFields
|
4
|
+
|
5
|
+
def simple_login_form
|
6
|
+
form = "<form accept-charset='UTF-8' action='/sessions' method='post'><div style='margin:0;padding:0;display:inline'>" + fields + "</form>"
|
7
|
+
form.html_safe
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.included(base)
|
11
|
+
base.helper_method :simple_login_form
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module RegisterFormHelpers
|
16
|
+
include FormInputFields
|
17
|
+
|
18
|
+
def simple_register_form
|
19
|
+
form = "<form accept-charset='UTF-8' action='/users' method='post'><div style='margin:0;padding:0;display:inline'>" + fields + "</form>"
|
20
|
+
form.html_safe
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.included(base)
|
24
|
+
base.helper_method :simple_register_form
|
25
|
+
end
|
26
|
+
end
|
27
|
+
module LogOut
|
28
|
+
def simple_logout_link
|
29
|
+
"<a href='/logout' data-method='delete'>logout</a>".html_safe
|
30
|
+
end
|
31
|
+
def self.included(base)
|
32
|
+
base.helper_method :simple_logout_link
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if defined? ActionController::Base
|
38
|
+
ActionController::Base.class_eval do
|
39
|
+
include AuthEasy::LoginFormHelpers
|
40
|
+
include AuthEasy::RegisterFormHelpers
|
41
|
+
include AuthEasy::LogOut
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module AuthEasy
|
2
|
+
module RegistrationActions
|
3
|
+
def new
|
4
|
+
end
|
5
|
+
|
6
|
+
def create
|
7
|
+
@user = User.new(params[:user])
|
8
|
+
if @user.save
|
9
|
+
login(@user)
|
10
|
+
redirect_to request.referer
|
11
|
+
else
|
12
|
+
flash[:notice] = "Invalid Email or Password"
|
13
|
+
redirect_to action: 'new'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module UserModelAdditions
|
19
|
+
# The code below doesn't seem to work at all
|
20
|
+
# def self.included(base)
|
21
|
+
# base.send(:has_secure_password)
|
22
|
+
# base.send.(:attr_accessible, :email, :password)
|
23
|
+
# end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# To Use the registration actions add: include AuthEasy::RegistrationActions in your
|
28
|
+
# user controller
|
29
|
+
|
30
|
+
if defined? User
|
31
|
+
User.class_eval do
|
32
|
+
include AuthEasy::UserModelAdditions
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module AuthEasy
|
2
|
+
module SessionsActions
|
3
|
+
|
4
|
+
def new
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
user = User.find_by_email(params[:user][:email])
|
9
|
+
if user && user.authenticate(params[:user][:password])
|
10
|
+
login(user)
|
11
|
+
redirect_to request.referer, :notice => "Logged in!"
|
12
|
+
else
|
13
|
+
flash[:notice] = "Invalid Email or Password"
|
14
|
+
redirect_to request.referer
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy
|
19
|
+
reset_session
|
20
|
+
redirect_to request.referer, :notice => "Logged out!"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
#In order to use: include AuthEasy::SessionsActions in your SessionsController.
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: auth_easy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Deatherage
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bcrypt-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
description: Set up basic authentication and session management with dis gem
|
28
|
+
email: deatheragethomas@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/auth_easy.rb
|
34
|
+
- lib/auth_easy/controller_additions.rb
|
35
|
+
- lib/auth_easy/form_fields.rb
|
36
|
+
- lib/auth_easy/form_helpers.rb
|
37
|
+
- lib/auth_easy/registration_actions.rb
|
38
|
+
- lib/auth_easy/sessions_actions.rb
|
39
|
+
homepage: https://github.com/deatheragetr/auth-easy
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>'
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.3.1
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.0.3
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Easy Authentication
|
63
|
+
test_files: []
|