forked from External/greenlight
Merge pull request #6 from zach-chai/auth_landing
personalized rooms page
This commit is contained in:
commit
4534cf28ea
|
@ -5,3 +5,9 @@
|
||||||
// Bootstrap
|
// Bootstrap
|
||||||
@import "bootstrap-sprockets";
|
@import "bootstrap-sprockets";
|
||||||
@import "bootstrap";
|
@import "bootstrap";
|
||||||
|
|
||||||
|
.room {
|
||||||
|
.room-link {
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,4 +5,17 @@ class LandingController < ApplicationController
|
||||||
@meeting_token = params[:id] || @meeting_token = rand.to_s[2..10]
|
@meeting_token = params[:id] || @meeting_token = rand.to_s[2..10]
|
||||||
@meeting_url = meeting_url(@meeting_token)
|
@meeting_url = meeting_url(@meeting_token)
|
||||||
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
|
end
|
||||||
|
|
|
@ -2,9 +2,9 @@ class SessionsController < ApplicationController
|
||||||
def create
|
def create
|
||||||
@user = User.from_omniauth(request.env['omniauth.auth'])
|
@user = User.from_omniauth(request.env['omniauth.auth'])
|
||||||
session[:user_id] = @user.id
|
session[:user_id] = @user.id
|
||||||
|
redirect_to controller: 'landing', action: 'room', name: @user.username
|
||||||
rescue => e
|
rescue => e
|
||||||
logger.error "Error authenticating via omniauth: #{e}"
|
logger.error "Error authenticating via omniauth: #{e}"
|
||||||
ensure
|
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,13 @@ class User < ApplicationRecord
|
||||||
|
|
||||||
def self.from_omniauth(auth_hash)
|
def self.from_omniauth(auth_hash)
|
||||||
user = find_or_create_by(uid: auth_hash['uid'], provider: auth_hash['provider'])
|
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.name = auth_hash['info']['name']
|
||||||
user.save!
|
user.save!
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.twitter_username(auth_hash)
|
||||||
|
auth_hash['info']['nickname']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
<div class="page-wrapper room">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-2 col-sm-offset-10">
|
||||||
|
<% if admin? %>
|
||||||
|
<span class="user"><%= current_user.name %></span>
|
||||||
|
<%= link_to "Logout", "/logout" %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to "Login", "/auth/twitter" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-4 col-sm-offset-4">
|
||||||
|
<div class="room-link">
|
||||||
|
Room Link: <%= link_to "/rooms/#{@room_name}", "/rooms/#{@room_name}" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -4,6 +4,7 @@ Rails.application.routes.draw do
|
||||||
get 'meeting(/:id)', to: 'landing#index'
|
get 'meeting(/:id)', to: 'landing#index'
|
||||||
get '/auth/:provider/callback', to: 'sessions#create'
|
get '/auth/:provider/callback', to: 'sessions#create'
|
||||||
get '/logout', to: 'sessions#destroy'
|
get '/logout', to: 'sessions#destroy'
|
||||||
|
get '/rooms/:name', to: 'landing#room'
|
||||||
|
|
||||||
root to: 'landing#index'
|
root to: 'landing#index'
|
||||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||||
|
|
|
@ -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
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "provider", null: false
|
t.string "provider", null: false
|
||||||
|
@ -18,9 +18,11 @@ ActiveRecord::Schema.define(version: 20161017160526) do
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_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", "uid"], name: "index_users_on_provider_and_uid", unique: true
|
||||||
t.index ["provider"], name: "index_users_on_provider"
|
t.index ["provider"], name: "index_users_on_provider"
|
||||||
t.index ["uid"], name: "index_users_on_uid"
|
t.index ["uid"], name: "index_users_on_uid"
|
||||||
|
t.index ["username"], name: "index_users_on_username", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue