authem 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YmU3ZGJiMWZhNzdlY2VkNTAzNDRkYjUyOGI3NjQwMGRlMTZjOGI5Mw==
5
- data.tar.gz: !binary |-
6
- ZTVmOGQ1MjEzODYwYmEzNDc5ODMyNDlhZjk4ZTgzNmE4ZTM1YzY5Zg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- Yzc2NDYxNjgzN2Q1NmFkNjhkZGU1MjA0MjkwZjA5NjA1ZDQ4ZGViMTc1MmJm
10
- MTkzOWI5OGM2ZWY2ZDY2MDY0YTk0NWExOThlMzc2Yzg2MmEwZTNjYTRlNzQ1
11
- ZGYzN2M4NTFjOTEyZjgwYjc1NmM1MmVhNDE3NTJjZjc2ZGY2MTM=
12
- data.tar.gz: !binary |-
13
- ODZhOTI1NTFmNTEyMjVlMjBhNTBmMzQxMjE3NWYzZjBmNTdmNmFlYjI3MTMw
14
- MDU2OTU3MmM1YzNkOGY4ZDk3NzJmNDIxNGI3ODc4MzE0NmE5NWFlMDUyZTNl
15
- YmQzNmE1ZmU1YzU2NWEyZWMzZTg0MjhjNmQxNjhhYjE3NTFjOTg=
2
+ SHA1:
3
+ metadata.gz: a40c5db73a417e2772c43f44a1dba85b5e6adce1
4
+ data.tar.gz: 236197959698d38dff3f402bcbc1698da38d5a89
5
+ SHA512:
6
+ metadata.gz: c501d7b841f08db286efb0cd4b7e5c76039fd1a23872b9e8a391d4b1abbffb151391a88a32d18d5171f7e8c8eced89f458b6ebab2cca7638d6f71ca7d20e4cee
7
+ data.tar.gz: 98f8ae677bb99167796480d5bd7c05ee6d378a5c1f743226ccd36de9e8c74fdc9d137ccc93ce5046b2becd73b35f50e33258f6e2e8e9108c09e11d15aa640b57
data/README.markdown CHANGED
@@ -1,12 +1,13 @@
1
1
  # Authem
2
2
 
3
- Authem is an authentication library for Ruby web applications.
3
+ Authem is an email-based authentication library for Ruby web applications. It ONLY supports email/password authentication. It does not automatically integrate with Twitter, Facebook, or whatever oauth or SSO service you like the best. It is meant to handle user security but allow you to fully customize your user account behavior because the code is all yours.
4
4
 
5
5
  ## Compatibility
6
6
 
7
- Authem is tested against Ruby 1.9.2, 1.9.3, Rubinius
7
+ Authem is tested against Ruby 1.9.2, 1.9.3, 2.0.0, and Rubinius
8
8
 
9
9
  [![Build Status](https://secure.travis-ci.org/paulelliott/authem.png)](http://travis-ci.org/paulelliott/authem)
10
+ [![Code Climate](https://codeclimate.com/github/paulelliott/authem.png)](https://codeclimate.com/github/paulelliott/authem)
10
11
 
11
12
  ## Installation
12
13
 
@@ -14,26 +15,34 @@ Add the following to your project's Gemfile:
14
15
 
15
16
  gem 'authem'
16
17
 
18
+ Or for Rails 4:
19
+
20
+ gem 'authem', github: 'paulelliott/authem', branch: 'rails4'
21
+
17
22
  ## Usage
18
23
 
19
24
  ### Model Setup
20
25
 
21
- Tell authem which of your classes will be used for authentication
26
+ Tell authem which of your classes will be used for authentication in `config/initializers/authem.rb`
22
27
 
23
28
  Authem.configure do |config|
24
29
  config.user_class = User
25
30
  end
26
31
 
27
32
  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
+ the right stuff in the database.
34
+
35
+ create_table :users do |t|
36
+ t.column :email, :string
37
+ t.column :password_digest, :string
38
+ t.column :remember_token, :string
39
+ t.column :reset_password_token, :string
40
+ t.column :session_token, :string
41
+ end
33
42
 
34
43
  Then in your model
35
44
 
36
- include Authem::Model
45
+ include Authem::User
37
46
 
38
47
  #### Model Usage
39
48
 
@@ -53,13 +62,9 @@ Example:
53
62
  password_confirmation: '$ushi'
54
63
  )
55
64
 
56
- When saved, the password is hashed and stored as `crypted_password` in your
65
+ When saved, the password is hashed and stored as `password_digest` in your
57
66
  database.
58
67
 
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
68
  ### Controller Usage
64
69
 
65
70
  In your application controller:
@@ -68,40 +73,92 @@ In your application controller:
68
73
 
69
74
  Which gives you access to
70
75
 
71
- * `current_user`
72
- * `signed_in?`
73
- * `require_user`
74
76
  * `sign_in`
75
77
  * `sign_out`
76
- * `remember_me!`
77
- * `establish_presence`
78
+ * `current_user`
79
+ * `require_user`
80
+ * `signed_in?`
78
81
  * `redirect_back_or_to`
79
82
 
80
83
  Then require authentication for a whole controller or action(s) with:
81
84
 
82
- before_filter :require_user
85
+ before_filter :require_user, only: [:edit, :update]
86
+
87
+ Or get even crazier:
83
88
 
84
- For signing in users, try a SessionsController like the following
89
+ before_filter :maybe_require_user_under_certain_circumstances
90
+
91
+ private
92
+
93
+ def maybe_require_user_under_certain_circumstances
94
+ require_user if sky.blue? and rain.expected?
95
+ end
96
+
97
+ For signing in/out users, try a SessionsController like the following
85
98
 
86
99
  class UserSessionsController < ApplicationController
87
- skip_before_filter :require_user, except: :destroy
100
+ //works best with decent_exposure :)
101
+ expose(:user) { User.find_by_email(params[:email]) }
88
102
 
103
+ // expects params: { email: 'foo@example.com', password: 'bar' }
89
104
  def create
90
- if sign_in(params[:email], params[:password])
91
- redirect_back_or_to(new_post_path)
105
+ if user && user.authenticate(params[:password])
106
+ sign_in(user)
107
+ redirect_back_or_to(:profile)
92
108
  else
109
+ flash.now.alert = "Your email and password do not match"
93
110
  render :new
94
111
  end
95
112
  end
113
+
114
+ def destroy
115
+ sign_out
116
+ redirect_to :root
117
+ end
96
118
  end
97
119
 
120
+ Resetting passwords is a little more involved, but would look like this:
121
+
122
+ class PasswordResetsController < ApplicationController
123
+ //works best with decent_exposure :)
124
+ expose(:user_by_email) { User.find_by_email(params[:email]) }
125
+ expose(:user_by_token) { User.find_by_reset_password_token(params[:id]) }
126
+ expose(:reset_password_email) { UserMailer.reset_password_email(user_by_email) }
127
+
128
+ before_filter :verify_user, only: [:edit, :update]
129
+
130
+ // expects params: { email: 'foo@example.com' }
131
+ def create
132
+ reset_password_email.deliver if user_by_email
133
+ redirect_to [:new, :password_reset], alert: "Instructions for resetting your password have been sent to #{params[:email]}"
134
+ end
135
+
136
+ // expects params: { user: { password: 'bar', password_confirmation: 'bar' } }
137
+ def update
138
+ if user_by_token.reset_password(params[:user][:password], params[:user][:password_confirmation])
139
+ sign_in(user_by_token)
140
+ redirect_to :root
141
+ else
142
+ render :edit
143
+ end
144
+ end
145
+
146
+ protected
147
+
148
+ def verify_user
149
+ unless user_by_token
150
+ redirect_to [:new, :password_reset], alert: "We can't find your account with that token. You should try requesting another one."
151
+ end
152
+ end
153
+ end
154
+
155
+
98
156
  ## Configuration
99
157
 
100
- Currently, authem lets you configure the user class and sign in path:
158
+ Authem lets you configure the user class:
101
159
 
102
160
  Authem.configure do |config|
103
161
  config.user_class = Admin
104
- config.sign_in_path = :log_in
105
162
  end
106
163
 
107
164
  ## Contribute
@@ -110,10 +167,3 @@ Pull requests are welcome; please provide spec coverage for new code.
110
167
 
111
168
  * `bundle install`
112
169
  * `rake`
113
-
114
- ## Thanks
115
-
116
- * mattonrails
117
- * narwen
118
- * mattpolito
119
- * knwang
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- require 'bundler'
2
-
3
1
  require "rspec/core/rake_task"
4
2
  RSpec::Core::RakeTask.new(:spec) do |spec|
5
3
  spec.pattern = "spec/**/*_spec.rb"
@@ -4,10 +4,8 @@ module Authem::BaseUser
4
4
  extend ::ActiveSupport::Concern
5
5
 
6
6
  included do
7
- attr_accessible :email, :password, :password_confirmation
8
-
9
7
  validates_uniqueness_of :email
10
- validates_format_of :email, with: /^\S+@\S+$/
8
+ validates_format_of :email, with: /\A\S+@\S+\z/
11
9
  validates_presence_of :password, on: :create
12
10
  validates_confirmation_of :password
13
11
  end
@@ -1,3 +1,3 @@
1
1
  module Authem
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,139 +1,139 @@
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.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Elliott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-01 00:00:00.000000000 Z
11
+ date: 2013-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 4.0.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 4.0.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bcrypt-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: actionpack
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 4.0.0.rc1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 4.0.0.rc1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activerecord
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 4.0.0.rc1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 4.0.0.rc1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: database_cleaner
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: pg
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ! '>='
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ! '>='
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: pry
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ! '>='
129
+ - - '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ! '>='
136
+ - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  description: Authem provides a simple solution for email-based authentication.
@@ -164,17 +164,17 @@ require_paths:
164
164
  - lib
165
165
  required_ruby_version: !ruby/object:Gem::Requirement
166
166
  requirements:
167
- - - ! '>='
167
+ - - '>='
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  requirements:
172
- - - ! '>='
172
+ - - '>='
173
173
  - !ruby/object:Gem::Version
174
174
  version: '0'
175
175
  requirements: []
176
176
  rubyforge_project:
177
- rubygems_version: 2.0.0
177
+ rubygems_version: 2.0.3
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: Authem authenticates them by email