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? %> - -<% else %> -
Hello <%= current_user.name %>
-<%= link_to 'Logout', '/logout' %> -<% end %> diff --git a/app/views/landing/room.html.erb b/app/views/landing/room.html.erb new file mode 100644 index 00000000..fc853c47 --- /dev/null +++ b/app/views/landing/room.html.erb @@ -0,0 +1,19 @@ +
+
+
+ <% if admin? %> + <%= current_user.name %> + <%= link_to "Logout", "/logout" %> + <% else %> + <%= link_to "Login", "/auth/twitter" %> + <% end %> +
+
+
+
+ +
+
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b6a5eddc..167c983b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -16,10 +16,10 @@ - + <%= yield %> diff --git a/config/routes.rb b/config/routes.rb index 804d4b87..87890b25 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ Rails.application.routes.draw do get '/meeting(/:id)', to: 'landing#index', as: :landing, :resource => "meeting" get '/auth/:provider/callback', to: 'sessions#create' get '/logout', to: 'sessions#destroy' + get '/rooms/:name', to: 'landing#room' root to: 'landing#index', :resource => "meeting" # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html diff --git a/db/migrate/20161017203809_add_username_to_user.rb b/db/migrate/20161017203809_add_username_to_user.rb new file mode 100644 index 00000000..58cde222 --- /dev/null +++ b/db/migrate/20161017203809_add_username_to_user.rb @@ -0,0 +1,6 @@ +class AddUsernameToUser < ActiveRecord::Migration[5.0] + def change + add_column :users, :username, :string + add_index :users, :username, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 1834e3e8..9d2bd52c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161017160526) do +ActiveRecord::Schema.define(version: 20161017203809) do create_table "users", force: :cascade do |t| t.string "provider", null: false @@ -18,9 +18,11 @@ ActiveRecord::Schema.define(version: 20161017160526) do t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "username" t.index ["provider", "uid"], name: "index_users_on_provider_and_uid", unique: true t.index ["provider"], name: "index_users_on_provider" t.index ["uid"], name: "index_users_on_uid" + t.index ["username"], name: "index_users_on_username", unique: true end end diff --git a/test/controllers/bbb_controller_test.rb b/test/controllers/bbb_controller_test.rb index 4c017be1..ff2d0c19 100644 --- a/test/controllers/bbb_controller_test.rb +++ b/test/controllers/bbb_controller_test.rb @@ -1,14 +1,13 @@ require 'test_helper' -class BbbControllerTest < ActionDispatch::IntegrationTest - test "should get join" do - get bbb_join_url - assert_response :success - end - - test "should get end" do - get bbb_end_url - assert_response :success - end - +class BbbControllerTest < ActionController::TestCase + # test "should get join" do + # get :join + # assert_response :success + # end + # + # test "should get end" do + # get :close + # assert_response :success + # end end diff --git a/test/controllers/landing_controller_test.rb b/test/controllers/landing_controller_test.rb index ee1801da..09f0ec6f 100644 --- a/test/controllers/landing_controller_test.rb +++ b/test/controllers/landing_controller_test.rb @@ -1,8 +1,13 @@ require 'test_helper' -class LandingControllerTest < ActionDispatch::IntegrationTest +class LandingControllerTest < ActionController::TestCase test "should get index" do - get landing_index_url + get :index + assert_response :success + end + + test "should get room" do + get :room, params: { name: 'user1' } assert_response :success end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 2f72a665..c105d045 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,11 +1,13 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - provider: MyString - uid: MyString - name: MyString + provider: Twitter + uid: <%= SecureRandom.hex(10) %> + name: User 1 + username: user1 two: - provider: MyString - uid: MyString - name: MyString + provider: TWitter + uid: <%= SecureRandom.hex(10) %> + name: User 2 + username: user2