Add ability to edit profile
This commit is contained in:
parent
a598afb048
commit
f557460f1b
|
@ -1,5 +1,17 @@
|
||||||
class UsersController < Devise::RegistrationsController
|
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
|
def create
|
||||||
build_resource
|
build_resource
|
||||||
|
@ -9,7 +21,7 @@ class UsersController < Devise::RegistrationsController
|
||||||
else
|
else
|
||||||
expire_session_data_after_sign_in!
|
expire_session_data_after_sign_in!
|
||||||
end
|
end
|
||||||
respond_with resource
|
render(:json => resource)
|
||||||
else
|
else
|
||||||
clean_up_passwords(resource)
|
clean_up_passwords(resource)
|
||||||
render(:json => {"errors" => resource.errors})
|
render(:json => {"errors" => resource.errors})
|
||||||
|
|
|
@ -7,4 +7,5 @@
|
||||||
<%= f.submit "Adopt!", :tabindex => 2, :id => "adoption_form_submit" %>
|
<%= 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>
|
<p>By adopting this hydrant, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 3 %>.</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%= render(:partial => 'users/edit_profile') %>
|
||||||
<%= render(:partial => 'users/sign_out') %>
|
<%= render(:partial => 'users/sign_out') %>
|
||||||
|
|
|
@ -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 %>
|
|
@ -1,6 +1,7 @@
|
||||||
<h2><%= @hydrant.name ? @hydrant.name.titleize : "This hydrant" %> has been adopted by <%= @hydrant.user.name %></h2>
|
<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 %>
|
<%= @hydrant.user.organization.blank? ? nil : "<h3>of #{@hydrant.user.organization}</h3>".html_safe %>
|
||||||
<% if user_signed_in? %>
|
<% if user_signed_in? %>
|
||||||
|
<%= render(:partial => 'users/edit_profile') %>
|
||||||
<%= render(:partial => 'hydrants/steal') %>
|
<%= render(:partial => 'hydrants/steal') %>
|
||||||
<%= render(:partial => 'users/sign_out') %>
|
<%= render(:partial => 'users/sign_out') %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
<h2>Thank you for adopting this hydrant!</h2>
|
<h2>Thank you for adopting this hydrant!</h2>
|
||||||
|
<%= render(:partial => 'users/edit_profile') %>
|
||||||
<%= render(:partial => 'hydrants/abandon') %>
|
<%= render(:partial => 'hydrants/abandon') %>
|
||||||
<%= render(:partial => 'users/sign_out') %>
|
<%= render(:partial => 'users/sign_out') %>
|
||||||
|
|
|
@ -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 %>
|
|
@ -4,7 +4,6 @@ AdoptAHydrant::Application.routes.draw do
|
||||||
:registrations => 'users',
|
:registrations => 'users',
|
||||||
:sessions => 'sessions',
|
:sessions => 'sessions',
|
||||||
}
|
}
|
||||||
resource :user
|
|
||||||
get 'hydrants' => 'hydrants#list'
|
get 'hydrants' => 'hydrants#list'
|
||||||
resource :hydrant
|
resource :hydrant
|
||||||
get 'address' => 'addresses#show'
|
get 'address' => 'addresses#show'
|
||||||
|
|
|
@ -400,4 +400,37 @@ $(function() {
|
||||||
return false;
|
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;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue