diff --git a/app/assets/stylesheets/landing.scss b/app/assets/stylesheets/landing.scss index 0dbe3ca0..3bcfc498 100644 --- a/app/assets/stylesheets/landing.scss +++ b/app/assets/stylesheets/landing.scss @@ -5,3 +5,9 @@ // Bootstrap @import "bootstrap-sprockets"; @import "bootstrap"; + +.room { + .room-link { + margin: 0 auto; + } +} diff --git a/app/controllers/landing_controller.rb b/app/controllers/landing_controller.rb index 166895a8..0c6c9e5e 100644 --- a/app/controllers/landing_controller.rb +++ b/app/controllers/landing_controller.rb @@ -16,4 +16,16 @@ class LandingController < ApplicationController end end + def room + @room_name = params[:name] + @user = User.find_by(username: @room_name) + if @user.nil? + redirect_to root_path + end + end + + def admin? + @user == current_user + end + helper_method :admin? end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index e2ab24aa..83820889 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -2,9 +2,9 @@ class SessionsController < ApplicationController def create @user = User.from_omniauth(request.env['omniauth.auth']) session[:user_id] = @user.id + redirect_to controller: 'landing', action: 'room', name: @user.username rescue => e logger.error "Error authenticating via omniauth: #{e}" - ensure redirect_to root_path end diff --git a/app/models/user.rb b/app/models/user.rb index 80c35a02..487fdcbc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,8 +2,17 @@ class User < ApplicationRecord def self.from_omniauth(auth_hash) user = find_or_create_by(uid: auth_hash['uid'], provider: auth_hash['provider']) + user.username = self.send("#{auth_hash['provider']}_username", auth_hash) rescue nil user.name = auth_hash['info']['name'] user.save! user end + + def self.twitter_username(auth_hash) + auth_hash['info']['nickname'] + end + + def room_url + "/rooms/#{username}" + end end diff --git a/app/views/landing/index.html.erb b/app/views/landing/index.html.erb index 444cf1f5..f5765617 100644 --- a/app/views/landing/index.html.erb +++ b/app/views/landing/index.html.erb @@ -45,21 +45,21 @@
- + - + - -<% if current_user.nil? %> -