Add ability to edit profile

This commit is contained in:
Erik Michaels-Ober 2011-03-27 12:44:15 -07:00
parent a598afb048
commit f557460f1b
8 changed files with 72 additions and 3 deletions

View File

@ -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})

View File

@ -7,4 +7,5 @@
<%= f.submit "Adopt!", :tabindex => 2, :id => "adoption_form_submit" %>
<p>By adopting this hydrant, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 3 %>.</p>
<% end %>
<%= render(:partial => 'users/edit_profile') %>
<%= render(:partial => 'users/sign_out') %>

View File

@ -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 %>

View File

@ -1,6 +1,7 @@
<h2><%= @hydrant.name ? @hydrant.name.titleize : "This hydrant" %> has been adopted by <%= @hydrant.user.name %></h2>
<%= @hydrant.user.organization.blank? ? nil : "<h3>of #{@hydrant.user.organization}</h3>".html_safe %>
<% if user_signed_in? %>
<%= render(:partial => 'users/edit_profile') %>
<%= render(:partial => 'hydrants/steal') %>
<%= render(:partial => 'users/sign_out') %>
<% end %>

View File

@ -1,3 +1,4 @@
<h2>Thank you for adopting this hydrant!</h2>
<%= render(:partial => 'users/edit_profile') %>
<%= render(:partial => 'hydrants/abandon') %>
<%= render(:partial => 'users/sign_out') %>

View File

@ -0,0 +1,19 @@
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:id => "edit_form", :method => :put}) do |f| %>
<h2>Edit your Profile</h2>
<%= 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" %> <em>(leave blank if you don't want to change it)</em>
<%= f.password_field "password", :tabindex => 6 %>
<%= f.label "current_password", "Current password", :id => "user_current_password_label" %> <em>(we need your current password to confirm your changes)</em>
<%= f.password_field "current_password", :tabindex => 7 %>
<%= f.submit "Update", :tabindex => 8, :id => "user_update_submit" %>
<% end %>

View File

@ -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'

View File

@ -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;
});
});