Skip to content

Commit

Permalink
Make default_name/default_email configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Oct 3, 2012
1 parent 085d285 commit d894e80
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/omnigollum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ class User
end

class OmniauthUser < User
def initialize (hash)
def initialize (hash, options)
# Validity checks, don't trust providers
@uid = hash['uid'].to_s.strip
raise OmniauthUserInitError, "Insufficient data from authentication provider, uid not provided or empty" if @uid.empty?

@name = hash['info']['name'].to_s.strip if hash['info'].has_key?('name')

@name = hash['info']['name'].to_s.strip if hash['info'].has_key?('name')
@name = options[:default_name] if @name.empty?

raise OmniauthUserInitError, "Insufficient data from authentication provider, name not provided or empty" if !@name || @name.empty?

@email = hash['info']['email'].to_s.strip if hash['info'].has_key?('email')
@email = hash['info']['email'].to_s.strip if hash['info'].has_key?('email')
@email = options[:default_email] if @email.empty?

raise OmniauthUserInitError, "Insufficient data from authentication provider, email not provided or empty" if !@email || @email.empty?

@nickname = hash['info']['nickname'].to_s.strip if hash['info'].has_key?('nickname')
Expand Down Expand Up @@ -119,6 +123,8 @@ class << self; attr_accessor :default_options; end
:path_images => "#{dir}/public/images",
:path_views => "#{dir}/views",
:path_templates => "#{dir}/templates",
:default_name => nil,
:default_email => nil,
:provider_names => []
}

Expand Down Expand Up @@ -224,14 +230,14 @@ def self.registered(app)
app.before options[:route_prefix] + '/auth/:name/callback' do
begin
if !request.env['omniauth.auth'].nil?
user = Omnigollum::Models::OmniauthUser.new(request.env['omniauth.auth'])
user = Omnigollum::Models::OmniauthUser.new(request.env['omniauth.auth'], options)
session[:omniauth_user] = user

# Update gollum's author hash, so commits are recorded correctly
session['gollum.author'] = {
:name => user.nickname ?
user.name + ' (' + user.nickname + ')' :
user.name,
user.name + ' (' + user.nickname + ')' :
user.name,
:email => user.email
}

Expand Down

0 comments on commit d894e80

Please sign in to comment.