diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb
index 8714b9a6..9d9e2b33 100644
--- a/app/controllers/rooms_controller.rb
+++ b/app/controllers/rooms_controller.rb
@@ -57,9 +57,16 @@ class RoomsController < ApplicationController
def join
opts = default_meeting_options
- # If you're unauthenticated, you must enter a name to join the meeting.
- if params[@room.invite_path][:join_name]
- redirect_to @room.join_path(params[@room.invite_path][:join_name], opts)
+ if @room.is_running?
+ # If you're unauthenticated, you must enter a name to join the meeting.
+ if params[@room.invite_path][:join_name]
+ redirect_to @room.join_path(params[@room.invite_path][:join_name], opts)
+ else
+ redirect_to @room.join_path(current_user, opts)
+ end
+ else
+ # They need to wait until the meeting begins.
+
end
end
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index ecf32d56..ecbcdfd3 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -18,7 +18,6 @@ class SessionsController < ApplicationController
else
# Login unsuccessful, display error message.
- render :new
end
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 64ee6d8b..a7fd0af2 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,11 +1,8 @@
class UsersController < ApplicationController
- # GET /signup
- def new
- @user = User.new
- end
+ before_action :find_user, only: [:edit, :update]
- # POST /signup
+ # POST /users
def create
user = User.new(user_params)
user.provider = "greenlight"
@@ -13,18 +10,61 @@ class UsersController < ApplicationController
if user.save
login(user)
else
+ # Handle error on user creation.
end
end
- # GET /settings
- def settings
- redirect_to root_path unless current_user
+ # GET /users/:user_uid/edit
+ def edit
+ if current_user
+ redirect_to current_user.room unless @user == current_user
+ else
+ redirect_to root_path
+ end
end
+ # PATCH /users/:user_uid
+ def update
+ # Update account information if passed.
+ @user.name = user_params[:name] if user_params[:name]
+ @user.email = user_params[:email] if user_params[:email]
+
+ # Verify that the provided password is correct.
+ if user_params[:password] && @user.authenticate(user_params[:password])
+ # Verify that the new passwords match.
+ if user_params[:new_password] == user_params[:password_confirmation]
+ @user.password = user_params[:new_password]
+ else
+ # New passwords don't match.
+
+ end
+ else
+ # Original password is incorrect, can't update.
+
+ end
+
+ if @user.save
+ # Notify the use that their account has been updated.
+ redirect_to edit_user_path(@user), notice: "Information successfully updated."
+ else
+ # Handle validation errors.
+ render :edit
+ end
+ end
+
private
+ def find_user
+ @user = User.find_by(uid: params[:user_uid])
+
+ unless @user
+ # Handle user does not exist.
+
+ end
+ end
+
def user_params
- params.require(:user).permit(:name, :email, :password, :password_confirmation)
+ params.require(:user).permit(:name, :email, :password, :password_confirmation, :new_password, :provider)
end
end
diff --git a/app/models/application_record.rb b/app/models/application_record.rb
index 10a4cba8..e0f5f7bb 100644
--- a/app/models/application_record.rb
+++ b/app/models/application_record.rb
@@ -1,3 +1,7 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
+
+ def to_param
+ uid
+ end
end
diff --git a/app/models/room.rb b/app/models/room.rb
index ccc137a3..a4ba46de 100644
--- a/app/models/room.rb
+++ b/app/models/room.rb
@@ -10,10 +10,6 @@ class Room < ApplicationRecord
ROOM_ICONS = %w(circle star certificate play cloud heart square bookmark cog)
RETURNCODE_SUCCESS = "SUCCESS"
- def to_param
- uid
- end
-
# Determines if a user owns a room.
def owned_by?(user)
return false if user.nil?
@@ -72,8 +68,6 @@ class Room < ApplicationRecord
# Returns a URL to join a user into a meeting.
def join_path(user, options = {})
- username = user.name if user.is_a?(User)
-
# Create the meeting if it isn't running.
start_session(options) unless is_running?
@@ -100,7 +94,11 @@ class Room < ApplicationRecord
end
# Generate the join URL.
- bbb.join_meeting_url(bbb_id, username, password, {userID: user.uid})
+ if user.is_a?(User)
+ bbb.join_meeting_url(bbb_id, user.name, password, {userID: user.uid})
+ else
+ bbb.join_meeting_url(bbb_id, user, password)
+ end
end
# Fetches all recordings for a meeting.
diff --git a/app/models/user.rb b/app/models/user.rb
index 6c7f0ab1..ac1af10b 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -22,7 +22,11 @@ class User < ApplicationRecord
# Generates a user from omniauth.
def from_omniauth(auth)
- user = find_or_initialize_by(uid: auth['uid'], provider: auth['provider'])
+ user = find_or_initialize_by(
+ social_uid: auth['uid'],
+ provider: auth['provider']
+ )
+
user.name = send("#{auth['provider']}_name", auth)
user.username = send("#{auth['provider']}_username", auth)
user.email = send("#{auth['provider']}_email", auth)
diff --git a/app/views/rooms/join.html.erb b/app/views/rooms/join.html.erb
index e60a7681..e95e9f3c 100644
--- a/app/views/rooms/join.html.erb
+++ b/app/views/rooms/join.html.erb
@@ -9,7 +9,7 @@
-
-<%= @room.participants %>
diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb
deleted file mode 100644
index 8bc7afb1..00000000
--- a/app/views/sessions/new.html.erb
+++ /dev/null
@@ -1,49 +0,0 @@
-<% content_for :title do %>
-
-
<%= "Login" %>
-
-<% end %>
-
-
-
-
-
- <%= render layout: 'shared/center_panel' do %>
-
-
- <% configured_providers.each do |provider| %>
- <%= link_to omniauth_login_url(provider), class: "signin-link signin-link-#{provider}" do %>
-
- <% end %>
- <% end %>
-
- <% if allow_greenlight_users? %>
-
or...
-
- <%= form_for(:session, url: login_path) do |f| %>
-
- <%= f.label :email, "Email Address" %>
- <%= f.text_field :email %>
-
-
- <%= f.label :password %>
- <%= f.password_field :password %>
-
-
- <%= f.submit "Login", class: "btn white-text light-green" %>
- <%= link_to "Don't have an account? Sign up!", signup_path %>
- <% end %>
- <% end %>
-
- <% end %>
-
-
-
-
\ No newline at end of file
diff --git a/app/views/shared/_flash_messages.html.erb b/app/views/shared/_flash_messages.html.erb
new file mode 100644
index 00000000..dd0978d9
--- /dev/null
+++ b/app/views/shared/_flash_messages.html.erb
@@ -0,0 +1,3 @@
+<% flash.each do |key, value| %>
+ <%= content_tag :div, value, class: "flash #{key} d-inline-block text-success" %>
+<% end %>
diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb
index 207fb0b3..51394ecf 100644
--- a/app/views/shared/_header.html.erb
+++ b/app/views/shared/_header.html.erb
@@ -31,7 +31,7 @@
<%= link_to current_user.main_room, class: "dropdown-item" do %>
Home Room
<% end %>
- <%= link_to settings_path, class: "dropdown-item" do %>
+ <%= link_to edit_user_path(current_user), class: "dropdown-item" do %>
Settings
<% end %>
diff --git a/app/views/shared/modals/_login_modal.html.erb b/app/views/shared/modals/_login_modal.html.erb
index cd9ae0f8..9742f926 100644
--- a/app/views/shared/modals/_login_modal.html.erb
+++ b/app/views/shared/modals/_login_modal.html.erb
@@ -15,25 +15,29 @@
<% end %>
-
diff --git a/app/views/shared/modals/_signup_modal.html.erb b/app/views/shared/modals/_signup_modal.html.erb
index c851ca20..d0f95de9 100644
--- a/app/views/shared/modals/_signup_modal.html.erb
+++ b/app/views/shared/modals/_signup_modal.html.erb
@@ -9,7 +9,7 @@
- <%= form_for(User.new, url: signup_path) do |f| %>
+ <%= form_for(User.new) do |f| %>
<%= f.label :name, "Full Name", class: "form-label text-left" %>
<%= f.text_field :name, class: "form-control", placeholder: "Full Name" %>
diff --git a/app/views/shared/settings/_account.html.erb b/app/views/shared/settings/_account.html.erb
new file mode 100644
index 00000000..06be4f28
--- /dev/null
+++ b/app/views/shared/settings/_account.html.erb
@@ -0,0 +1,32 @@
+<%= form_for @user, url: update_user_path, method: :patch do |f| %>
+ <%= hidden_field_tag :setting, "account" %>
+
+
+<% end %>
diff --git a/app/views/shared/settings/_design.html.erb b/app/views/shared/settings/_design.html.erb
new file mode 100644
index 00000000..360a4fa8
--- /dev/null
+++ b/app/views/shared/settings/_design.html.erb
@@ -0,0 +1,7 @@
+
diff --git a/app/views/shared/settings/_image.html.erb b/app/views/shared/settings/_image.html.erb
new file mode 100644
index 00000000..cef0b0ed
--- /dev/null
+++ b/app/views/shared/settings/_image.html.erb
@@ -0,0 +1,5 @@
+
diff --git a/app/views/shared/settings/_password.html.erb b/app/views/shared/settings/_password.html.erb
new file mode 100644
index 00000000..68b9d3b8
--- /dev/null
+++ b/app/views/shared/settings/_password.html.erb
@@ -0,0 +1,20 @@
+<%= form_for @user, url: update_user_path, method: :patch do |f| %>
+ <%= hidden_field_tag :setting, "password" %>
+
+
+<% end %>
diff --git a/app/views/shared/settings/_setting_view.html.erb b/app/views/shared/settings/_setting_view.html.erb
new file mode 100644
index 00000000..a1c185af
--- /dev/null
+++ b/app/views/shared/settings/_setting_view.html.erb
@@ -0,0 +1,10 @@
+<%= content_tag(:div, id: setting_id, class: "setting-view card") do %>
+
+
+
<%= setting_title %>
+
+
+
+ <%= render "shared/settings/#{setting_id}" %>
+
+<% end %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb
new file mode 100644
index 00000000..f843c157
--- /dev/null
+++ b/app/views/users/edit.html.erb
@@ -0,0 +1,86 @@
+
+
+ <%= render "shared/components/subtitle", subtitle: "Settings", search: false %>
+
+
+
+
+ <%= link_to edit_user_path(@user, setting: "account"), id: "account", class: "list-group-item list-group-item-action setting-btn" do %>
+ Account
+ <% end %>
+
+ <%= link_to edit_user_path(@user, setting: "image"), id: "image", class: "list-group-item list-group-item-action setting-btn" do %>
+ Profile Image
+ <% end %>
+
+ <% if @user.social_uid.nil? %>
+ <%= link_to edit_user_path(@user, setting: "password"), id: "password", class: "list-group-item list-group-item-action setting-btn" do %>
+ Password
+ <% end %>
+ <% end %>
+
+ <%= link_to edit_user_path(@user, setting: "design"), id: "design", class: "list-group-item list-group-item-action setting-btn" do %>
+ Design
+ <% end %>
+
+
+ <% if @user.errors.any? %>
+
Errors:
+
+ <% @user.errors.full_messages.each do |err| %>
+ - <%= err %>.
+ <% end %>
+
+ <% end %>
+
+
+ <%= render 'shared/flash_messages' unless flash.empty? %>
+
+
+
+
+
+ <%= render "shared/settings/setting_view", setting_id: "account", setting_title: "Update your Account Info" %>
+ <%= render "shared/settings/setting_view", setting_id: "image", setting_title: "Change your Profile Image" %>
+
+ <% if @user.social_uid.nil? %>
+ <%= render "shared/settings/setting_view", setting_id: "password", setting_title: "Change your Password" %>
+ <% end %>
+
+ <%= render "shared/settings/setting_view", setting_id: "design", setting_title: "Customize GreenLight" %>
+
+
+
+
+
diff --git a/app/views/users/settings.html.erb b/app/views/users/settings.html.erb
deleted file mode 100644
index a0f3a2dc..00000000
--- a/app/views/users/settings.html.erb
+++ /dev/null
@@ -1,132 +0,0 @@
-
-
- <%= render "shared/components/subtitle", subtitle: "Settings", search: false %>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Update your Account
-
-
-
-
-
-
-
-
-
-
-
Change your Password
-
-
-
-
-
-
-
-
-
-
-
Customize Greenlight
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/config/routes.rb b/config/routes.rb
index 364e2476..ecdd54ff 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -19,18 +19,14 @@ Rails.application.routes.draw do
end
end
- # Signup route.
- post '/signup', to: 'users#create'
-
- # User settings.
- get '/settings', to: 'users#settings'
+ # User resources.
+ #resources :users, only: [:create, :update, :edit], param: :user_uid
+ get '/users/:user_uid/edit', to: 'users#edit', as: :edit_user
+ patch '/users/:user_uid/edit', to: 'users#update', as: :update_user
# Handles login of greenlight provider accounts.
post '/login', to: 'sessions#create', as: :create_session
- # Login to Greenlight.
- get '/login', to: 'sessions#new'
-
# Log the user out of the session.
get '/logout', to: 'sessions#destroy'
diff --git a/db/migrate/20180504131648_create_users.rb b/db/migrate/20180504131648_create_users.rb
index e7d4da27..9d90185b 100644
--- a/db/migrate/20180504131648_create_users.rb
+++ b/db/migrate/20180504131648_create_users.rb
@@ -7,6 +7,7 @@ class CreateUsers < ActiveRecord::Migration[5.0]
t.string :name
t.string :username
t.string :email
+ t.string :social_uid
t.string :image
t.string :password_digest, index: { unique: true }
diff --git a/db/schema.rb b/db/schema.rb
index 0aaa3e79..520062d4 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -36,6 +36,7 @@ ActiveRecord::Schema.define(version: 20180504131705) do
t.string "name"
t.string "username"
t.string "email"
+ t.string "social_uid"
t.string "image"
t.string "password_digest"
t.datetime "created_at", null: false