From d1638755778a8df890afd1fed0b6e5324c6e0795 Mon Sep 17 00:00:00 2001 From: Mark Schmale Date: Sun, 12 Dec 2010 13:23:00 -0800 Subject: [PATCH 1/6] added email validation. The border of the input field becomes red if the input seems to be invalid. --- public/javascripts/validation.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/public/javascripts/validation.js b/public/javascripts/validation.js index 24c8fdf2e..97c4b43e0 100644 --- a/public/javascripts/validation.js +++ b/public/javascripts/validation.js @@ -7,6 +7,9 @@ var Validation = { username: { characters: /^(|[A-Za-z0-9_]{0,32})$/, length: [6, 32] + }, + email: { + characters: /^(([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,}))(, *(([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})))*$/ } }, events: { @@ -15,10 +18,19 @@ var Validation = { if(!Validation.rules.username.characters.test(this.value + String.fromCharCode(evt.keyCode))) { evt.preventDefault(); } + }, + emailKeypress: function(evt) { + if(evt.charCode === 0) { return; } + if(!Validation.rules.email.characters.test(this.value + String.fromCharCode(evt.charCode))) { + $('#user_email').css('border-color', '#8B0000'); + } else { + $('#user_email').css('border-color', '#666666'); + } } } }; $(function() { $("#user_username").keypress(Validation.events.usernameKeypress); + $("#user_email").keypress(Validation.events.emailKeypress); }); From 4cc62ffacab0e43ff64985afc2aefc9ea124445b Mon Sep 17 00:00:00 2001 From: Mark Schmale Date: Mon, 13 Dec 2010 08:38:02 +0100 Subject: [PATCH 2/6] added spec for email validation --- spec/javascripts/validation-spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/javascripts/validation-spec.js b/spec/javascripts/validation-spec.js index ab1aa8931..f289f926d 100644 --- a/spec/javascripts/validation-spec.js +++ b/spec/javascripts/validation-spec.js @@ -7,6 +7,13 @@ describe("Validation", function() { }); }); }); + describe("email", function() { + describe("characters", function() { + it("is the regex for checking if the input is a valid list of e-mail addresses", function() { + expect((typeof Validation.rules.email.characters.test === "function")).toBeTruthy(); + }); + }); + }); }); describe("events", function() { describe("usernameKeypress", function() { @@ -16,5 +23,16 @@ describe("Validation", function() { expect(Validation.rules.username.characters.test("ffffffffffffffffffffffffffffffffff")).toBeFalsy(); }); }); + describe("emailKeypress", function() { + it("colors the border red if the input seems to be a invalid list", function() { + expect(Validation.rules.email.characters.test("user@example.com")).toBeTruthy(); + expect(Validation.rules.email.characters.test("user@example.com, user@example.com")).toBeTruthy(); + expect(Validation.rules.email.characters.test("user@example.com, user@example.com, user@example.com")).toBeTruthy(); + expect(Validation.rules.email.characters.test("user@example.com user@example.com")).toBeFalsy(); + expect(Validation.rules.email.characters.test("user@examplecom")).toBeFalsy(); + expect(Validation.rules.email.characters.test("userexample.com")).toBeFalsy(); + expect(Validation.rules.email.characters.test("userexamplecom")).toBeFalsy(); + }); + }); }); }); From 9a873aa760e1889aba9e8334b37ad9a29156e09a Mon Sep 17 00:00:00 2001 From: Mark Schmale Date: Mon, 13 Dec 2010 15:48:36 +0100 Subject: [PATCH 3/6] added fix for Bug #695 to email-validation --- public/javascripts/validation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/javascripts/validation.js b/public/javascripts/validation.js index 97c4b43e0..923fb7fce 100644 --- a/public/javascripts/validation.js +++ b/public/javascripts/validation.js @@ -20,8 +20,8 @@ var Validation = { } }, emailKeypress: function(evt) { - if(evt.charCode === 0) { return; } - if(!Validation.rules.email.characters.test(this.value + String.fromCharCode(evt.charCode))) { + if(evt.keyCode === 0) { return; } + if(!Validation.rules.email.characters.test(this.value + String.fromCharCode(evt.keyCode))) { $('#user_email').css('border-color', '#8B0000'); } else { $('#user_email').css('border-color', '#666666'); From f861955d8046fe9f3bb9d65f5470495817aa41f5 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 13 Dec 2010 12:11:54 -0800 Subject: [PATCH 4/6] profile.image_url is set to :thumb_large in update_profile --- app/models/user.rb | 2 +- spec/models/user_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index b57131607..b5496f47d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -304,7 +304,7 @@ class User def update_profile(params) if params[:photo] params[:photo].update_attributes(:pending => false) if params[:photo].pending - params[:image_url] = params[:photo].url + params[:image_url] = params[:photo].url(:thumb_large) params[:image_url_medium] = params[:photo].url(:thumb_medium) params[:image_url_small] = params[:photo].url(:thumb_small) end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1e43efc2a..1af1454ab 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -296,7 +296,7 @@ describe User do end it 'updates image_url' do user.update_profile(@params).should be_true - user.reload.profile.image_url.should == @photo.absolute_url + user.reload.profile.image_url.should == @photo.absolute_url(:thumb_large) user.profile.image_url_medium.should == @photo.absolute_url(:thumb_medium) user.profile.image_url_small.should == @photo.absolute_url(:thumb_small) end From d0355fdd43760958dbc1b4bf2dc64469dad2eb8d Mon Sep 17 00:00:00 2001 From: mblog Date: Mon, 13 Dec 2010 22:14:25 +0100 Subject: [PATCH 5/6] Feature #348: Change Email --- app/controllers/users_controller.rb | 8 ++++++++ app/models/user.rb | 2 +- app/views/users/edit.html.haml | 8 ++++++-- config/locales/diaspora/en.yml | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7a45d186c..27ba92eeb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,6 +21,7 @@ class UsersController < ApplicationController params[:user].delete(:password) if params[:user][:password].blank? params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank? params[:user].delete(:language) if params[:user][:language].blank? + params[:user].delete(:email) if params[:user][:email].blank? # change email notifications if params[:user][:disable_mail] @@ -39,6 +40,13 @@ class UsersController < ApplicationController else flash[:error] = I18n.t 'users.update.language_not_changed' end + # change email + elsif params[:user][:email] + if @user.update_attributes(:email => params[:user][:email]) + flash[:notice] = I18n.t 'users.update.email_changed' + else + flash[:error] = I18n.t 'users.update.email_not_changed' + end end redirect_to edit_user_path(@user) diff --git a/app/models/user.rb b/app/models/user.rb index b5496f47d..46eb94392 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -61,7 +61,7 @@ class User person.save if person end - attr_accessible :getting_started, :password, :password_confirmation, :language, :disable_mail + attr_accessible :getting_started, :password, :password_confirmation, :language, :disable_mail, :email def strip_and_downcase_username if username.present? diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 3a813eb82..887b8ad29 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -37,8 +37,12 @@ .span-8.last %h3 = t('.your_email') - %p - = current_user.email + = form_for @user do |f| + = f.error_messages + %p + = f.label :email, current_user.email + = f.text_field :email + = f.submit t('.change_email') %br %br diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 4f42bb261..ab7567534 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -176,6 +176,7 @@ en: close_account: "Close Account" change_language: "Change Language" change_password: "Change Password" + change_email: "Change Email" new_password: "New Password" download_xml: "download my xml" download_photos: "download my photos" @@ -220,6 +221,8 @@ en: language_changed: "Language Changed" language_not_changed: "Language Change Failed" email_notifications_changed: "Language Change Failed" + email_changed: "Email Changed" + email_not_changed: "Email Change Failed" public: does_not_exist: "User %{username} does not exist!" comments: From 3a136570878e6fac79dd618a372e7ee4aa140731 Mon Sep 17 00:00:00 2001 From: MrZYX Date: Mon, 13 Dec 2010 21:48:10 +0100 Subject: [PATCH 6/6] fix for #557 --- app/helpers/sockets_helper.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 8b48069a1..6ce79653d 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -12,6 +12,11 @@ module SocketsHelper def action_hash(uid, object, opts={}) begin user = User.find_by_id uid + unless user.nil? + old_locale = I18n.locale + I18n.locale = user.language.to_s + end + if object.is_a? StatusMessage post_hash = {:post => object, :person => object.person, @@ -59,7 +64,9 @@ module SocketsHelper end action_hash[:mine?] = object.person && (object.person.owner.id == uid) if object.respond_to?(:person) - + + I18n.locale = old_locale unless user.nil? + action_hash.to_json end