forked from External/greenlight
Merge pull request #222 from bruckwubete/bn_launcher_integration
Bn launcher integration
This commit is contained in:
@ -22,4 +22,23 @@ module SessionsHelper
|
||||
def current_user
|
||||
@current_user ||= User.find_by(id: session[:user_id])
|
||||
end
|
||||
|
||||
def generate_checksum(customer_name, redirect_url, secret)
|
||||
string = customer_name + redirect_url + secret
|
||||
OpenSSL::Digest.digest('sha1', string).unpack("H*").first
|
||||
end
|
||||
|
||||
def parse_customer_name(hostname)
|
||||
provider = hostname.split('.')
|
||||
provider.first == 'www' ? provider.second : provider.first
|
||||
end
|
||||
|
||||
def omniauth_options(env)
|
||||
gl_redirect_url = env["rack.url_scheme"] + "://" + env["SERVER_NAME"] + ":" + env["SERVER_PORT"]
|
||||
env['omniauth.strategy'].options[:customer] = parse_customer_name env["SERVER_NAME"]
|
||||
env['omniauth.strategy'].options[:gl_redirect_url] = gl_redirect_url
|
||||
env['omniauth.strategy'].options[:default_callback_url] = Rails.configuration.gl_callback_url
|
||||
env['omniauth.strategy'].options[:checksum] = generate_checksum parse_customer_name(env["SERVER_NAME"]),
|
||||
gl_redirect_url, Rails.configuration.launcher_secret
|
||||
end
|
||||
end
|
||||
|
@ -22,7 +22,9 @@ class User < ApplicationRecord
|
||||
class << self
|
||||
# Generates a user from omniauth.
|
||||
def from_omniauth(auth)
|
||||
find_or_initialize_by(social_uid: auth['uid'], provider: auth['provider']).tap do |u|
|
||||
# Provider is the customer name if in loadbalanced config mode
|
||||
provider = auth['provider'] == "bn_launcher" ? auth['info']['customer'] : auth['provider']
|
||||
find_or_initialize_by(social_uid: auth['uid'], provider: provider).tap do |u|
|
||||
u.name = send("#{auth['provider']}_name", auth) unless u.name
|
||||
u.username = send("#{auth['provider']}_username", auth) unless u.username
|
||||
u.email = send("#{auth['provider']}_email", auth)
|
||||
@ -65,6 +67,22 @@ class User < ApplicationRecord
|
||||
def google_image(auth)
|
||||
auth['info']['image']
|
||||
end
|
||||
|
||||
def bn_launcher_name(auth)
|
||||
auth['info']['name']
|
||||
end
|
||||
|
||||
def bn_launcher_username(auth)
|
||||
auth['info']['username']
|
||||
end
|
||||
|
||||
def bn_launcher_email(auth)
|
||||
auth['info']['email']
|
||||
end
|
||||
|
||||
def bn_launcher_image(auth)
|
||||
auth['info']['image']
|
||||
end
|
||||
end
|
||||
|
||||
# Retrives a list of all a users rooms that are not the main room, sorted by last session date.
|
||||
|
@ -44,7 +44,11 @@
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<%= link_to "Login", "#loginModal", :class => "btn btn-pill btn-outline-primary mx-2", "data-toggle": "modal" %>
|
||||
<% if Rails.configuration.omniauth_bn_launcher && !current_user %>
|
||||
<%= link_to "Login", "#{Rails.configuration.relative_url_root}/auth/bn_launcher", :class => "btn btn-pill btn-outline-primary mx-2" %>
|
||||
<% else %>
|
||||
<%= link_to "Login", "#loginModal", :class => "btn btn-pill btn-outline-primary mx-2", "data-toggle": "modal" %>
|
||||
<% end %>
|
||||
|
||||
<% if allow_user_signup? %>
|
||||
<%= link_to "Signup", signup_path, :class => "btn btn-pill btn-outline-primary mx-2" %>
|
||||
|
Reference in New Issue
Block a user