Merge branch 'master' of git://gitorious.org/~ruinar/selectricity/ruinar-selectricity
authorBenjamin Mako Hill <mako@atdot.cc>
Sun, 17 Jun 2012 23:23:16 +0000 (19:23 -0400)
committerBenjamin Mako Hill <mako@atdot.cc>
Sun, 17 Jun 2012 23:23:16 +0000 (19:23 -0400)
app/controllers/account_controller.rb
app/models/user.rb
app/views/account/change_contact.rhtml [new file with mode: 0644]
app/views/account/summary.rhtml

index 51bd80500f424b0cdd7329d0b961286c118cacab..4b7fea9fc17451bdb11fde5be136ee7b022ccd1c 100644 (file)
@@ -60,7 +60,26 @@ class AccountController < ApplicationController
   
   #The following methods are for selectricity specific uses
   def summary
+    #@user = User.find(params[:id])
+    
+    #constrain the find command such that it only returns the user if it's the currently
+    #logged in user, otherwise, redirect to the front page
+    id = params[:id]
+    user_id = session[:user][:id]
+    @user = User.find(id, :conditions => ["id = ?", user_id])
+    
+    rescue
+      redirect_to :controller =>'front'
+    
+  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
   
   
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
diff --git a/app/views/account/change_contact.rhtml b/app/views/account/change_contact.rhtml
new file mode 100644 (file)
index 0000000..b16bc8b
--- /dev/null
@@ -0,0 +1,15 @@
+<div id="title-header">
+  <span class="header">Change E-mail</span>
+  <span class="subheader"></span>
+</div>
+<div class="user_edit">
+       <p>Current E-mail: <%=h @user.email %></p>
+       
+       <% form_tag do -%>
+       
+       <p><label for="login">New E-mail</label><br/>
+       <%= text_field_tag 'email' %></p>
+       
+       <p><%= submit_tag 'Submit' %></p>
+       <% end -%>
+</div>
\ No newline at end of file
index 4d79f5b18fe3b0011145a6981c9d69cd038bf31f..075d0964b2fbd26b76bc9d0f1dbee96662ddb3d3 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?