From b6c33d42dd37f1fb10db479c5d6b7fb4c660beb9 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 13 Apr 2011 23:32:19 -0700 Subject: [PATCH] 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. --- app/controllers/account_controller.rb | 9 +++++++++ app/models/user.rb | 5 +++++ app/views/account/change_contact.rhtml | 4 +++- app/views/account/summary.rhtml | 6 ++++++ 4 files changed, 23 insertions(+), 1 deletion(-) 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: -- 2.39.5