From: justin Date: Thu, 14 Apr 2011 06:32:19 +0000 (-0700) Subject: Added funcitionality so user can change the email address associated with their accou... X-Git-Url: https://projects.mako.cc/source/selectricity/commitdiff_plain/b6c33d42dd37f1fb10db479c5d6b7fb4c660beb9 Added funcitionality so user can change the email address associated with their account. Don't think it's particular robust, but was implemented via model attribute assignment methods, so carries any of those associated benefits. --- diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 51bd805..ce4303d 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 17fe702..1358840 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 index d8fa638..b16bc8b 100644 --- a/app/views/account/change_contact.rhtml +++ b/app/views/account/change_contact.rhtml @@ -3,9 +3,11 @@
+

Current E-mail: <%=h @user.email %>

+ <% form_tag do -%> -


+


<%= text_field_tag 'email' %>

<%= submit_tag 'Submit' %>

diff --git a/app/views/account/summary.rhtml b/app/views/account/summary.rhtml index 0ea9f24..61a4b24 100644 --- a/app/views/account/summary.rhtml +++ b/app/views/account/summary.rhtml @@ -10,6 +10,12 @@ E-mail: <%=h @user.email %>
Member since: <%=h @user.created_at.strftime("%x") %>

+

+ <%= link_to "Update Email Address", :action => 'change_contact', + :id => @user.id %> +

+ +

Your Elections: