diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 4830403..0ee3b25 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,5 +1,17 @@
class UsersController < Devise::RegistrationsController
- respond_to :json
+ def edit
+ render_with_scope :edit
+ end
+
+ def update
+ if resource.update_with_password(params[resource_name])
+ sign_in resource_name, resource, :bypass => true
+ redirect_to :controller => "hydrants", :action => "show", :hydrant_id => params[:hydrant_id]
+ else
+ clean_up_passwords(resource)
+ render(:json => {"errors" => resource.errors})
+ end
+ end
def create
build_resource
@@ -9,7 +21,7 @@ class UsersController < Devise::RegistrationsController
else
expire_session_data_after_sign_in!
end
- respond_with resource
+ render(:json => resource)
else
clean_up_passwords(resource)
render(:json => {"errors" => resource.errors})
diff --git a/app/views/hydrants/_adopt.html.erb b/app/views/hydrants/_adopt.html.erb
index 2241c10..745b363 100644
--- a/app/views/hydrants/_adopt.html.erb
+++ b/app/views/hydrants/_adopt.html.erb
@@ -7,4 +7,5 @@
<%= f.submit "Adopt!", :tabindex => 2, :id => "adoption_form_submit" %>
By adopting this hydrant, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 3 %>.
<% end %>
+<%= render(:partial => 'users/edit_profile') %>
<%= render(:partial => 'users/sign_out') %>
diff --git a/app/views/users/_edit_profile.html.erb b/app/views/users/_edit_profile.html.erb
new file mode 100644
index 0000000..7658016
--- /dev/null
+++ b/app/views/users/_edit_profile.html.erb
@@ -0,0 +1,3 @@
+<%= form_for :user, :url => edit_user_registration_path, :html => {:id => "edit_profile_form", :method => "get"} do |f| %>
+ <%= f.submit "Edit profile", :id => "edit_profile_form_submit" %>
+<% end %>
diff --git a/app/views/users/_profile.html.erb b/app/views/users/_profile.html.erb
index d47a9a1..2a47ed1 100644
--- a/app/views/users/_profile.html.erb
+++ b/app/views/users/_profile.html.erb
@@ -1,6 +1,7 @@
<%= @hydrant.name ? @hydrant.name.titleize : "This hydrant" %> has been adopted by <%= @hydrant.user.name %>
<%= @hydrant.user.organization.blank? ? nil : "of #{@hydrant.user.organization}
".html_safe %>
<% if user_signed_in? %>
+<%= render(:partial => 'users/edit_profile') %>
<%= render(:partial => 'hydrants/steal') %>
<%= render(:partial => 'users/sign_out') %>
<% end %>
diff --git a/app/views/users/_thank_you.html.erb b/app/views/users/_thank_you.html.erb
index 4044ec6..5ddc3cd 100644
--- a/app/views/users/_thank_you.html.erb
+++ b/app/views/users/_thank_you.html.erb
@@ -1,3 +1,4 @@
Thank you for adopting this hydrant!
+<%= render(:partial => 'users/edit_profile') %>
<%= render(:partial => 'hydrants/abandon') %>
<%= render(:partial => 'users/sign_out') %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb
new file mode 100644
index 0000000..6232234
--- /dev/null
+++ b/app/views/users/edit.html.erb
@@ -0,0 +1,19 @@
+<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:id => "edit_form", :method => :put}) do |f| %>
+ Edit your Profile
+ <%= f.hidden_field "id" %>
+ <%= f.label "email", "Email address", :id => "user_email_label" %>
+ <%= f.text_field "email", :tabindex => 1 %>
+ <%= f.label "name", "Name", :id => "user_name_label" %>
+ <%= f.text_field "name", :tabindex => 2 %>
+ <%= f.label "organization", "Organization", :id => "user_organization_label" %>
+ <%= f.text_field "organization", :tabindex => 3 %>
+ <%= f.label "voice_number", "Phone number", :id => "user_voice_number_label" %>
+ <%= f.text_field "voice_number", :tabindex => 4 %>
+ <%= f.label "sms_number", "SMS number", :id => "user_sms_number_label" %>
+ <%= f.text_field "sms_number", :tabindex => 5 %>
+ <%= f.label "password", "New password", :id => "user_password_label" %> (leave blank if you don't want to change it)
+ <%= f.password_field "password", :tabindex => 6 %>
+ <%= f.label "current_password", "Current password", :id => "user_current_password_label" %> (we need your current password to confirm your changes)
+ <%= f.password_field "current_password", :tabindex => 7 %>
+ <%= f.submit "Update", :tabindex => 8, :id => "user_update_submit" %>
+<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index eafbff7..9706e0f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -4,7 +4,6 @@ AdoptAHydrant::Application.routes.draw do
:registrations => 'users',
:sessions => 'sessions',
}
- resource :user
get 'hydrants' => 'hydrants#list'
resource :hydrant
get 'address' => 'addresses#show'
diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index 0b5110d..03d1d4e 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -400,4 +400,37 @@ $(function() {
return false;
}
});
+ $('#edit_profile_form').live('submit', function() {
+ $.get('/users/edit', {
+ 'commit': $('#edit_profile_form_submit').val(),
+ 'utf8': '✓',
+ 'authenticity_token': $('#edit_profile_form input[name="authenticity_token"]').val()
+ }, function(data) {
+ activeInfoWindow.setContent(data);
+ });
+ return false;
+ });
+ $('#edit_form').live('submit', function() {
+ $.post('/users.json', {
+ 'id': $('#id').val(),
+ 'hydrant_id': activeHydrantId,
+ 'commit': $('#edit_form_submit').val(),
+ 'utf8': '✓',
+ 'authenticity_token': $('#edit_form input[name="authenticity_token"]').val(),
+ '_method': 'put',
+ 'user': {
+ 'email': $('#user_email').val(),
+ 'name': $('#user_name').val(),
+ 'organization': $('#user_organization').val(),
+ 'voice_number': $('#user_voice_number').val(),
+ 'sms_number': $('#user_sms_number').val(),
+ 'password': $('#user_password').val(),
+ 'password_confirmation': $('#user_password').val(),
+ 'current_password': $('#user_current_password').val()
+ }
+ }, function(data) {
+ activeInfoWindow.setContent(data);
+ });
+ return false;
+ });
});