work on user settings

This commit is contained in:
Josh 2018-06-04 15:58:59 -04:00
parent 79949b4aa6
commit d9a95ffc18
22 changed files with 266 additions and 232 deletions

View File

@ -57,9 +57,16 @@ class RoomsController < ApplicationController
def join
opts = default_meeting_options
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

View File

@ -18,7 +18,6 @@ class SessionsController < ApplicationController
else
# Login unsuccessful, display error message.
render :new
end
end

View File

@ -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

View File

@ -1,3 +1,7 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def to_param
uid
end
end

View File

@ -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.

View File

@ -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)

View File

@ -9,7 +9,7 @@
</div>
<div class="row">
<div class="col-lg-6 col-md-8 col-sm-12 form-inline mb-5">
<div class="col-lg-6 col-md-8 col-sm-12 form-inline mb-5 align-top">
<% if @room.owner.image.nil? %>
<span class="avatar"><%= @room.owner.name.first %></span>
<% else %>
@ -34,5 +34,3 @@
</div>
</div>
</div>
<%= @room.participants %>

View File

@ -1,49 +0,0 @@
<% content_for :title do %>
<div class="title">
<h2><%= "Login" %></h2>
</div>
<% end %>
<div class="page-wrapper login">
<div class="container-fluid">
<div class="center-panel-wrapper">
<%= render layout: 'shared/center_panel' do %>
<div class="center-block center-panel-content-size col-xs-12">
<% configured_providers.each do |provider| %>
<%= link_to omniauth_login_url(provider), class: "signin-link signin-link-#{provider}" do %>
<div class="signin-button center-block">
<div class="signin-icon-wrapper">
<%= image_tag("#{provider}_logo.png", alt: "T", class: "signin-icon") %>
</div>
<div class="signin-text-wrapper text-center">
<span class="signin-text"><%= "Login with #{provider.capitalize}" %></span>
</div>
</div>
<% end %>
<% end %>
<% if allow_greenlight_users? %>
<center><p>or...<br><br></p></center>
<%= form_for(:session, url: login_path) do |f| %>
<div class="input-field col s12">
<%= f.label :email, "Email Address" %>
<%= f.text_field :email %>
</div>
<div class="input-field col s12">
<%= f.label :password %>
<%= f.password_field :password %>
</div>
<br>
<%= f.submit "Login", class: "btn white-text light-green" %>
<%= link_to "Don't have an account? Sign up!", signup_path %>
<% end %>
<% end %>
</div>
<% end %>
</div>
</div>
</div>

View File

@ -0,0 +1,3 @@
<% flash.each do |key, value| %>
<%= content_tag :div, value, class: "flash #{key} d-inline-block text-success" %>
<% end %>

View File

@ -31,7 +31,7 @@
<%= link_to current_user.main_room, class: "dropdown-item" do %>
<i class="dropdown-icon fas fa-home"></i> Home Room
<% end %>
<%= link_to settings_path, class: "dropdown-item" do %>
<%= link_to edit_user_path(current_user), class: "dropdown-item" do %>
<i class="dropdown-icon fe fe-settings"></i> Settings
<% end %>
<div class="dropdown-divider"></div>

View File

@ -15,25 +15,29 @@
<% end %>
<hr>
<%= form_for(:session, url: create_session_path) do |f| %>
<div class="form-group">
<div class="input-icon">
<span class="input-icon-addon">
<i class="fas fa-at"></i>
</span>
<input type="email" class="form-control" placeholder="Email">
<%= f.text_field :email, class: "form-control", placeholder: "Email" %>
</div>
</div>
<div class="form-group">
<div class="input-icon">
<span class="input-icon-addon">
<i class="fas fa-key"></i>
</span>
<input type="password" class="form-control" placeholder="Password">
<%= f.password_field :password, class: "form-control", placeholder: "Password" %>
</div>
</div>
<div class="form-footer">
<button type="submit" class="btn btn-outline-primary btn-block btn-pill">Login</button>
</div>
<%= f.submit "Login", class: "btn btn-outline-primary btn-block btn-pill" %>
</div>
<% end %>
</div>
</div>
</div>

View File

@ -9,7 +9,7 @@
<hr class="small-rule">
<%= form_for(User.new, url: signup_path) do |f| %>
<%= form_for(User.new) do |f| %>
<div class="form-group">
<%= f.label :name, "Full Name", class: "form-label text-left" %>
<%= f.text_field :name, class: "form-control", placeholder: "Full Name" %>

View File

@ -0,0 +1,32 @@
<%= form_for @user, url: update_user_path, method: :patch do |f| %>
<%= hidden_field_tag :setting, "account" %>
<div class="form-group">
<div class="row">
<div class="col-6">
<%= f.label "Fullname", class: "form-label" %>
<div class="input-icon">
<span class="input-icon-addon">
<i class="fas fa-user"></i>
</span>
<%= f.text_field :name, class: "form-control", value: @user.name, placeholder: "Fullname" %>
</div>
</div>
<div class="col-6">
<%= f.label "Email", class: "form-label" %>
<div class="input-icon">
<span class="input-icon-addon">
<i class="fas fa-at"></i>
</span>
<%= f.text_field :email, class: "form-control #{'is-invalid' if !@user.errors.messages[:email].empty?}", value: @user.email, placeholder: "Email" %>
</div>
</div>
</div>
<br>
<%= f.label "Provider", class: "form-label" %>
<%= f.text_field :provider, class: "form-control", value: @user.provider.capitalize, readonly: "" %>
</div>
<div class="card-footer">
<%= f.submit "Update", class: "btn btn-primary float-right" %>
</div>
<% end %>

View File

@ -0,0 +1,7 @@
<div class="form-group">
<div class="row">
<div class="col-6">
</div>
</div>
</div>

View File

@ -0,0 +1,5 @@
<div class="form-group">
<div class="row">
</div>
</div>

View File

@ -0,0 +1,20 @@
<%= form_for @user, url: update_user_path, method: :patch do |f| %>
<%= hidden_field_tag :setting, "password" %>
<div class="form-group">
<div class="row">
<div class="col-8">
<%= f.label "Old Password", class: "form-label" %>
<%= f.password_field :password, class: "form-control" %>
<br>
<%= f.label "New Password", class: "form-label" %>
<%= f.password_field :new_password, class: "form-control" %>
<br>
<%= f.label "New Password Confirmation", class: "form-label" %>
<%= f.password_field :password_confirmation, class: "form-control" %>
</div>
</div>
</div>
<div class="card-footer">
<%= f.submit "Update", class: "btn btn-primary float-right" %>
</div>
<% end %>

View File

@ -0,0 +1,10 @@
<%= content_tag(:div, id: setting_id, class: "setting-view card") do %>
<div class="card-body p-6">
<div class="card-title text-primary">
<h4><%= setting_title %></h4>
</div>
<hr>
<%= render "shared/settings/#{setting_id}" %>
</div>
<% end %>

View File

@ -0,0 +1,86 @@
<div class="container mt-8">
<%= render "shared/components/subtitle", subtitle: "Settings", search: false %>
<div class="row">
<div class="col-lg-3 mb-4">
<div class="list-group list-group-transparent mb-0">
<%= link_to edit_user_path(@user, setting: "account"), id: "account", class: "list-group-item list-group-item-action setting-btn" do %>
<span class="icon mr-3"><i class="fe fe-user"></i></span>Account
<% end %>
<%= link_to edit_user_path(@user, setting: "image"), id: "image", class: "list-group-item list-group-item-action setting-btn" do %>
<span class="icon mr-3"><i class="fe fe-image"></i></span>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 %>
<span class="icon mr-3"><i class="fe fe-lock"></i></span>Password
<% end %>
<% end %>
<%= link_to edit_user_path(@user, setting: "design"), id: "design", class: "list-group-item list-group-item-action setting-btn" do %>
<span class="icon mr-3"><i class="fe fe-edit-2"></i></span>Design
<% end %>
</div>
<% if @user.errors.any? %>
<h5 class="mt-8">Errors:</h5>
<ul>
<% @user.errors.full_messages.each do |err| %>
<li class="text-danger"><%= err %>.</li>
<% end %>
</ul>
<% end %>
<div class="mt-8">
<%= render 'shared/flash_messages' unless flash.empty? %>
</div>
</div>
<div class="col-lg-9">
<%= 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" %>
</div>
</div>
</div>
<script>
/*
// Helper for grabbing URL params.
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href);
if (results==null){
return null;
} else {
return results[1] || 0;
}
}
settingsViews = $('.setting-view');
$(document).ready(function(){
var setting = $.urlParam("setting");
/*if (!["account", "image", "password", "design"].includes(setting)){
var url = [location.protocol, '//', location.host, location.pathname].join('');
window.location.href = url + "?setting=account";
}
if (!["account", "image", "password", "design"].includes(setting)){ setting = "account"; }
$("#" + setting).addClass("active");
settingsViews.each(function(i, view){
if($(view).attr("id") != setting){
$(view).hide();
}
});
});*/
</script>

View File

@ -1,132 +0,0 @@
<div class="container mt-8">
<%= render "shared/components/subtitle", subtitle: "Settings", search: false %>
<div class="row">
<div class="col-lg-3 mb-4">
<div class="list-group list-group-transparent mb-0">
<button id="account" class="list-group-item list-group-item-action setting-btn active">
<span class="icon mr-3"><i class="fe fe-user"></i></span>Account
</button>
<button id="password" class="list-group-item list-group-item-action setting-btn">
<span class="icon mr-3"><i class="fe fe-lock"></i></span>Password
</button>
<button id="design" class="list-group-item list-group-item-action setting-btn">
<span class="icon mr-3"><i class="fe fe-edit-2"></i></span>Design
</button>
</div>
</div>
<div class="col-lg-9">
<div id="account" class="setting-view card">
<div class="card-body p-6">
<div class="card-title text-primary">
<h4>Update your Account</h4>
</div>
<hr>
<div class="form-group">
<div class="row">
<div class="col-6">
<label class="form-label">Fullname</label>
<div class="input-icon">
<span class="input-icon-addon">
<i class="fas fa-user"></i>
</span>
<input type="text" class="form-control" value="<%= current_user.name %>" placeholder="Fullname">
</div>
</div>
<div class="col-6">
<label class="form-label">Email</label>
<div class="input-icon">
<span class="input-icon-addon">
<i class="fas fa-at"></i>
</span>
<input type="email" class="form-control" value="<%= current_user.email %>" placeholder="Email">
</div>
</div>
</div>
<br>
<label class="form-label">Account Provider</label>
<input type="text" class="form-control" value="<%= current_user.provider.capitalize %>" readonly="">
<br>
<label class="form-label">Profile Image</label>
<span class="avatar avatar-xl" style="background-image: url(<%= current_user.image %>)"></span>
</div>
</div>
<div class="card-footer">
<a href="#" class="btn btn-primary float-right">Update</a>
</div>
</div>
<div id="password" class="setting-view card">
<div class="card-body p-6">
<div class="card-title text-primary">
<h4>Change your Password</h4>
</div>
<hr>
<div class="form-group">
<div class="row">
<div class="col-8">
<label class="form-label">Old Password</label>
<input type="password" class="form-control">
<br>
<label class="form-label">New Password</label>
<input type="password" class="form-control">
<br>
<label class="form-label">New Password Confirmation</label>
<input type="password" class="form-control">
</div>
</div>
</div>
</div>
<div class="card-footer">
<a href="#" class="btn btn-primary float-right">Update</a>
</div>
</div>
<div id="design" class="setting-view card">
<div class="card-body p-6">
<div class="card-title text-primary">
<h4>Customize Greenlight</h4>
</div>
<hr>
<div class="form-group">
<div class="row">
<div class="col-6">
</div>
</div>
</div>
</div>
<div class="card-footer">
<a href="#" class="btn btn-primary float-right">Update</a>
</div>
</div>
</div>
</div>
</div>
<script>
settingsButtons = $('.setting-btn');
settingsViews = $('.setting-view');
$(document).ready(function(){
settingsButtons.each(function(i, btn) {
if(i != 0){ $(settingsViews[i]).hide(); }
$(btn).click(function(){
$(btn).addClass("active");
settingsViews.each(function(i, view){
if($(view).attr("id") == $(btn).attr("id")){
$(view).show();
} else {
$(settingsButtons[i]).removeClass("active");
$(view).hide();
}
});
});
});
});
</script>

View File

@ -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'

View File

@ -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 }

View File

@ -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