From 602382e24e8d67978f5d7441748c65a83dce88de Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 1 Jun 2011 13:01:34 +0200 Subject: [PATCH] Extended UsersController#update method for changing password with minimal specs, added form to view and locales (en). --- app/controllers/users_controller.rb | 7 ++++++ app/views/users/edit.html.haml | 11 ++++++++-- config/locales/diaspora/en.yml | 4 ++++ spec/controllers/users_controller_spec.rb | 26 +++++++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 88076acfa..858bccf2d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -53,6 +53,13 @@ class UsersController < ApplicationController unless u[:a_ids] == ["home"] @user.aspects.where(:id => u[:a_ids]).update_all(:open => true) end + elsif u[:email] + @user.unconfirmed_email = u[:email] + if @user.save + flash[:notice] = I18n.t 'users.update.unconfirmed_email_changed' + else + flash[:error] = I18n.t 'users.update.unconfirmed_email_not_changed' + end end end diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 54f960817..1721df878 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -22,8 +22,15 @@ .span-5.last %h3 = t('.your_email') - %p - = current_user.email + = form_for 'user', :url => user_path, :html => { :method => :put } do |f| + = f.error_messages + %p + = f.text_field :email, :value => @user.unconfirmed_email || @user.email + = f.submit t('.change_email') + %br + - if @user.unconfirmed_email.present? + %p= t('.email_awaiting_confirmation', :email => @user.email, :unconfirmed_email => @user.unconfirmed_email) + %br %br %br diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 782aa46d1..012f4e579 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -688,6 +688,7 @@ en: close_account: "Close Account" change_language: "Change Language" change_password: "Change Password" + change_email: "Change E-Mail" new_password: "New Password" current_password: "Current password" download_xml: "download my xml" @@ -703,6 +704,7 @@ en: private_message: "...you receive a private message?" liked: "...someone likes your post?" change: "Change" + email_awaiting_confirmation: "We have sent you an activation link to %{unconfirmed_email}. Till you follow this link and activate the new address, we will continue to use your original address %{email}." destroy: "Account successfully closed." getting_started: welcome: "Welcome to Diaspora!" @@ -726,6 +728,8 @@ en: language_changed: "Language Changed" language_not_changed: "Language Change Failed" email_notifications_changed: "Email notifications changed" + unconfirmed_email_changed: "E-Mail Changed. Needs activation." + unconfirmed_email_not_changed: "E-Mail Change Failed" public: does_not_exist: "User %{username} does not exist!" diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index dc99406a8..8e070a0d7 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -108,6 +108,32 @@ describe UsersController do end end + describe 'email' do + it 'allow the user to change his (unconfirmed) email' do + put(:update, :id => @user.id, :user => { :email => "my@newemail.com"}) + @user.reload + @user.unconfirmed_email.should eql("my@newemail.com") + end + + it 'informs the user about success' do + put(:update, :id => @user.id, :user => { :email => "my@newemail.com"}) + request.flash[:notice].should eql(I18n.t('users.update.unconfirmed_email_changed')) + request.flash[:error].should be_blank + end + + it 'informs the user about failure' do + put(:update, :id => @user.id, :user => { :email => "my@newemailcom"}) + request.flash[:error].should eql(I18n.t('users.update.unconfirmed_email_not_changed')) + request.flash[:notice].should be_blank + end + + it 'allow the user to change his (unconfirmed) email to blank (= abort confirmation)' do + put(:update, :id => @user.id, :user => { :email => ""}) + @user.reload + @user.unconfirmed_email.should eql(nil) + end + end + describe 'email settings' do it 'lets the user turn off mail' do par = {:id => @user.id, :user => {:email_preferences => {'mentioned' => 'true'}}}