authstrategies 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTQ3YmIyY2QwNDJhNWJiMjk3YWE5MTdjZGFjNGY3NDA0ZDY4ZTk1Yw==
4
+ MjAxN2FiZmE5MmYwZmQ5MTc3YWYyY2ZiYWE4OGY1YjAzN2JlNTQzYw==
5
5
  data.tar.gz: !binary |-
6
- OGJlYjQ4NjM3YWJkZjI5MGExNWM3YjgyZWU0ZTYxNGI5M2U1YmQxYw==
6
+ NWNiNDJkNjUwMTdmYWZjNGI4MTEwODFlMTMyMzhjMGU4MDAxY2EyNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWU5NmFhYmM4YzhjZDFlNmQ4OTFjZWI2ZDY4MzE3MTlkNzE4NDEzZDhjOTI5
10
- Y2Y2NDdiYmQxYzA1NmFjY2MxZGZhNWE3MzU0MjU0MzdkNjZkNDBmNDYyM2M5
11
- YmY4YWMxMDQ2ZTJjODUyN2QwNGY2OGVjNzI0N2Y5Njc4Nzc5ZTk=
9
+ MGZiNTU3MDAzN2FkNTc3MzRlM2I3NTAxYjE3OTA0NmRlMDU0ZmZkNjcxNmU3
10
+ MGIwNmMyNTg5YjgyNDFhOWFhMjc4OWJiOTQ3ZmRlYTY0M2ZkMjg3YmEwZDRm
11
+ NWVhZGE1NTBlMjI2ZWEyMjU3MTYzYTRlNGVlNjVjYmFkM2ZmZmE=
12
12
  data.tar.gz: !binary |-
13
- MDVkYWI0NTNhOWRhOWJmYjIwZDdkYWQ0YTI1MGY1YjA1N2VlNTFjZDE2NDA1
14
- OTY1N2IxYzZkZjk4ZDE3OTU5OWM4MmNjZGIxOTY5Nzg2MjRmODk3Y2ExY2Q4
15
- YTUwZmQ4YTEyMDIzMmFjNWMxNDBmNjE5OTQzMTA3N2NkZmFiZTU=
13
+ ZTlhM2E4MzdhNTYyMjk5MDdiZjM1ZTU4OTY1OThhY2JmZDA5OGZhYzhmZTEw
14
+ OTBhZDc3MzRmZjI1OGZhYjQ3YzM0YmU3YTAxZDU5MGYwNDJkOWEzODg2Y2Zh
15
+ Y2QyY2VlOTRlODBiYmE2Y2M4NDFiZGNiZGY1NmU2MWExZWQyYzc=
data/README.md CHANGED
@@ -19,137 +19,141 @@ Or install it yourself as:
19
19
  ## Usage
20
20
 
21
21
  Authstrategies uses sinatra-activerecord as orm. There is currently no rake task to generate a migration for the user model, but you can use the following: (courtesy of device)
22
+ ```ruby
23
+ def up
24
+ create_table :users do |t|
25
+ t.string :email, :null => false, :defautl => ""
26
+ t.string :encrypted_password, :null => false, :default => ""
22
27
 
23
- def up
24
- create_table :users do |t|
25
- t.string :email, :null => false, :defautl => ""
26
- t.string :encrypted_password, :null => false, :default => ""
28
+ t.string :remember_token
29
+ t.boolean :remember_me
27
30
 
28
- t.string :remember_token
29
- t.boolean :remember_me
30
-
31
- t.timestamps
32
- end
33
-
34
- add_index :users, :email, :unique => true
35
- add_index :users, :remember_token, :unique => true
36
- end
31
+ t.timestamps
32
+ end
37
33
 
34
+ add_index :users, :email, :unique => true
35
+ add_index :users, :remember_token, :unique => true
36
+ end
37
+ ```
38
38
 
39
39
  After that your application should be configurad similarly to the following:
40
-
40
+ ```ruby
41
41
  require 'authstrategies'
42
42
 
43
- class YourApp < Sinatra::Application
44
- use Rack::Session::Cookie, {
45
- :secret => 'such secret many secure wow',
46
- :expire_after => 3600
47
- }
48
- use Rack::Flash
49
- use Authstrategies::Middleware
50
- end
51
-
43
+ class YourApp < Sinatra::Application
44
+ use Rack::Session::Cookie, {
45
+ :secret => 'such secret many secure wow',
46
+ :expire_after => 3600
47
+ }
48
+ use Rack::Flash
49
+ use Authstrategies::Middleware
50
+ end
51
+ ```
52
52
  The expire after for Rack::Session::Cookie is optional, but I set it, because
53
53
  some modern browsers will not delete session cookies after the user closes his browser like you would normally expect. This may pose a security thread if your users log in from a public computer.
54
54
 
55
55
  If you want to use the helpers provided with authstrategies put:
56
56
 
57
- require 'authstrategies/helpers'
58
-
59
- helpers Authstrategies::Helpers
57
+ require 'authstrategies/helpers'
58
+ helpers Authstrategies::Helpers
60
59
 
61
60
  in your code.
62
61
 
63
- To authenticate a user call authenticate!
64
- To check if a user is authenticated call authenticated?
65
- To get the currently logged in user call current_user
66
- To logout the user class logout.
62
+ ## Helpers
63
+
64
+ authenticate!
65
+ To authenticate a user call
66
+
67
+ authenticated?
68
+ To check if a user is authenticated
69
+
70
+ current_user
71
+ To get the currently logged in user
72
+
73
+ logout
74
+ To logout the user
75
+
76
+ login_path
77
+ returns the login path as a string
67
78
 
68
- login_path returns the login path as a string
69
- logout_path returns the logout path as a string
70
- signup_path returns the signup path as a string
79
+ logout_path
80
+ returns the logout path as a string
81
+
82
+ signup_path
83
+ returns the signup path as a string
71
84
 
72
85
  ## Callbacks
73
86
 
74
87
  after_set_user
75
88
  This is called every time the user is set. The user is set:
76
- => on each request when they are accessed for the first time via env['warden'].user
77
- => when the user is initially authenticated
78
- => when the user is set via the set_user method
89
+ on each request when they are accessed for the first time via env['warden'].user
90
+ when the user is initially authenticated
91
+ when the user is set via the set_user method
79
92
  Courtesy of Warden, for more information check the warden callbacks wiki
80
93
 
81
94
  after_authentication
82
95
 
83
96
  Executed every time the user is authenticated
84
97
  (first time in each session).
85
- Courtesy of Warden, for more information check the warden callbacks wiki
98
+ Courtesy of Warden, for more information check the warden callbacks wiki.
86
99
 
87
100
  before_login_failure
88
101
 
89
102
  This callback is run right before the failure application is called.
90
- Courtesy of Warden, for more information
91
- check the warden callbacks wiki
103
+ Courtesy of Warden, for more information check the warden callbacks wiki.
92
104
 
93
105
  after_login_failure
94
106
 
95
- This is called in the failure application
96
- Useful for redirecting the user after he logs in
107
+ This is called in the failure application.
97
108
  2 params are passed to this callback
98
- =>request - the request data
99
- =>response - the response data
109
+ request - the request data
110
+ response - the response data
100
111
 
101
112
  before_logout
102
113
 
103
114
  This callback is run before each user is logged out.
104
- Courtesy of Warden, for more information
105
- check the warden callbacks wiki
115
+ Courtesy of Warden, for more information check the warden callbacks wiki.
106
116
 
107
117
  after_logout
108
118
 
109
119
  This is called after the user is logged out.
110
- Useful for redirecting the user after logging out
111
120
  2 parameters are passed to this callback
112
- =>request - the request data
113
- =>response - the response data
114
-
115
- after_logout_path
116
-
117
- This defines a path to redirect the user to
118
- after he logs out and a flash message to print
119
- path default is root path
120
- message default is 'Logged out successfully!'
121
+ request - the request data
122
+ response - the response data
121
123
 
122
124
  after_login
123
125
 
124
126
  This is called each time after the user logs in
125
127
  3 parameters are passed to this callback
126
- =>current_user - the user that hase just been set
127
- =>request - the request data
128
- =>response - the response data
129
-
130
- after_login_path
131
-
132
- This defines a path to redirect the user to
133
- after he logs in and a flash message to print
134
- path default is root path
135
- message default is 'Logged in successfully!'
128
+ current_user - the user that hase just been set
129
+ request - the request data
130
+ response - the response data
136
131
 
137
132
  after_signup
138
133
 
139
- This is called after the user is saved into
140
- the database
134
+ This is called after the user is saved into the database.
141
135
  3 parameters are passed to this callback
142
- =>user - the user that just signed up
143
- =>request - the request data
144
- =>response - the response data
136
+ user - the user that just signed up
137
+ request - the request data
138
+ response - the response data
145
139
  Also since the user is set to session via env['warden'].set_user
146
140
  after_set_user is also called after the user signs up
147
141
 
148
- after_signup_path
149
- This defines a path to redirect the user to
150
- after he signs up and a flash message to print
151
- path default is root path
152
- message default is 'Successfully signed up!
142
+ ## Configuration
143
+
144
+ You can cofigure authstrategies throug:
145
+ ```ruby
146
+ Authstrategies::Manager.config do |config|
147
+ config[:after_login_path] = '/' #sets a path to redirect the user after logging in
148
+ config[:after_login_msg] = 'Successfully logged in!' #sets a message to give to the user after he logs in
149
+
150
+ config[:after_logout_path] = '/' #sets a path to redirect the user after logging out
151
+ config[:after_logout_msg] = 'Successfully logged out!' #sets a message to give to the user after he logs out
152
+
153
+ config[:after_signup_path] = '/' #sets a path to redirect the user after he signs up
154
+ config[:after_signup_msg] = 'Successfully signed up!' #sets a message to give to the user after he signs up
155
+ end
156
+ ```
153
157
  ## Contributing
154
158
 
155
159
  1. Fork it
@@ -26,6 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.add_runtime_dependency "protected_attributes"
27
27
  spec.add_runtime_dependency "warden"
28
28
  spec.add_runtime_dependency "bcrypt-ruby"
29
- spec.add_runtime_dependency "rack-flash3", '1.0.5'
29
+ spec.add_runtime_dependency "sinatra-flash"
30
+ spec.add_runtime_dependency "i18n"
31
+ spec.add_runtime_dependency "rack-contrib"
30
32
 
31
33
  end
@@ -1,9 +1,12 @@
1
1
  require "authstrategies/version"
2
2
  require "warden"
3
- require "rack-flash"
3
+ require "sinatra/flash"
4
+ require "rack/contrib"
4
5
  require "sinatra/base"
5
6
  require "active_record"
6
7
  require "bcrypt"
8
+ require "i18n"
9
+ require "i18n/backend/fallbacks"
7
10
  require "authstrategies/session_serializer.rb"
8
11
  require "authstrategies/helpers.rb"
9
12
  require "authstrategies/password.rb"
@@ -16,14 +19,11 @@ module Authstrategies
16
19
  @@callbacks = {}
17
20
 
18
21
  @@config = {
19
- :after_login_path => '/',
20
- :after_login_msg => 'Successfully logged in!',
22
+ :default_locales => :en,
21
23
 
24
+ :after_login_path => '/',
22
25
  :after_logout_path => '/',
23
- :after_logout_msg => 'Successfully logged out!',
24
-
25
26
  :after_signup_path => '/',
26
- :after_signup_msg => 'Successfully signed up!',
27
27
  }
28
28
 
29
29
  def self.registered? hook
@@ -1,7 +1,7 @@
1
1
  module Authstrategies
2
2
  module Helpers
3
- def authenticate! strategy= :password
4
- env['warden'].authenticate! strategy
3
+ def authenticate!
4
+ env['warden'].authenticate!
5
5
  end
6
6
 
7
7
  def authenticated?
@@ -0,0 +1,13 @@
1
+ bg:
2
+ login_msg: Успешен вход в системата!
3
+ logout_msg: Вие излязохте от системата!
4
+ signup_msg: Успешна регистрация!
5
+ email: E-mail
6
+ password: Парола
7
+ remember_me: Запомни ме!
8
+ submit: Изпращане
9
+ not_registered: Нямаш акаунт?
10
+ signup: Регистрация
11
+ confirm: Потвърждаване
12
+ register: Регистрация
13
+ login: Вход
@@ -0,0 +1,13 @@
1
+ en:
2
+ login_msg: Successfully logged in!
3
+ logout_msg: Successgully logged out!
4
+ signup_msg: Successfully signed up!
5
+ email: E-mail
6
+ password: Password
7
+ remember_me: Remember me!
8
+ submit: Submit
9
+ not_registered: Don't have an account?
10
+ signup: Signup
11
+ confirm: Confirm
12
+ register: Register
13
+ login: Log in
@@ -2,9 +2,18 @@ module Authstrategies
2
2
  class Middleware < Sinatra::Base
3
3
  register Base
4
4
  register RememberMe
5
+ register Sinatra::Flash
6
+
7
+ use Rack::Locale
5
8
 
6
9
  include Manager
7
10
 
11
+ I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
12
+ I18n.load_path = Dir[File.join(File.dirname(__FILE__)+'/locales', '*.yml')]
13
+ I18n.backend.load_translations
14
+ I18n.enforce_available_locales = true
15
+ I18n.default_locale = Manager.config[:default_locales]
16
+
8
17
  get '/login/?' do
9
18
  redirect '/' if authenticated?
10
19
  erb :login
@@ -22,7 +31,7 @@ module Authstrategies
22
31
  )
23
32
  end
24
33
  Manager.call :after_login, [current_user, request, response]
25
- flash[:notice] = Manager.config[:after_login_msg]
34
+ flash[:notice] = I18n.t 'login_msg'
26
35
  redirect Manager.config[:after_login_path]
27
36
  end
28
37
  end
@@ -39,7 +48,7 @@ module Authstrategies
39
48
  user.save
40
49
  env['warden'].set_user(user)
41
50
  Manager.call :after_signup, [user, request, response]
42
- flash[:notice] = Manager.config[:after_signup_msg]
51
+ flash[:notice] = I18n.t 'signup_msg'
43
52
  redirect Manager.config[:after_signup_path]
44
53
  else
45
54
  flash[:error] = user.errors.messages
@@ -53,7 +62,7 @@ module Authstrategies
53
62
  response.delete_cookie("authstrategies")
54
63
  logout
55
64
  Manager.call :after_logout, [request, response]
56
- flash[:notice] = Manager.config[:after_logout_msg]
65
+ flash[:notice] = I18n.t 'logout_msg'
57
66
  redirect Manager.config[:after_logout_path]
58
67
  end
59
68
  redirect '/'
@@ -1,3 +1,3 @@
1
1
  module Authstrategies
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,8 +1,9 @@
1
1
  <%= flash[:error] %>
2
2
  <%= flash[:notice] %>
3
3
  <form action="login" method="post">
4
- <p>Username:<input type="text" name="email" /></p>
5
- <p>Password:<input type="password" name="password" /></p>
6
- <p>Remember Me: <input type="checkbox" name="remember_me" /></p>
7
- <p><input type="submit" name="Submit" /></p>
4
+ <p><%= I18n.t 'email' %>:<input type="email" name="email" required/></p>
5
+ <p><%= I18n.t 'password' %>:<input type="password" name="password" required/></p>
6
+ <p><%= I18n.t 'remember_me' %> <input type="checkbox" name="remember_me" /></p>
7
+ <p><input type="submit" value=<%= I18n.t 'submit' %> /></p>
8
+ <%= I18n.t 'not_registered' %><a href=<%= signup_path%>><%= I18n.t 'signup' %></a>
8
9
  </form>
@@ -1,8 +1,22 @@
1
1
  <%= flash[:error] %>
2
2
  <%= flash[:notice] %>
3
3
  <form action="signup" method="post">
4
- <p>E-mail:<input type="text" name="email" /></p>
5
- <p>Password:<input type="password" name="password" /></p>
6
- <p>Confirm password:<input type="password" name="password_confirmation" /></p>
7
- <input type="submit" value="Register!" />
4
+ <table border="0">
5
+ <tr>
6
+ <td><%= I18n.t 'email' %>:</td>
7
+ <td><input type="email" name="email" required/></td>
8
+ </tr>
9
+ <tr>
10
+ <td><%= I18n.t 'password' %>:</td>
11
+ <td><input type="password" name="password" required/></td>
12
+ </tr>
13
+ <tr>
14
+ <td><%= I18n.t 'confirm' %>:</td>
15
+ <td><input type="password" name="password_confirmation" /></td>
16
+ </tr>
17
+ <tr>
18
+ <td><input type="submit" value=<%= I18n.t 'register' %> /></td>
19
+ </tr>
20
+ </table>
8
21
  </form>
22
+ <%= I18n.t 'already_registered' %> <a href=<%= login_path %>><%= I18n.t 'login' %></a>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authstrategies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dobromir Ivanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-06 00:00:00.000000000 Z
11
+ date: 2014-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -109,19 +109,47 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rack-flash3
112
+ name: sinatra-flash
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '='
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: i18n
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
116
137
  - !ruby/object:Gem::Version
117
- version: 1.0.5
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rack-contrib
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
118
146
  type: :runtime
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
- - - '='
150
+ - - ! '>='
123
151
  - !ruby/object:Gem::Version
124
- version: 1.0.5
152
+ version: '0'
125
153
  description: AuthStrategies is a Warden implementation for sinatra.
126
154
  email:
127
155
  - dobromir0ivanov@gmail.com
@@ -137,6 +165,8 @@ files:
137
165
  - authstrategies.gemspec
138
166
  - lib/authstrategies.rb
139
167
  - lib/authstrategies/helpers.rb
168
+ - lib/authstrategies/locales/bg.yml
169
+ - lib/authstrategies/locales/en.yml
140
170
  - lib/authstrategies/middleware.rb
141
171
  - lib/authstrategies/models/user.rb
142
172
  - lib/authstrategies/password.rb