From: Benjamin Mako Hill Date: Sun, 17 Jun 2012 23:23:16 +0000 (-0400) Subject: Merge branch 'master' of git://gitorious.org/~ruinar/selectricity/ruinar-selectricity X-Git-Url: https://projects.mako.cc/source/selectricity/commitdiff_plain/15870a550ddd18192efc71c1355a238e7c7c53e8?hp=ee280d9250b5b4c925cc6b4809ce40437d600e7d Merge branch 'master' of git://gitorious.org/~ruinar/selectricity/ruinar-selectricity --- diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 51bd805..4b7fea9 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -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 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 new file mode 100644 index 0000000..b16bc8b --- /dev/null +++ b/app/views/account/change_contact.rhtml @@ -0,0 +1,15 @@ +
+ Change E-mail + +
+
+

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

+ + <% form_tag do -%> + +


+ <%= text_field_tag 'email' %>

+ +

<%= submit_tag 'Submit' %>

+ <% end -%> +
\ No newline at end of file diff --git a/app/views/account/summary.rhtml b/app/views/account/summary.rhtml index 4d79f5b..075d096 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: