Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support different email for signin #447

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions barkeep_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions migrations/20130521220244_add_login_column_to_users.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions public/coffee/user_settings.coffee
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 9 additions & 1 deletion views/user_settings.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
</span>
</td>
</tr>
<tr><td>Email</td><td><%= current_user.email %></td></tr>
<tr><td>Login</td><td><%= current_user.login %></td></tr>
<tr>
<td>Email</td>
<td>
<span id="editEmail" class="editable west" rel="tipsy" title="Edit">
<%= current_user.email %>
</span>
</td>
</tr>
<tr>
<td>Gravatar</td>
<td>
Expand Down