Added funcitionality so user can change the email address associated with their accou...
authorjustin <tr0phy13@gmail.com>
Thu, 14 Apr 2011 06:32:19 +0000 (23:32 -0700)
committerjustin <tr0phy13@gmail.com>
Thu, 14 Apr 2011 06:32:19 +0000 (23:32 -0700)
app/controllers/account_controller.rb
app/models/user.rb
app/views/account/change_contact.rhtml
app/views/account/summary.rhtml

index 51bd80500f424b0cdd7329d0b961286c118cacab..ce4303dde9694e64a1c00d9293ba291e5abcf85e 100644 (file)
@@ -63,6 +63,15 @@ class AccountController < ApplicationController
     @user = User.find(params[:id])
   end
   
+  def change_contact
+    @user = User.find(params[:id])
+    return unless request.post?
+    @user.email=params[:email]
+    @user.save!
+    flash[:notice] = "Email successfully updated"
+    render :action => 'summary'
+  end
+  
   
 end
 
index 17fe702332970e51b7f1ecacb3e0627e70feb312..13588402064c996a69e018283ffa1dc5f4a63f61 100644 (file)
@@ -25,6 +25,10 @@ class User < ActiveRecord::Base
   def name
      [ firstname, lastname].join(" ")
   end
+  
+  def email=(new_email)
+    self[:email] = new_email
+  end
 
   # Authenticates a user by their login name and unencrypted password.  Returns the user or nil.
   def self.authenticate(login, password)
@@ -82,4 +86,5 @@ class User < ActiveRecord::Base
       errors.add(:login, "should not begin or end with spaces") if login and login.strip!
       errors.add(:login, "should contain only letters, numbers, and spaces") unless login =~ /^[A-Za-z0-9 ]*$/
     end
+    
 end
index d8fa638eda7ede21fc6b0ae9b00853177a1a34f7..b16bc8b3954c51c900457f35aac82328d7e8214f 100644 (file)
@@ -3,9 +3,11 @@
   <span class="subheader"></span>
 </div>
 <div class="user_edit">
+       <p>Current E-mail: <%=h @user.email %></p>
+       
        <% form_tag do -%>
        
-       <p><label for="login">Change E-mail</label><br/>
+       <p><label for="login">New E-mail</label><br/>
        <%= text_field_tag 'email' %></p>
        
        <p><%= submit_tag 'Submit' %></p>
index 0ea9f241dcb729614205a6445581998fc1b3335a..61a4b24735d1d2d45cbbf299a955c3856b425230 100644 (file)
@@ -10,6 +10,12 @@ E-mail: <%=h @user.email %><br />
 Member since: <%=h @user.created_at.strftime("%x") %>
 </p>
 
+<p>
+       <%= link_to "Update Email Address", :action => 'change_contact',
+                                                                         :id => @user.id %>
+</p>
+
+
 <p>Your Elections:
   <table class="voterbox" id="election">
     <tr>

Benjamin Mako Hill || Want to submit a patch?