Extended UsersController#update method for changing password with minimal specs, added form to view and locales (en).

This commit is contained in:
Sebastian 2011-06-01 13:01:34 +02:00
parent 5b408ecca3
commit 602382e24e
4 changed files with 46 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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!"

View file

@ -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'}}}