authem 1.0.0.rc1 → 1.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +102 -0
- data/lib/authem/controller_support.rb +2 -1
- data/lib/authem/version.rb +1 -1
- data/lib/generators/authem/model/model_generator.rb +23 -0
- metadata +3 -2
data/README.markdown
CHANGED
@@ -8,6 +8,102 @@ Authem is tested against Ruby 1.9.2, 1.9.3, Rubinius
|
|
8
8
|
|
9
9
|
[![Build Status](https://secure.travis-ci.org/paulelliott/authem.png)](http://travis-ci.org/paulelliott/authem)
|
10
10
|
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add the following to your project's Gemfile:
|
14
|
+
|
15
|
+
gem 'authem'
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### Model Setup
|
20
|
+
|
21
|
+
Tell authem which of your classes will be used for authentication
|
22
|
+
|
23
|
+
Authem.configure do |config|
|
24
|
+
config.user_class = User
|
25
|
+
end
|
26
|
+
|
27
|
+
Once you've decided which class to use for authentication, make sure it has
|
28
|
+
access to database columns called:
|
29
|
+
|
30
|
+
* email
|
31
|
+
* salt
|
32
|
+
* crypted\_password
|
33
|
+
|
34
|
+
Then in your model
|
35
|
+
|
36
|
+
include Authem::Model
|
37
|
+
|
38
|
+
#### Model Usage
|
39
|
+
|
40
|
+
Now that your class is all set up using Authem...
|
41
|
+
|
42
|
+
Provide your instance with the following attributes:
|
43
|
+
|
44
|
+
* email
|
45
|
+
* password
|
46
|
+
* password\_confirmation
|
47
|
+
|
48
|
+
Example:
|
49
|
+
|
50
|
+
User.new(
|
51
|
+
email: 'matt@example.com',
|
52
|
+
password: '$ushi',
|
53
|
+
password_confirmation: '$ushi'
|
54
|
+
)
|
55
|
+
|
56
|
+
When saved, the password is hashed and stored as `crypted_password` in your
|
57
|
+
database.
|
58
|
+
|
59
|
+
You can call back to the model with `User#authenticate`, passing it email and
|
60
|
+
password, which returns self if the credentials are correct, otherwise
|
61
|
+
it returns nil.
|
62
|
+
|
63
|
+
### Controller Usage
|
64
|
+
|
65
|
+
In your application controller:
|
66
|
+
|
67
|
+
include Authem::ControllerSupport
|
68
|
+
|
69
|
+
Which gives you access to
|
70
|
+
|
71
|
+
* `current_user`
|
72
|
+
* `signed_in?`
|
73
|
+
* `require_user`
|
74
|
+
* `sign_in`
|
75
|
+
* `sign_out`
|
76
|
+
* `remember_me!`
|
77
|
+
* `establish_presence`
|
78
|
+
* `redirect_back_or_to`
|
79
|
+
|
80
|
+
Then require authentication for a whole controller or action(s) with:
|
81
|
+
|
82
|
+
before_filter :require_user
|
83
|
+
|
84
|
+
For signing in users, try a SessionsController like the following
|
85
|
+
|
86
|
+
class UserSessionsController < ApplicationController
|
87
|
+
skip_before_filter :require_user, except: :destroy
|
88
|
+
|
89
|
+
def create
|
90
|
+
if sign_in(params[:email], params[:password])
|
91
|
+
redirect_back_or_to(new_post_path)
|
92
|
+
else
|
93
|
+
render :new
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
## Configuration
|
99
|
+
|
100
|
+
Currently, authem lets you configure the user class and sign in path:
|
101
|
+
|
102
|
+
Authem.configure do |config|
|
103
|
+
config.user_class = Admin
|
104
|
+
config.sign_in_path = :log_in
|
105
|
+
end
|
106
|
+
|
11
107
|
## Contribute
|
12
108
|
|
13
109
|
Pull requests are welcome; please provide spec coverage for new code.
|
@@ -15,3 +111,9 @@ Pull requests are welcome; please provide spec coverage for new code.
|
|
15
111
|
* `bundle install`
|
16
112
|
* `rake`
|
17
113
|
|
114
|
+
## Thanks
|
115
|
+
|
116
|
+
* mattonrails
|
117
|
+
* narwen
|
118
|
+
* mattpolito
|
119
|
+
* knwang
|
@@ -26,7 +26,7 @@ module Authem::ControllerSupport
|
|
26
26
|
|
27
27
|
def require_user
|
28
28
|
unless current_user
|
29
|
-
session[:return_to_url] = request.url
|
29
|
+
session[:return_to_url] = request.url unless request.url.xhr?
|
30
30
|
redirect_to Authem::Config.sign_in_path
|
31
31
|
end
|
32
32
|
end
|
@@ -43,6 +43,7 @@ module Authem::ControllerSupport
|
|
43
43
|
|
44
44
|
included do
|
45
45
|
helper_method :current_user
|
46
|
+
helper_method :signed_in?
|
46
47
|
end
|
47
48
|
|
48
49
|
end
|
data/lib/authem/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Authem
|
4
|
+
class ModelGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
argument :model_name, type: :string, default: "user"
|
7
|
+
|
8
|
+
def generate_model
|
9
|
+
generate("model #{model_name} email:string, password_digest:string, reset_password_token:string, session_token:string")
|
10
|
+
end
|
11
|
+
|
12
|
+
def update_model_to_include_authem
|
13
|
+
insert_into_file "app/models/#{model_name}.rb", "\n include Authem::User\n\n", after: "class #{model_name.camelize} < ActiveRecord::Base\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_initializer
|
17
|
+
create_file 'config/initializers/authem.rb' do
|
18
|
+
%Q(Authem.configure do |config|\n config.user_class = #{model_name.camelize}\nend)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc2
|
5
5
|
prerelease: 6
|
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: 2012-
|
12
|
+
date: 2012-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/authem/user.rb
|
171
171
|
- lib/authem/version.rb
|
172
172
|
- lib/authem.rb
|
173
|
+
- lib/generators/authem/model/model_generator.rb
|
173
174
|
- LICENSE
|
174
175
|
- README.markdown
|
175
176
|
- Rakefile
|