ae_users 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/README +47 -0
  2. data/Rakefile +36 -0
  3. data/VERSION +1 -0
  4. data/ae_users.gemspec +117 -0
  5. data/app/controllers/account_controller.rb +167 -0
  6. data/app/controllers/auth_controller.rb +202 -0
  7. data/app/controllers/permission_controller.rb +172 -0
  8. data/app/helpers/account_helper.rb +2 -0
  9. data/app/helpers/auth_helper.rb +5 -0
  10. data/app/helpers/permission_helper.rb +2 -0
  11. data/app/models/account.rb +50 -0
  12. data/app/models/auth_notifier.rb +34 -0
  13. data/app/models/auth_ticket.rb +39 -0
  14. data/app/models/email_address.rb +17 -0
  15. data/app/models/login.rb +23 -0
  16. data/app/models/open_id_identity.rb +5 -0
  17. data/app/models/permission.rb +57 -0
  18. data/app/models/person.rb +156 -0
  19. data/app/models/role.rb +7 -0
  20. data/app/views/account/_personal_info.rhtml +35 -0
  21. data/app/views/account/_procon_profile.rhtml +3 -0
  22. data/app/views/account/_signup_form.html.erb +39 -0
  23. data/app/views/account/activate.rhtml +6 -0
  24. data/app/views/account/activation_error.rhtml +11 -0
  25. data/app/views/account/change_password.rhtml +3 -0
  26. data/app/views/account/edit_profile.rhtml +117 -0
  27. data/app/views/account/signup.rhtml +9 -0
  28. data/app/views/account/signup_noactivation.rhtml +7 -0
  29. data/app/views/account/signup_success.rhtml +8 -0
  30. data/app/views/auth/_auth_form.rhtml +54 -0
  31. data/app/views/auth/_forgot_form.html.erb +12 -0
  32. data/app/views/auth/_mini_auth_form.rhtml +17 -0
  33. data/app/views/auth/_openid_auth_form.html.erb +14 -0
  34. data/app/views/auth/_other_login_options.html.erb +24 -0
  35. data/app/views/auth/auth_form.js.erb +63 -0
  36. data/app/views/auth/forgot.rhtml +3 -0
  37. data/app/views/auth/forgot_form.rhtml +6 -0
  38. data/app/views/auth/index.css.erb +23 -0
  39. data/app/views/auth/login.rhtml +6 -0
  40. data/app/views/auth/needs_activation.rhtml +6 -0
  41. data/app/views/auth/needs_person.html.erb +32 -0
  42. data/app/views/auth/needs_profile.rhtml +14 -0
  43. data/app/views/auth/openid_login.html.erb +6 -0
  44. data/app/views/auth/resend_activation.rhtml +3 -0
  45. data/app/views/auth_notifier/account_activation.rhtml +13 -0
  46. data/app/views/auth_notifier/generated_password.rhtml +10 -0
  47. data/app/views/permission/_add_grantee.rhtml +47 -0
  48. data/app/views/permission/_role_member.rhtml +8 -0
  49. data/app/views/permission/_show.rhtml +81 -0
  50. data/app/views/permission/_userpicker.rhtml +0 -0
  51. data/app/views/permission/add_role_member.rhtml +3 -0
  52. data/app/views/permission/admin.rhtml +45 -0
  53. data/app/views/permission/edit.rhtml +9 -0
  54. data/app/views/permission/edit_role.rhtml +63 -0
  55. data/app/views/permission/grant.rhtml +10 -0
  56. data/db/migrate/002_create_accounts.rb +17 -0
  57. data/db/migrate/003_create_email_addresses.rb +17 -0
  58. data/db/migrate/004_create_people.rb +24 -0
  59. data/db/migrate/013_simplify_signup.rb +15 -0
  60. data/db/migrate/014_create_permissions.rb +16 -0
  61. data/db/migrate/015_create_roles.rb +18 -0
  62. data/db/migrate/016_refactor_people.rb +36 -0
  63. data/db/migrate/017_people_permissions.rb +9 -0
  64. data/generators/ae_users/USAGE +14 -0
  65. data/generators/ae_users/ae_users_generator.rb +12 -0
  66. data/generators/ae_users/templates/add.png +0 -0
  67. data/generators/ae_users/templates/admin.png +0 -0
  68. data/generators/ae_users/templates/group.png +0 -0
  69. data/generators/ae_users/templates/logout.png +0 -0
  70. data/generators/ae_users/templates/migration.rb +25 -0
  71. data/generators/ae_users/templates/openid.gif +0 -0
  72. data/generators/ae_users/templates/remove.png +0 -0
  73. data/generators/ae_users/templates/user.png +0 -0
  74. data/init.rb +1 -0
  75. data/install.rb +1 -0
  76. data/lib/ae_users.rb +781 -0
  77. data/rails/init.rb +20 -0
  78. data/tasks/ae_users_tasks.rake +4 -0
  79. data/test/ae_users_test.rb +8 -0
  80. data/uninstall.rb +1 -0
  81. metadata +134 -0
@@ -0,0 +1,3 @@
1
+ <h1>Thank you</h1>
2
+
3
+ <p>A new password has been generated and emailed to you.</p>
@@ -0,0 +1,6 @@
1
+ <h1>I forgot my password...</h1>
2
+
3
+ <p>No problem. Just type in your email address below and we'll <b>reset your password to a random one</b>, and send
4
+ it to you via email.</p>
5
+
6
+ <%= render :partial => 'forgot_form' %>
@@ -0,0 +1,23 @@
1
+ .auth_form {
2
+ margin-left: 0.5em;
3
+ width: 300px;
4
+ }
5
+ .auth_form input {
6
+ width: 100%;
7
+ }
8
+ .auth_form input[type=radio], .auth_form input[type=checkbox] {
9
+ width: auto;
10
+ }
11
+ .auth_form label.block {
12
+ margin-left: -0.5em;
13
+ font-weight: bold;
14
+ display: block;
15
+ }
16
+ #openid_url {
17
+ background-color: #fff;
18
+ background-image: url(<%= image_path "ae_users/openid.gif" %>);
19
+ background-position: left;
20
+ background-repeat: no-repeat;
21
+ padding-left: 18px;
22
+ width: 90%;
23
+ }
@@ -0,0 +1,6 @@
1
+ <div id="login">
2
+ <h2>Log in</h2>
3
+ <%= render :partial => 'auth_form' %>
4
+ </div>
5
+
6
+ <%= render :partial => 'other_login_options' %>
@@ -0,0 +1,6 @@
1
+ <h1>Account not activated</h1>
2
+
3
+ <p>That account hasn't been activated yet. If you want to try resending the activation email (because you
4
+ didn't receive it, or accidentally deleted it), click the button below.</p>
5
+
6
+ <p><%= button_to "Resend activation email", :action => 'resend_activation', :account => params[:account], :email => params[:email] %></p>
@@ -0,0 +1,32 @@
1
+ <h2>Welcome!</h2>
2
+
3
+ <p>This is the first time you've visited this site. We just need a few pieces of information
4
+ from you before we can log you in. We've attempted to get as much of it as possible from your
5
+ OpenID provider, but some of it may be missing and/or incorrect. Please check the following form
6
+ before pressing "Save changes" below.</p>
7
+
8
+ <%= auth_stylesheet %>
9
+
10
+ <% form_for("person", @person, :url => {:action => 'needs_person'},
11
+ :html => {:id => 'edit_profile_form', :style => "max-width: 800px;"}) do |f| %>
12
+ <%= hidden_field_tag "return_to", params[:return_to] %>
13
+ <%= render :partial => 'account/personal_info', :locals => {:f => f} %>
14
+
15
+ <p>
16
+ <label for="email" class="block">Email:</label>
17
+ <%= text_field_tag "email", params[:email] %>
18
+ </p>
19
+
20
+ <% if @app_profile -%>
21
+
22
+ <% form_for("app_profile", @app_profile) do |profile_form| %>
23
+ <%= render :partial => "account/#{@app_profile.class.name.tableize.singularize}",
24
+ :locals => {:f => profile_form}%>
25
+ <label></label>
26
+ <%= submit_tag %>
27
+ <% end %>
28
+ <% else -%>
29
+ <label></label>
30
+ <%= submit_tag %>
31
+ <% end -%>
32
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <h1>Update your profile</h1>
2
+
3
+ <p>Hello! It appears this is the first time you've logged into this site. Before you log in,
4
+ please take a moment to update your personal information below.</p>
5
+
6
+ <%= auth_stylesheet %>
7
+
8
+ <% form_for("app_profile", @app_profile, :html => {:class => 'auth_form'}) do |profile_form| %>
9
+ <%= hidden_field_tag "return_to", params[:return_to] %>
10
+ <%= hidden_field_tag "person", @person.id %>
11
+ <%= render :partial => "account/#{@app_profile.class.name.tableize.singularize}",
12
+ :locals => {:f => profile_form}%>
13
+ <%= submit_tag "Update your profile" %>
14
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <div id="openid_login">
2
+ <h2>Log in with OpenID</h2>
3
+ <%= render :partial => 'openid_auth_form' %>
4
+ </div>
5
+
6
+ <%= render :partial => "other_login_options" %>
@@ -0,0 +1,3 @@
1
+ <h1>Thank you</h1>
2
+
3
+ <p>A new activation key has been generated, and an email has been sent to your address.</p>
@@ -0,0 +1,13 @@
1
+ Dear <%=@name%>,
2
+
3
+ Thank you for signing up for an account on <%=@server_name%>! There's just one more
4
+ step you need to do before you can use it: we need you to verify that this email address
5
+ belongs to you.
6
+
7
+ To do that, simply go to:
8
+
9
+ <%= url_for :only_path => false, :controller => "account", :action => "activate", :account => @account.id, :activation_key => @account.activation_key, :escape => false%>
10
+
11
+ Thanks again for signing up!
12
+
13
+ - The Management
@@ -0,0 +1,10 @@
1
+ Dear <%=@name%>,
2
+
3
+ You have requested a password reset for your account on <%=@server_name%>. This has been
4
+ completed. Your new password is:
5
+
6
+ <%= @password %>
7
+
8
+ Thanks!
9
+
10
+ - The Management
@@ -0,0 +1,47 @@
1
+ <% if AeUsers.js_framework == "prototype" -%>
2
+ <ul style="list-style-type: none; padding-left: 0;">
3
+ <% for grantee in @grantees do -%>
4
+ <li granteeName="<%=h grantee.name %>">
5
+ <% if grantee.kind_of? Role -%>
6
+ <table>
7
+ <tr>
8
+ <td>
9
+ <%= image_tag "ae_users/group.png", :style => "float: left;" %>
10
+ <div class="grantee_id" style="display: none;"><%= grantee.class.name %>:<%= grantee.id %></div>
11
+ </td>
12
+ <td>
13
+ <b><%=h grantee.name %></b><br/>
14
+ <i><%=pluralize(grantee.people.count, "person")%></i>
15
+ </td>
16
+ </tr>
17
+ </table>
18
+ <% elsif grantee.kind_of? Person -%>
19
+ <table>
20
+ <tr>
21
+ <td>
22
+ <%= image_tag "ae_users/user.png", :style => "float: left;" %>
23
+ <div class="grantee_id" style="display: none;"><%= grantee.class.name %>:<%= grantee.id %></div>
24
+ </td>
25
+ <td>
26
+ <b><%=h grantee.name %></b><br/>
27
+ <i>
28
+ <% if grantee.primary_email_address.nil? -%>
29
+ No email address
30
+ <% else -%>
31
+ <%=h grantee.primary_email_address %>
32
+ <% end -%>
33
+ </td>
34
+ </tr>
35
+ </table>
36
+ <% end -%>
37
+ </li>
38
+ <% end -%>
39
+ </ul>
40
+
41
+ <% elsif AeUsers.js_framework == "jquery" -%>
42
+
43
+ <% for grantee in @grantees do -%>
44
+ <%=grantee.name %><% if grantee.kind_of? Role %> (<%= pluralize(grantee.people.count, "person") %>)<% end %>|<%=grantee.class.name %>:<%= grantee.id %>
45
+ <% end -%>
46
+
47
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ <li id="person_<%=person.id%>"><%= image_tag "ae_users/user.png" %>
2
+ <%=h person.name %>
3
+ <%= link_to_remote "Remove",
4
+ { :url => { :controller => "permission", :action => "remove_role_member", :id => person.id, :role => @role.id },
5
+ :success => "$('person_#{person.id}').remove();",
6
+ :confirm => "Are you sure you want to remove that member from this role?" },
7
+ { :class => "permission_action" } %>
8
+ </li>
@@ -0,0 +1,81 @@
1
+ <style type="text/css">
2
+ div.auto_complete {
3
+ z-index: 1000;
4
+ }
5
+
6
+ .permission_action {
7
+ font-size: 80%;
8
+ text-transform: uppercase;
9
+ text-decoration: none;
10
+ color: #444;
11
+ background-color: #ffc;
12
+ }
13
+ </style>
14
+ <%= auto_complete_stylesheet %>
15
+
16
+ <% div_for item, :permissions do %>
17
+ <ul>
18
+ <% permission_names(item).each do |perm| -%>
19
+ <li><b><%=h(perm.to_s.humanize)%></b>:
20
+ <% grants = permission_grants(item, perm) -%>
21
+ <% if grants.length == 0 -%>
22
+ <% if all_permitted?(item, perm) -%>
23
+ everybody
24
+ <% elsif grants.length == 0 -%>
25
+ <span id="<%= perm %>_nobody">nobody</span>
26
+ <% end -%>
27
+ <% else -%>
28
+ <% grants.each_index do |i| -%>
29
+ <% grant = grants[i] -%>
30
+ <span id="grant_<%=grant.id%>">
31
+ <% if grant.grantee.kind_of? Role -%>
32
+ <%= image_tag "ae_users/group.png" %>
33
+ <% elsif grant.grantee.kind_of? Person -%>
34
+ <%= image_tag "ae_users/user.png" %>
35
+ <% end -%>
36
+ <% if grant.grantee -%>
37
+ <%= h(grant.grantee.name) %>
38
+ <% else -%>
39
+ Unknown entity
40
+ <% end -%>
41
+ <% if logged_in? and logged_in_person.permitted?(item, "change_permissions") and not (grant.grantee == logged_in_person) -%>
42
+ <%= link_to_remote "Remove",
43
+ { :url => { :controller => "permission", :action => "revoke", :id => grant.id, :format => "js" },
44
+ :success => "$('grant_#{grant.id}').remove();",
45
+ :confirm => "Are you sure you want to revoke that permission?",
46
+ :failure => "alert(request.responseText)" },
47
+ { :class => "permission_action" } %>
48
+ <% end -%>
49
+
50
+ <% if i < grants.length - 1 %>, <% end %>
51
+ </span>
52
+ <% end -%>
53
+ <% end -%>
54
+ <% if logged_in? and logged_in_person.permitted?(item, "change_permissions") -%>
55
+ <div id="<%= perm %>_insert_grants_here" style="display: inline;"></div>
56
+ | <span id="grant_open_<%=perm%>">
57
+ <%= link_to_function "Add", "$('grant_open_#{perm}').toggle(); $('grant_#{perm}').toggle(); $('#{perm}_grantee_shim').focus();",
58
+ :class => "permission_action" %>
59
+ </span>
60
+ <span id="grant_<%=perm %>" style="display: none;">
61
+ <%= link_to_function "&laquo;", "$('grant_open_#{perm}').toggle(); $('grant_#{perm}').toggle();",
62
+ :class => "permission_action" %>
63
+ <%= user_picker "#{perm}_grantee", :roles => true,
64
+ :callback => "nobody = $('#{perm}_nobody');
65
+ if (nobody) {
66
+ nobody.remove();
67
+ }
68
+ new Ajax.Updater('#{perm}_insert_grants_here', '#{url_for :controller => 'permission', :action => 'grant', :perm => full_permission_name(item, perm),
69
+ :item_klass => item.class.name, :item_id => item.id, :escape => false}',
70
+ {
71
+ parameters: { 'klass': klass, 'id': id },
72
+ insertion: Insertion.Bottom,
73
+ }
74
+ );" %>
75
+ </span>
76
+ <% end -%>
77
+ </li>
78
+ <% end -%>
79
+ </ul>
80
+ <% end %>
81
+
File without changes
@@ -0,0 +1,3 @@
1
+ <li><%= image_tag "ae_users/user.png" %>
2
+ <%=h @person.name %>
3
+ </li>
@@ -0,0 +1,45 @@
1
+ <h1>Administration</h1>
2
+
3
+ <style type="text/css">
4
+ .permission_action {
5
+ font-size: 80%;
6
+ text-transform: uppercase;
7
+ text-decoration: none;
8
+ color: #444;
9
+ background-color: #ffc;
10
+ }
11
+ </style>
12
+
13
+ <h2>Base permissions</h2>
14
+
15
+ <blockquote>Base permissions apply to all objects of a particular type. If you grant someone base permissions on a type of object, they will be able to perform that action on any object of that type. Please choose the type of object you want to change the permissions for:</blockquote>
16
+
17
+ <ul>
18
+ <% @pclasses.each do |pc| -%>
19
+ <li>
20
+ <%= link_to pc.name.pluralize.humanize, :action => "edit", :klass => pc.name %>
21
+ </li>
22
+ <% end -%>
23
+ </ul>
24
+
25
+ <h2>Roles</h2>
26
+
27
+ <blockquote>Roles are groups of people. Roles can be given permissions just as if they were people. This can be convenient for assigning permissions to large groups of people at once. Please choose the role you want to edit:</blockquote>
28
+
29
+ <ul>
30
+ <% @roles.each do |role| -%>
31
+ <li id="role_<%= role.id%>">
32
+ <%= link_to role.name, :action => "edit_role", :id => role.id %>
33
+ <%= link_to_remote "Delete",
34
+ { :url => { :controller => "permission", :action => "delete_role", :id => role.id },
35
+ :success => "$('role_#{role.id}').remove();",
36
+ :confirm => "Are you sure you want to delete that role?" },
37
+ { :class => "permission_action" } %>
38
+ </li>
39
+ <% end -%>
40
+ </ul>
41
+
42
+ <% form_for :role, @role, :url => {:action => "create_role"} do |f| %>
43
+ New role: <%= f.text_field "name" %>
44
+ <%= submit_tag "Create" %>
45
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <h1>
2
+ <% if @item.kind_of? ActiveRecord::Base -%>
3
+ Permissions for <%=h @item.name %>
4
+ <% else -%>
5
+ Base permissions for all <%=h @item.name.pluralize %>
6
+ <% end -%>
7
+ </h1>
8
+
9
+ <%= render :partial => "show", :locals => { :item => @item } %>
@@ -0,0 +1,63 @@
1
+ <h1>Editing role <%= @role.name %></h1>
2
+
3
+ <h2>Members</h2>
4
+
5
+ <style type="text/css">
6
+ div.auto_complete {
7
+ z-index: 1000;
8
+ }
9
+
10
+ .permission_action {
11
+ font-size: 80%;
12
+ text-transform: uppercase;
13
+ text-decoration: none;
14
+ color: #444;
15
+ background-color: #ffc;
16
+ }
17
+ </style>
18
+ <%= auto_complete_stylesheet %>
19
+
20
+ <ul style="list-style-type: none;" id="members_list">
21
+ <% @role.people.each do |person| -%>
22
+ <%= render :partial => "role_member", :locals => {:person => person} %>
23
+ <% end -%>
24
+ <span id="add_member_open">
25
+ <%= link_to_function "Add member", "$('add_member_open').toggle(); $('add_member').toggle();",
26
+ :class => "permission_action" %>
27
+ </span>
28
+ <span id="add_member" style="display: none;">
29
+ <%= link_to_function "&laquo;", "$('add_member_open').toggle(); $('add_member').toggle();",
30
+ :class => "permission_action" %>
31
+ <%= user_picker "member_to_add",
32
+ :callback => "new Ajax.Updater('members_list', '#{url_for :controller => 'permission', :action => 'add_role_member',
33
+ :role => @role.id, :escape => false}',
34
+ {
35
+ parameters: { 'klass': klass, 'id': id },
36
+ insertion: Insertion.Top,
37
+ }
38
+ );" %>
39
+ </ul>
40
+
41
+ <h2>Permissions</h2>
42
+
43
+ <ul>
44
+ <% @role.permissions.each do |perm| -%>
45
+ <li>
46
+ <% if perm.permission.nil? -%>
47
+ Global superadmin
48
+ <% else -%>
49
+ <%=h perm.permission.humanize %>
50
+ <% if not perm.permissioned.nil? -%>
51
+ <%=h perm.permissioned.class %>
52
+ <% if perm.permissioned.respond_to? "name" %>
53
+ "<%=h perm.permissioned.name %>"
54
+ <% elsif perm.permissioned.respond_to? "title" %>
55
+ "<%=h perm.permissioned.title %>"
56
+ <% else -%>
57
+ #<%= perm.permissioned.id %>
58
+ <% end -%>
59
+ <% end -%>
60
+ <% end -%>
61
+ </li>
62
+ <% end -%>
63
+ </ul>
@@ -0,0 +1,10 @@
1
+ <% if @perm.grantee.kind_of? Role -%>
2
+ <%= image_tag "ae_users/group.png" %>
3
+ <% elsif @perm.grantee.kind_of? Person -%>
4
+ <%= image_tag "ae_users/user.png" %>
5
+ <% end -%>
6
+ <%= h(@perm.grantee.name) %>
7
+ <%= link_to_remote "Remove",
8
+ { :url => { :controller => "permission", :action => "revoke", :id => @perm.id },
9
+ :success => "$('grant_#{@perm.id}').remove();" },
10
+ { :class => "permission_action" } %>
@@ -0,0 +1,17 @@
1
+ class CreateAccounts < ActiveRecord::Migration
2
+ def self.up
3
+ ActiveRecord::Base.establish_connection :users
4
+ create_table :accounts do |t|
5
+ t.column :password, :string, :null => false
6
+ t.column :active, :boolean
7
+ t.column :activation_key, :string
8
+ t.column :created_at, :datetime
9
+ t.column :updated_at, :datetime
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ ActiveRecord::Base.establish_connection :users
15
+ drop_table :accounts
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class CreateEmailAddresses < ActiveRecord::Migration
2
+ def self.up
3
+ ActiveRecord::Base.establish_connection :users
4
+ create_table :email_addresses do |t|
5
+ t.column :address, :string, :null => false
6
+ t.column :primary, :boolean
7
+ t.column :account_id, :integer, :null => false
8
+ t.column :created_at, :datetime
9
+ t.column :updated_at, :datetime
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ ActiveRecord::Base.establish_connection :users
15
+ drop_table :email_addresses
16
+ end
17
+ end