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,7 @@
1
+ class Role < ActiveRecord::Base
2
+ acts_as_permissioned :permission_names => ['edit']
3
+
4
+ establish_connection :users
5
+ has_and_belongs_to_many :people
6
+ has_many :permissions, :dependent => :destroy
7
+ end
@@ -0,0 +1,35 @@
1
+ <h2>Personal Information</h2>
2
+ <table>
3
+ <tr>
4
+ <th style="text-align: right;">
5
+ <label for="person_firstname">First name</label>
6
+ </th>
7
+ <td>
8
+ <%= f.text_field "firstname" %>
9
+ </td>
10
+ </tr>
11
+ <tr>
12
+ <th style="text-align: right;">
13
+ <label for="person_lastname">Last name</label>
14
+ </th>
15
+ <td>
16
+ <%= f.text_field "lastname" %>
17
+ </td>
18
+ </tr>
19
+ <tr>
20
+ <th style="text-align: right;">
21
+ <label for="person_birthdate">Date of birth</label>
22
+ </th>
23
+ <td>
24
+ <%= f.date_select "birthdate", :include_blank => true, :start_year => Date.today.year, :end_year => 1900, :order => [:month, :day, :year] %>
25
+ </td>
26
+ </tr>
27
+ <tr>
28
+ <th style="text-align: right;">
29
+ <label for="person_lastname">Gender</label>
30
+ </th>
31
+ <td>
32
+ <%= f.select "gender", ["", "male", "female"] %>
33
+ </td>
34
+ </tr>
35
+ </table>
@@ -0,0 +1,3 @@
1
+ <%= f.label "nickname", "Nickname:" %> <%= f.text_field "nickname" %><br/>
2
+ <%= f.label "phone", "Phone number:" %> <%= f.text_field "phone" %><br/>
3
+ <%= f.label "best_call_time", "Best time to call:" %> <%= f.text_field "best_call_time" %>
@@ -0,0 +1,39 @@
1
+ <h2>Account Info</h2>
2
+ <table>
3
+ <tr>
4
+ <th style="text-align: right;">
5
+ <label for="email" class="required">Email address:</label>
6
+ </th>
7
+ <td>
8
+ <%= text_field_tag "email", params[:email] %>
9
+ </td>
10
+ </tr>
11
+ <tr>
12
+ <th style="text-align: right;">
13
+ <label for="password1" class="required">Password:</label>
14
+ </th>
15
+ <td>
16
+ <%= password_field_tag "password1", params[:password1] %>
17
+ </td>
18
+ </tr>
19
+ <tr>
20
+ <th style="text-align: right;">
21
+ <label for="password2" class="required">Re-enter password:</label>
22
+ </th>
23
+ <td>
24
+ <%= password_field_tag "password2", params[:password2] %>
25
+ </td>
26
+ </tr>
27
+ </table>
28
+
29
+ <%= render :partial => "account/personal_info", :locals => {:f => f} %>
30
+
31
+ <% if @app_profile -%>
32
+ <% form_for("app_profile", @app_profile) do |profile_form| %>
33
+ <%= render :partial => "account/#{@app_profile.class.name.tableize.singularize}",
34
+ :locals => {:f => profile_form}%>
35
+ <p><%= submit_tag "Complete registration" %></p>
36
+ <% end %>
37
+ <% else -%>
38
+ <p><%= submit_tag "Complete registration" %></p>
39
+ <% end -%>
@@ -0,0 +1,6 @@
1
+ <h1>Thank you</h1>
2
+
3
+ <p><%= @account.person.firstname %>, you have successfully activated your account.
4
+ You can now log in using your email address and password.</p>
5
+
6
+ <p>To log in, <%= link_to "return to the main page", "/" %>.</p>
@@ -0,0 +1,11 @@
1
+ <h1>Activation error</h1>
2
+
3
+ <p>We're sorry, there was an error while activating your account. One of several things has happened:</p>
4
+
5
+ <ul>
6
+ <li>The account was already active.</li>
7
+ <li>No account matching that account ID could be found.</li>
8
+ <li>The activation key you used was incorrect or out of date.</li>
9
+ </ul>
10
+
11
+ <p>If you feel you've reached this page in error, please contact the site administrators.</p>
@@ -0,0 +1,3 @@
1
+ <h1>Thank you</h1>
2
+
3
+ <p>Your password has been changed.</p>
@@ -0,0 +1,117 @@
1
+ <h1>Edit your profile</h1>
2
+
3
+ <style type="text/css">
4
+ form {
5
+ max-width: 640px;
6
+ }
7
+ </style>
8
+
9
+ <% if @person.account -%>
10
+ <% form_for("password", nil, :url => {:action => 'change_password'},
11
+ :html => {:id => 'change_password_form'}) do |f| %>
12
+ <h2>Change password</h2>
13
+ <table>
14
+ <tr>
15
+ <th style="text-align: right;">
16
+ <label for="password_password1">New password</label>
17
+ </th>
18
+ <td>
19
+ <%= f.password_field "password1", :label => "New password" %>
20
+ </td>
21
+ </tr>
22
+ <tr>
23
+ <th style="text-align: right;">
24
+ <label for="password_password2">Confirm new password</label>
25
+ </th>
26
+ <td>
27
+ <%= f.password_field "password2", :label => "New password" %>
28
+ </td>
29
+ </tr>
30
+ </table>
31
+ <p>
32
+ <%= submit_tag "Change password" %>
33
+ </p>
34
+ <% end %>
35
+ <% end -%>
36
+
37
+ <h2>OpenID Identities</h2>
38
+
39
+ <p>OpenID is a free and easy way to use a single digital identity across the Internet. For more information,
40
+ <%= link_to "visit the OpenID web site", "http://www.openid.net" %>.</p>
41
+
42
+ <table>
43
+ <% @person.open_id_identities.each do |id| -%>
44
+ <tr>
45
+ <td></td>
46
+ <td>
47
+ <%= image_tag "ae_users/openid.gif" %>
48
+ <i><%=h id.identity_url %></i>
49
+ </td>
50
+ <td><%= button_to "Delete", {:action => "delete_openid", :id => id.id}, {:confirm => "Are you sure you wish to remove this OpenID?"} %></td>
51
+ </tr>
52
+ <% end -%>
53
+ <tr>
54
+ <% form_for("add_openid", nil, :url => {:action => "add_openid"}) do |f| -%>
55
+ <td>Add new OpenID:</td>
56
+ <td><%= text_field_tag "openid_url", @openid_url, :style => "background: #FFFFFF url('#{image_path "ae_users/openid.gif"}') no-repeat scroll 0pt 50%; padding-left: 18px; width: 60%;" %></td>
57
+ <td><%= submit_tag "Add" %></td>
58
+ <% end -%>
59
+ </tr>
60
+ </table>
61
+
62
+ <% form_for("email_addresses", nil, :url => {:action => 'edit_email_addresses'},
63
+ :html => {:id => 'edit_email_addresses_form'}) do |f| %>
64
+
65
+ <h2>Edit email addresses</h2>
66
+
67
+ <p>Note: every account must have one "primary" email address. This is the one the site will use
68
+ to send you email (for example, if you forget your password).</p>
69
+
70
+ <table>
71
+ <tr>
72
+ <th></th>
73
+ <th>Address</th>
74
+ <th>Primary</th>
75
+ <th>Delete</th>
76
+ </tr>
77
+ <% @person.email_addresses.each do |addr| -%>
78
+ <tr>
79
+ <td></td>
80
+ <td>
81
+ <i><%= addr.address %></i>
82
+ </td>
83
+ <td>
84
+ <%= radio_button_tag "primary", addr.id, addr.primary %>
85
+ </td>
86
+ <td>
87
+ <%= check_box_tag "delete", addr.id %>
88
+ </td>
89
+ </tr>
90
+ <% end -%>
91
+ <tr>
92
+ <td>Add new address:</td>
93
+ <td>
94
+ <%= text_field_tag "new_address", "", :style => "width: 100%" %>
95
+ </td>
96
+ <td>
97
+ <%= radio_button_tag "primary", "new" %>
98
+ </td>
99
+ </tr>
100
+ </table>
101
+ <%= submit_tag "Edit email addresses" %>
102
+ <% end %>
103
+
104
+ <% form_for("person", @person, :url => {:action => 'edit_profile'},
105
+ :html => {:id => 'edit_profile_form'}) do |f| %>
106
+ <%= render :partial => 'personal_info', :locals => {:f => f} %>
107
+ <% if @app_profile -%>
108
+
109
+ <% form_for("app_profile", @app_profile) do |profile_form| %>
110
+ <%= render :partial => "account/#{@app_profile.class.name.tableize.singularize}",
111
+ :locals => {:f => profile_form}%>
112
+ <%= submit_tag "Edit profile" %>
113
+ <% end %>
114
+ <% else -%>
115
+ <%= submit_tag "Edit profile" %>
116
+ <% end -%>
117
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% form_for("person", @person, :url => {:action => 'signup'},
2
+ :html => {:id => 'signup_form'}) do |f| -%>
3
+
4
+ <h1>Sign up</h1>
5
+ <p>Thanks for creating an account! We just need a few pieces of information from you before we can complete your
6
+ signup process.</p>
7
+
8
+ <%= render :partial => 'signup_form', :locals => { :f => f } %>
9
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ <h1>Signup Complete</h1>
2
+
3
+ <p>Thanks for signing up! Your account has been created, <b>but there was an error attempting to send you an
4
+ activation email</b>. (This is not your problem, it's ours.)</p>
5
+
6
+ <p>Your account has therefore been activated immediately. You can use the form in the upper right-hand corner
7
+ of the page to log in.</p>
@@ -0,0 +1,8 @@
1
+ <h1>Signup Complete</h1>
2
+
3
+ <p>Thanks for signing up! Your account has been created, <b>but we still need you to activate it</b> in order to
4
+ verify that the email address you entered really belongs to you. We've sent an activation email to the address
5
+ you entered, and when you receive it, please follow the link in that message to activate
6
+ your account.</p>
7
+
8
+ <p>If you don't get the activation email, please contact the site administrators to let them know.</p>
@@ -0,0 +1,54 @@
1
+ <%= auth_stylesheet %>
2
+
3
+ <% form_for('login', @login, :url => {:action => 'login', :controller => 'auth'},
4
+ :html => {:class => 'auth_form'} ) do |f| -%>
5
+ <% if not logged_in? %>
6
+ <script type="text/javascript" src="<%=url_for :controller => 'auth', :action => "auth_form",
7
+ :format => "js", :openid_url => params[:openid_url] %>"></script>
8
+
9
+ <%= f.hidden_field "return_to" %>
10
+
11
+ <p>
12
+ <label for="email" class="block">Email address</label>
13
+ <%= text_field "login", "email", :tabindex => 1%>
14
+ </p>
15
+
16
+ <% if AeUsers.signup_allowed? -%>
17
+ <p>
18
+ <label class="block">Do you have a password?</label>
19
+ <%= f.radio_button "have_password", "false" %> <label for="login_have_password_false">No, I am a new user.</label>
20
+ <br/>
21
+ <%= f.radio_button "have_password", "true" %> <label for="login_have_password_true">Yes, my password is:</label>
22
+ <div style="margin-left: 2em; margin-top: 0; padding-top: 0;">
23
+ <%= password_field "login", "password" %>
24
+ </div>
25
+ </p>
26
+ <% else -%>
27
+ <p>
28
+ <label for="password" class="block">Password</label>
29
+ <%= password_field "login", "password", :tabindex => 2 %>
30
+ </p>
31
+ <% end -%>
32
+
33
+ <p style="text-align: center;">
34
+ <%= submit_tag "Log in", :style => "width: 20%; display: inline" %>
35
+ </p>
36
+
37
+ <% else %>
38
+ <div style="text-align: right; margin-right: 1em;">
39
+ <p>You are currently logged in as <%= logged_in_person.name %>.</p>
40
+ <p>
41
+ <% if logged_in_person.administrator? -%>
42
+ <%= image_tag "ae_users/admin.png" %>
43
+ <%= link_to "Administration", :controller => 'permission', :action => 'admin' %>
44
+ <span style="margin-right: 1em;">&nbsp;</span>
45
+ <% end -%>
46
+ <%= image_tag "ae_users/user.png" %>
47
+ <%= link_to "Edit profile", :controller => 'account', :action => 'edit_profile' %>
48
+ <span style="margin-right: 1em;">&nbsp;</span>
49
+ <%= image_tag "ae_users/logout.png" %>
50
+ <%= link_to "Log out", :controller => :auth, :action => :logout %>
51
+ </p>
52
+ </div>
53
+ <% end %>
54
+ <% end -%>
@@ -0,0 +1,12 @@
1
+ <%= auth_stylesheet %>
2
+
3
+ <% form_for "forgot", @forgot, :url => {:action => 'forgot', :controller => 'auth'},
4
+ :html => {:id => 'forgot_form', :style => 'max-width: 400px;', :class => 'auth_form'} do |f| %>
5
+
6
+ <label for="email" class="block">Email address:</label>
7
+ <%= text_field_tag "email" %>
8
+
9
+ <p style="text-align: center;">
10
+ <%= submit_tag "Email me a new password", :style => "width: 90%; display: inline" %>
11
+ </p>
12
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <div class="authbox">
2
+ <% if logged_in? -%>
3
+ <%= image_tag('ae_users/user.png') %>
4
+ <%= link_to logged_in_person.name,
5
+ :controller => 'account', :action => 'edit_profile' %>
6
+ <% if logged_in_person.administrator? -%>
7
+ |
8
+ <%= image_tag "ae_users/admin.png" %>
9
+ <%= link_to "Administration", :controller => 'permission', :action => 'admin' %>
10
+ <% end -%>
11
+ |
12
+ <%= image_tag "ae_users/logout.png" %>
13
+ <%= link_to "Log out", :controller => 'auth', :action => 'logout' %>
14
+ <% else -%>
15
+ <%= link_to "Log in", :controller => 'auth', :action => 'login', :return_to => url_for() %>
16
+ <% end -%>
17
+ </div>
@@ -0,0 +1,14 @@
1
+ <%= auth_stylesheet %>
2
+
3
+ <% form_for('login', @login, :url => {:action => 'openid_login', :controller => 'auth'},
4
+ :html => {:class => 'auth_form'} ) do |f| -%>
5
+
6
+ <%= f.hidden_field "return_to" %>
7
+
8
+ <label for="openid_url" class="block">OpenID</label>
9
+ <%= text_field_tag "openid_url" %>
10
+
11
+ <p style="text-align: center;">
12
+ <%= submit_tag "Log in with OpenID", :style => "width: 50%; display: inline" %>
13
+ </p>
14
+ <% end -%>
@@ -0,0 +1,24 @@
1
+ <% unless logged_in? -%>
2
+ <ul id="other_login_options">
3
+ <% if params[:action] == "login" -%>
4
+ <li>
5
+ <%= link_to "I forgot my password", :controller => "auth", :action => "forgot_form" %>
6
+ </li>
7
+ <% end -%>
8
+ <% if params[:action] == "openid_login" -%>
9
+ <li>
10
+ <%= link_to "What's OpenID?", "http://www.openid.net", :target => "_blank" %>
11
+ </li>
12
+ <% end -%>
13
+ <% unless params[:action] == "openid_login" -%>
14
+ <li>
15
+ <%= link_to "Log in with OpenID", :controller => "auth", :action => "openid_login", :return_to => @login.return_to %>
16
+ </li>
17
+ <% end -%>
18
+ <% unless params[:action] == "login" -%>
19
+ <li>
20
+ <%= link_to "Log in with a password", :controller => "auth", :action => "login", :return_to => @login.return_to %>
21
+ </li>
22
+ <% end -%>
23
+ </ul>
24
+ <% end -%>
@@ -0,0 +1,63 @@
1
+ <% if AeUsers.js_framework == "jquery" -%>
2
+ function chooseHavePassword() {
3
+ val = jQuery('.auth_form input[name="login[have_password]"]:checked').val();
4
+ $password = jQuery('.auth_form input[name="login[password]"]');
5
+ $password.val("");
6
+
7
+ if (val == "true") {
8
+ $password.attr('disabled', '');
9
+ $password.focus();
10
+ } else {
11
+ $password.attr('disabled', 'disabled');
12
+ }
13
+ }
14
+
15
+ function emailKeyPressListener(event) {
16
+ if (event.keyCode == 9) {
17
+ jQuery('#login_have_password_true').attr({'checked': 'true'});
18
+ chooseHavePassword();
19
+ event.stopPropagation();
20
+ event.preventDefault();
21
+ }
22
+ }
23
+
24
+ jQuery(document).ready(function () {
25
+ <% if (params[:login] and params[:login][:password]) -%>
26
+ jQuery('.auth_form input[name="login[have_password]"][value="false"]').attr('checked', 'checked');
27
+ <% end -%>
28
+ chooseHavePassword();
29
+ jQuery('.auth_form input[name="login[have_password]"]').bind('change', chooseHavePassword);
30
+ jQuery('.auth_form input[name="login[email]"]').bind('keydown', emailKeyPressListener);
31
+ });
32
+ <% else -%>
33
+ function chooseHavePassword() {
34
+ val = $('login_have_password_true').checked;
35
+ password = $('login_password');
36
+ password.value = "";
37
+
38
+ if (val) {
39
+ password.disabled = false;
40
+ password.focus();
41
+ } else {
42
+ password.disabled = true;
43
+ }
44
+ }
45
+
46
+ function emailKeyPressListener(event) {
47
+ if (event.keyCode == 9) {
48
+ $('login_have_password_true').checked = true;
49
+ chooseHavePassword();
50
+ Event.stop(event);
51
+ }
52
+ }
53
+
54
+ Event.observe(window, 'load', function () {
55
+ <% if (params[:login] and params[:login][:password]) -%>
56
+ $('login_have_password_true').checked = true;
57
+ <% end -%>
58
+ chooseHavePassword();
59
+ $('login_have_password_true').observe('change', chooseHavePassword);
60
+ $('login_have_password_false').observe('change', chooseHavePassword);
61
+ $('login_email').observe('keypress', emailKeyPressListener);
62
+ });
63
+ <% end -%>