From efc399623f015776a2c7618df37b575852e698b2 Mon Sep 17 00:00:00 2001 From: kumm Date: Sun, 26 May 2013 13:33:39 +0200 Subject: [PATCH 1/2] add login column, and use it on signin instead of email --- barkeep_server.rb | 8 ++++---- ...0130521220244_add_login_column_to_users.rb | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 migrations/20130521220244_add_login_column_to_users.rb diff --git a/barkeep_server.rb b/barkeep_server.rb index 29bb98a1..f9fd6ccf 100644 --- a/barkeep_server.rb +++ b/barkeep_server.rb @@ -173,7 +173,7 @@ def ensure_required_params(*required_params) before do # When running in read-only demo mode, if the user is not logged in, treat them as a demo user. - self.current_user ||= User.find(:email => session[:email]) + self.current_user ||= User.find(:login => session[:login]) if current_user.nil? && (defined?(ENABLE_READONLY_DEMO_MODE) && ENABLE_READONLY_DEMO_MODE) self.current_user = User.first(:permission => "demo") current_user.rack_session = session @@ -245,11 +245,11 @@ def ensure_required_params(*required_params) halt 401, "Your email #{email} is not authorized to login to Barkeep." end end - session[:email] = email - unless User.find(:email => email) + session[:login] = email + unless User.find(:login => email) # If there are no admin users yet, make the first user to log in the first admin. permission = User.find(:permission => "admin").nil? ? "admin" : "normal" - User.new(:email => email, :name => email, :permission => permission).save + User.new(:login => email, :email => email, :name => email, :permission => permission).save end redirect session[:login_started_url] || "/" end diff --git a/migrations/20130521220244_add_login_column_to_users.rb b/migrations/20130521220244_add_login_column_to_users.rb new file mode 100644 index 00000000..a69049a5 --- /dev/null +++ b/migrations/20130521220244_add_login_column_to_users.rb @@ -0,0 +1,20 @@ +require "bundler/setup" +require "pathological" +require "migrations/migration_helper.rb" + +Sequel.migration do + up do + alter_table(:users) { + add_column :login, String + add_index :login, :unique => true, :name => "login_is_unique_per_user" + } + run 'UPDATE users SET login=email' + end + + down do + alter_table(:users) { + drop_index :login, :name => "login_is_unique_per_user" + drop_column :login + } + end +end From 8e7927aaac415b956724f67afa88641e53e897ce Mon Sep 17 00:00:00 2001 From: kumm Date: Sun, 26 May 2013 13:39:33 +0200 Subject: [PATCH 2/2] make users.email editable at user settings --- barkeep_server.rb | 5 ++++- public/coffee/user_settings.coffee | 1 + views/user_settings.erb | 10 +++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/barkeep_server.rb b/barkeep_server.rb index f9fd6ccf..7d11ee27 100644 --- a/barkeep_server.rb +++ b/barkeep_server.rb @@ -264,7 +264,10 @@ def ensure_required_params(*required_params) put "/settings/:preference" do preference = params[:preference] - if preference == "displayname" + if preference == "email" + current_user.email = params[:value] + current_user.save + elsif preference == "displayname" current_user.name = params[:value] current_user.save elsif ["line_length", "default_to_side_by_side"].include? preference diff --git a/public/coffee/user_settings.coffee b/public/coffee/user_settings.coffee index 5cd52f39..4080c320 100644 --- a/public/coffee/user_settings.coffee +++ b/public/coffee/user_settings.coffee @@ -1,6 +1,7 @@ window.Settings = init: -> $("#editDisplayName").on "click", (e) => @makeTextEditable(e) + $("#editEmail").on "click", (e) => @makeTextEditable(e) $("#lineLengthSlider").slider value: parseInt($("#lineLengthSlider").attr("data-value")) min: 80 diff --git a/views/user_settings.erb b/views/user_settings.erb index 4ffd4681..e4caaf84 100644 --- a/views/user_settings.erb +++ b/views/user_settings.erb @@ -13,7 +13,15 @@ - Email<%= current_user.email %> + Login<%= current_user.login %> + + Email + + + <%= current_user.email %> + + + Gravatar