innetra-easy_authentication 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/Rakefile +14 -0
  2. data/easy_authentication.gemspec +32 -0
  3. data/generators/easy_authentication/easy_authentication_generator.rb +163 -0
  4. data/generators/easy_authentication/templates/controllers/roles_controller.rb +79 -0
  5. data/generators/easy_authentication/templates/controllers/sessions_controller.rb +44 -0
  6. data/generators/easy_authentication/templates/controllers/user_password_controller.rb +82 -0
  7. data/generators/easy_authentication/templates/controllers/user_roles_controller.rb +34 -0
  8. data/generators/easy_authentication/templates/controllers/users_controller.rb +72 -0
  9. data/generators/easy_authentication/templates/helpers/form_helper.rb +5 -0
  10. data/generators/easy_authentication/templates/helpers/shadowbox_helper.rb +23 -0
  11. data/generators/easy_authentication/templates/layouts/easy_authentication.erb +40 -0
  12. data/generators/easy_authentication/templates/layouts/easy_authentication_login.erb +22 -0
  13. data/generators/easy_authentication/templates/locales/en.easy_authentication.yml +84 -0
  14. data/generators/easy_authentication/templates/locales/es-MX.easy_authentication.yml +100 -0
  15. data/generators/easy_authentication/templates/migrations/easy_authentication.rb +54 -0
  16. data/generators/easy_authentication/templates/models/right.rb +2 -0
  17. data/generators/easy_authentication/templates/models/role.rb +12 -0
  18. data/generators/easy_authentication/templates/models/user.rb +3 -0
  19. data/generators/easy_authentication/templates/models/user_mailer.rb +0 -0
  20. data/generators/easy_authentication/templates/site_keys.rb +2 -0
  21. data/generators/easy_authentication/templates/stylesheets/default.css +249 -0
  22. data/generators/easy_authentication/templates/stylesheets/login.css +111 -0
  23. data/generators/easy_authentication/templates/stylesheets/roles.css +26 -0
  24. data/generators/easy_authentication/templates/stylesheets/users.css +21 -0
  25. data/generators/easy_authentication/templates/views/roles/_form.html.erb +37 -0
  26. data/generators/easy_authentication/templates/views/roles/edit.html.erb +19 -0
  27. data/generators/easy_authentication/templates/views/roles/index.html.erb +21 -0
  28. data/generators/easy_authentication/templates/views/roles/new.html.erb +19 -0
  29. data/generators/easy_authentication/templates/views/roles/show.html.erb +30 -0
  30. data/generators/easy_authentication/templates/views/sessions/new.html.erb +25 -0
  31. data/generators/easy_authentication/templates/views/user_password/edit.html.erb +35 -0
  32. data/generators/easy_authentication/templates/views/user_password/forgot_password.html.erb +16 -0
  33. data/generators/easy_authentication/templates/views/user_password/reset_password.html.erb +22 -0
  34. data/generators/easy_authentication/templates/views/user_roles/edit.html.erb +27 -0
  35. data/generators/easy_authentication/templates/views/users/_form.html.erb +47 -0
  36. data/generators/easy_authentication/templates/views/users/_user.html.erb +4 -0
  37. data/generators/easy_authentication/templates/views/users/edit.html.erb +14 -0
  38. data/generators/easy_authentication/templates/views/users/index.html.erb +21 -0
  39. data/generators/easy_authentication/templates/views/users/new.html.erb +14 -0
  40. data/generators/easy_authentication/templates/views/users/show.html.erb +53 -0
  41. data/init.rb +5 -0
  42. data/lib/controller_methods.rb +14 -0
  43. data/lib/cookie_authentication.rb +63 -0
  44. data/lib/helper_methods.rb +198 -0
  45. data/lib/password_authentication.rb +64 -0
  46. data/lib/user_methods.rb +109 -0
  47. data/tasks/rights.rake +35 -0
  48. data/tasks/sysadmin.rake +27 -0
  49. data/test/easy_authentication_test.rb +8 -0
  50. data/test/test_helper.rb +3 -0
  51. metadata +113 -0
@@ -0,0 +1,72 @@
1
+ class UsersController < ApplicationController
2
+
3
+ <% unless options[:skip_layout] -%>
4
+ layout "easy_authentication"
5
+ <% end -%>
6
+
7
+ def index
8
+ @users = User.all(:order => :login)
9
+
10
+ respond_to do |format|
11
+ format.html # index.html.erb
12
+ format.xml { render :xml => @users }
13
+ end
14
+ end
15
+
16
+ def show
17
+ @user = User.find_by_login(params[:id])
18
+
19
+ respond_to do |format|
20
+ format.html # show.html.erb
21
+ format.xml { render :xml => @user }
22
+ end
23
+ end
24
+
25
+ def new
26
+ @user = User.new
27
+
28
+ respond_to do |format|
29
+ format.html # new.html.erb
30
+ format.xml { render :xml => @user }
31
+ end
32
+ end
33
+
34
+ def create
35
+ @user = User.new(params[:user])
36
+
37
+ respond_to do |format|
38
+ if @user.save
39
+ flash[:notice] = t('users.flash.create', :login => @user.login)
40
+ format.html { redirect_to(@user) }
41
+ format.xml { render :xml => @user, :status => :created, :location => @user }
42
+ else
43
+ format.html { render :action => "new" }
44
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
45
+ end
46
+ end
47
+ end
48
+
49
+ def edit
50
+ @user = User.find_by_login(params[:id])
51
+ end
52
+
53
+ def update
54
+ @user = User.find_by_login(params[:id])
55
+
56
+ respond_to do |format|
57
+ if @user.update_attributes(params[:user])
58
+ flash[:notice] = t('users.flash.update', :login => @user.login)
59
+ format.html { redirect_to(@user) }
60
+ format.xml { head :ok }
61
+ else
62
+ format.html { render :action => "edit" }
63
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
64
+ end
65
+ end
66
+ end
67
+
68
+ def password
69
+ @user = User.find_by_login(params[:id])
70
+ end
71
+
72
+ end
@@ -0,0 +1,5 @@
1
+ module FormHelper
2
+ def required_field
3
+ "<span class=\"required\">*</span>"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ module ShadowboxHelper
2
+ def shadowbox(id, options = {}, &block)
3
+ class_name = "container "
4
+ class_name << options[:class] if options.has_key?(:class)
5
+ concat content_tag(:div,
6
+ content_tag(:div,
7
+ content_tag(:div,
8
+ content_tag(:div,
9
+ content_tag(:div,
10
+ capture(&block),
11
+ :class => class_name
12
+ ),
13
+ :class => "shadow3"
14
+ ),
15
+ :class => "shadow2"
16
+ ),
17
+ :class => "shadow1"
18
+ ),
19
+ :id => id.downcase.strip.gsub(' ', '_'),
20
+ :class => "shadow"
21
+ )
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml">
4
+ <head>
5
+ <title>Codebase [<%%= yield :title %>]</title>
6
+ <%%= stylesheet_link_tag 'easy_authentication/default', :media => :all %>
7
+ <%%= javascript_include_tag :all, :cache => true %>
8
+ <%%= yield :header %>
9
+ </head>
10
+ <body>
11
+ <table id="layout">
12
+ <tr>
13
+ <td id="head"colspan="2">
14
+ <%%= render :partial => current_user %>
15
+ <%%= yield :head %>
16
+ </td>
17
+ </tr>
18
+ <tr id="content">
19
+ <td id="page">
20
+ <%% if flash.has_key? :notice -%>
21
+ <div class="flash">
22
+ <%%= flash[:notice] %>
23
+ </div>
24
+ <%% end -%>
25
+ <%% if flash.has_key? :error -%>
26
+ <div class="flash error">
27
+ <%%= flash[:error] %>
28
+ </div>
29
+ <%% end -%>
30
+ <%% shadowbox "page_content" do %>
31
+ <%%= yield %>
32
+ <%% end %>
33
+ </td>
34
+ <td id="sidebar">
35
+ <%%= yield :sidebar %>
36
+ </td>
37
+ </tr>
38
+ </table>
39
+ </body>
40
+ </html>
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml">
4
+ <head>
5
+ <title>Codebase [<%%= yield :title %>]</title>
6
+ <%%= stylesheet_link_tag 'easy_authentication/default', :media => :all %>
7
+ <%%= yield :header %>
8
+ </head>
9
+ <body>
10
+ <%% if flash.has_key? :notice -%>
11
+ <div class="flash">
12
+ <%%= flash[:notice] %>
13
+ </div>
14
+ <%% end -%>
15
+ <%% if flash.has_key? :error -%>
16
+ <div class="flash error">
17
+ <%%= flash[:error] %>
18
+ </div>
19
+ <%% end -%>
20
+ <%%= yield %>
21
+ </body>
22
+ </html>
@@ -0,0 +1,84 @@
1
+ en:
2
+
3
+ easy_authentication:
4
+ access_denied: "Access denied"
5
+
6
+ # Views by controller
7
+ forms:
8
+ save: "Save"
9
+ cancel: "Cancel"
10
+ update: "Update"
11
+
12
+ roles:
13
+ flash:
14
+ create: "User role created."
15
+ update: "User role updated."
16
+ assigned_rights: "Assigned Rights"
17
+ edit:
18
+ title: "Edit User Role \"{{name}}\""
19
+ index:
20
+ title: "User Roles"
21
+ new_role_link: "New user role"
22
+ new:
23
+ title: "New User Role"
24
+ show:
25
+ title: "User Role \"{{name}}\""
26
+ edit_link: "Edit"
27
+ back_link: "Back"
28
+ sessions:
29
+ flash:
30
+ login: "Welcome {{full_name}}."
31
+ logout: "Your session has been closed."
32
+ error: "User or password incorrect."
33
+ new:
34
+ login: "User or Email"
35
+ password: "Password"
36
+ submit_button: "Login"
37
+ remember_me: "Remember me"
38
+ recover_password: "Forgot your password?"
39
+ users:
40
+ actions:
41
+ change_password_link: "Change Password"
42
+ logout_link: "Logout"
43
+ flash:
44
+ create: "User created."
45
+ update: "User updated."
46
+ index:
47
+ title: "Users"
48
+ new_link: "Add new user"
49
+ edit:
50
+ title: "Change Password \"{{login}}\""
51
+ cancel: "Cancel"
52
+ new:
53
+ cancel: "Cancel"
54
+ title: "New User"
55
+ login_comment: "(Eg: username)"
56
+ password_comment: "6 caracteres mínimum"
57
+ show:
58
+ edit: "Change Password"
59
+ login: "User"
60
+ back: "Back"
61
+ password_section:
62
+ edit_link: "Change password"
63
+ user_details:
64
+ title: "Contact Data"
65
+ edit_link: "Edit"
66
+ login: "Login"
67
+ email: "Email"
68
+ roles_section:
69
+ title: "Roles for this user"
70
+ edit_link: "Edit"
71
+ user_password:
72
+ edit:
73
+ title: "Change Password for \"{{full_name}}\" ({{login}})"
74
+ new_password: "New Password"
75
+ forgot_password:
76
+ login: "Username or Email"
77
+ submit_button: "Reset Password"
78
+ reset_password:
79
+ submit_button: "Change Password"
80
+ user_roles:
81
+ flash:
82
+ update: "User roles updated."
83
+ edit:
84
+ title: "Assign roles to \"{{login}}\""
@@ -0,0 +1,100 @@
1
+ "es-MX":
2
+
3
+ easy_authentication:
4
+ access_denied: "Accesso denegado"
5
+
6
+ # Models
7
+ activerecord:
8
+ models:
9
+ user: "Usuario"
10
+ attributes:
11
+ user:
12
+ login: "Nombre usuario"
13
+ password: "Contraseña"
14
+ password_confirmation: "Confirmación contraseña"
15
+ current_password: "Contraseña Actual"
16
+ email: "Correo Electrónico"
17
+ enabled: "Habilitado"
18
+ first_name: "Nombre(s)"
19
+ last_name: "Apellidos"
20
+
21
+ # General forms translations
22
+ forms:
23
+ save: "Guardar"
24
+ cancel: "Cancelar"
25
+ update: "Actualizar"
26
+
27
+ # Views by controller
28
+ roles:
29
+ flash:
30
+ create: "Rol de usuario creado"
31
+ update: "Rol de usuario actualizado"
32
+ assigned_rights: "Roles Asignados"
33
+ edit:
34
+ title: "Editar Rol de Usuario \"{{name}}\""
35
+ index:
36
+ title: "Roles de Usuario"
37
+ new_role_link: "Crear nuevo rol de usuario"
38
+ new:
39
+ title: "Nuevo Rol de Usuario"
40
+ show:
41
+ title: "Rol de Usuario \"{{name}}\""
42
+ edit_link: "Editar"
43
+ back_link: "Regresar"
44
+ sessions:
45
+ flash:
46
+ login: "Bienvenido {{full_name}}"
47
+ logout: "Su sessión ha sido cerrada"
48
+ error: "Usuario o contraseña incorrectos"
49
+ new:
50
+ login: "Nombre Usuario o Correo Electrónico"
51
+ password: "Contraseña"
52
+ submit_button: "Ingresar"
53
+ remember_me: "Recordar contraseña"
54
+ recover_password: "¿Olvidó su contraseña?"
55
+ users:
56
+ actions:
57
+ change_password_link: "Cambiar Contraseña"
58
+ logout_link: "Cerrar Sesión"
59
+ flash:
60
+ create: "Usuario creado."
61
+ update: "Usuario actualizado."
62
+ index:
63
+ title: "Usuarios Registrados"
64
+ new_link: "Registrar nuevo usuario"
65
+ edit:
66
+ title: "Editar \"{{full_name}}\" ({{login}})"
67
+ cancel: "Cancelar"
68
+ new:
69
+ cancel: "Cancelar"
70
+ title: "Nuevo Usuario"
71
+ login_comment: "(Ejemplo: nombreusuario)"
72
+ password_comment: "Mínimo 6 caracteres"
73
+ show:
74
+ edit: "Cambiar Contraseña"
75
+ login: "Usuario"
76
+ back: "Regresar"
77
+ password_section:
78
+ edit_link: "Cambiar contraseña"
79
+ user_details:
80
+ title: "Datos del usuario"
81
+ edit_link: "Editar"
82
+ login: "Usuario"
83
+ email: "Email"
84
+ roles_section:
85
+ title: "Roles del usuario"
86
+ edit_link: "Editar"
87
+ user_password:
88
+ edit:
89
+ title: "Cambiar Contraseña \"{{full_name}}\" ({{login}})"
90
+ new_password: "Nueva Contraseña"
91
+ forgot_password:
92
+ login: "Usuario o Correo Electrónico"
93
+ submit_button: "Recuperar Contraseña"
94
+ reset_password:
95
+ submit_button: "Cambiar Contraseña"
96
+ user_roles:
97
+ flash:
98
+ update: "Roles del usuario actualizados"
99
+ edit:
100
+ title: "Asignar roles a \"{{login}}\""
@@ -0,0 +1,54 @@
1
+ class CreateEasyAuthentication < ActiveRecord::Migration
2
+
3
+ def self.up
4
+
5
+ create_table :rights do |t|
6
+ t.string :controller_name, :nil => false
7
+ t.string :action_name, :nil => false
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ create_table :rights_roles, :id => false do |t|
13
+ t.integer :right_id, :nil => false
14
+ t.integer :role_id, :nil => false
15
+ end
16
+
17
+ create_table :roles do |t|
18
+ t.string :name, :nil => false
19
+ t.text :description
20
+
21
+ t.timestamps
22
+ end
23
+
24
+ create_table :roles_users, :id => false do |t|
25
+ t.integer :role_id, :nil => false
26
+ t.integer :user_id, :nil => false
27
+ end
28
+
29
+ create_table :users do |t|
30
+ t.string :first_name
31
+ t.string :last_name
32
+ t.string :email
33
+ t.string :login
34
+ t.string :password_hash, :null => false
35
+ t.string :password_salt, :null => false
36
+ t.string :remember_token, :limit => 40
37
+ t.datetime :remember_token_expires_at
38
+ t.string :password_reset_token, :limit => 40
39
+ t.boolean :enabled, :default => false
40
+
41
+ t.timestamps
42
+ end
43
+
44
+ end
45
+
46
+ def self.down
47
+ drop_table :rights
48
+ drop_table :rights_roles
49
+ drop_table :roles
50
+ drop_table :roles_users
51
+ drop_table :users
52
+ end
53
+
54
+ end
@@ -0,0 +1,2 @@
1
+ class Right < ActiveRecord::Base
2
+ end
@@ -0,0 +1,12 @@
1
+ class Role < ActiveRecord::Base
2
+
3
+ has_and_belongs_to_many :rights
4
+
5
+ validates_presence_of :name
6
+ validates_format_of :name, :with => /^[a-z_]+$/
7
+
8
+ def before_validation
9
+ self.name.downcase!
10
+ end
11
+
12
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ include EasyAuthentication::UserMethods
3
+ end
@@ -0,0 +1,2 @@
1
+ AUTH_SITE_KEY = '<%= auth_site_key %>'
2
+ AUTH_DIGEST_STRETCHES = <%= auth_digest_stretches %>
@@ -0,0 +1,249 @@
1
+ <% unless options[:skip_layout] -%>
2
+ body * {
3
+ color: #333;
4
+ font-family: helvetica, arial, clean, sans-serif;
5
+ font-size: 14px;
6
+ }
7
+
8
+ body {
9
+ background: #F9F9F9;
10
+ }
11
+
12
+ a {
13
+ color: #4183c4;
14
+ }
15
+
16
+ h1 a,
17
+ a.red {
18
+ color: #f00;
19
+ }
20
+
21
+ body, html {
22
+ margin: 0;
23
+ padding: 0;
24
+ }
25
+
26
+ table {
27
+ margin: 0;
28
+ }
29
+
30
+ table td {
31
+ margin: 0;
32
+ padding: 0;
33
+ vertical-align: top;
34
+ }
35
+
36
+ a.important {
37
+ font-weight: bold;
38
+ }
39
+
40
+ fieldset {
41
+ background-color: #eee;
42
+ border: none;
43
+ }
44
+
45
+ h1 {
46
+ background-color: #E8F0F3;
47
+ font-size: 19px;
48
+ margin: -5px;
49
+ margin-bottom: 10px;
50
+ padding: 10px;
51
+ }
52
+
53
+ h2 {
54
+ font-size: 17px;
55
+ border-bottom: #ccc dotted 1px;
56
+ }
57
+
58
+ h3 {
59
+ font-size: 15px;
60
+ }
61
+
62
+ h4 {
63
+ font-size: 13px;
64
+ }
65
+
66
+ hr {
67
+ border: none;
68
+ border-bottom: #ccc dotted 1px;
69
+ height: 0;
70
+ }
71
+
72
+ label {
73
+ font-weight: bold;
74
+ }
75
+
76
+ p {
77
+ margin-left: 10px;
78
+ margin-right: 10px;
79
+ }
80
+
81
+ table {
82
+ margin: 0 10px;
83
+ }
84
+
85
+ table td {
86
+ padding: 0;
87
+ }
88
+
89
+ ul {
90
+ list-style: none;
91
+ margin: 0;
92
+ margin-left: 10px;
93
+ padding: 0;
94
+ }
95
+
96
+ /* Shadow Effect */
97
+ .shadow {
98
+ margin-left: 3px;
99
+ margin-top: 3px;
100
+ }
101
+
102
+ .shadow .shadow1,
103
+ .shadow .shadow2,
104
+ .shadow .shadow3,
105
+ .sadow .container {
106
+ position: relative;
107
+ left: -1px;
108
+ top: -1px;
109
+ }
110
+
111
+ .shadow1 {
112
+ background-color: #c9c9c9;
113
+ }
114
+
115
+ .shadow2 {
116
+ background-color: #b0b0b0;
117
+ }
118
+
119
+ .shadow3 {
120
+ background-color: #a9a9a9;
121
+ }
122
+
123
+ /* Sidebar */
124
+ .sidebar_section {
125
+ font-size: 16px;
126
+ margin-bottom: 10px;
127
+ }
128
+
129
+ .sidebar_section .label {
130
+ line-height: 18px;
131
+ font-size: 11px;
132
+ min-width: 40px;
133
+ padding-right: 5px;
134
+ text-align: right;
135
+ }
136
+
137
+ .container.sidebar_section {
138
+ background-color: #E8F0F3;
139
+ }
140
+
141
+ .sidebar_section h1 {
142
+ border-bottom: 1px solid #ddd;
143
+ font-size: 16px;
144
+ margin: -5px;
145
+ margin-bottom: 5px;
146
+ padding: 3px;
147
+ }
148
+
149
+ .sidebar_section h1 .title_actions {
150
+ line-height: 21px;
151
+ }
152
+
153
+ /* Forms */
154
+ .comment {
155
+ color: #999;
156
+ font-size: 12px;
157
+ }
158
+
159
+ .required {
160
+ color: #f00;
161
+ font-weight: bold;
162
+ }
163
+
164
+ .title_actions {
165
+ font-weight: normal;
166
+ font-size: 12px;
167
+ float: right;
168
+ line-height: 25px;
169
+ }
170
+
171
+ .flash {
172
+ background-color: #FFFFE0;
173
+ border-color: #ffa82a;
174
+ color: #ff9d0d;
175
+ border: 3px solid;
176
+ font-weight: bold;
177
+ padding: 5px;
178
+ margin: 0 3px 10px 0;
179
+ }
180
+
181
+ .flash.error {
182
+ background-color: #FFFFE0;
183
+ border-color: #f00;
184
+ color: #f00;
185
+ }
186
+
187
+ /* Layout */
188
+
189
+ body, html {
190
+ margin: 0 15px;
191
+ min-width: 800px;
192
+ padding: 0;
193
+ }
194
+
195
+ #layout {
196
+ margin: 0;
197
+ width: 100%;
198
+ }
199
+
200
+ #layout tr {
201
+ clear: both;
202
+ }
203
+
204
+ #head {
205
+ height: 30px;
206
+ }
207
+
208
+ #navigation_bar {
209
+ height: 50px;
210
+ }
211
+
212
+ /* Content */
213
+ #content > td {
214
+ padding-top: 20px;
215
+ }
216
+
217
+ /* Page */
218
+ #page {
219
+ }
220
+
221
+ #page_content {
222
+ min-height: 100px;
223
+ }
224
+
225
+ .container {
226
+ background-color: #fff;
227
+ border: #ddd solid 3px;
228
+ padding: 5px;
229
+ }
230
+
231
+ /* Sidebar */
232
+ #sidebar {
233
+ padding-left: 10px;
234
+ width: 30%;
235
+ }
236
+
237
+ #logo .container {
238
+ text-align: center;
239
+ padding: 15px 10px 10px 10px;
240
+ }
241
+
242
+ <% end -%>
243
+ /* User Actions */
244
+ .user_actions {
245
+ float: right;
246
+ }
247
+
248
+ .user_actions a {
249
+ color: #f00;