Skip to content

Commit

Permalink
added name to user models
Browse files Browse the repository at this point in the history
  • Loading branch information
raymzag committed Jun 1, 2017
1 parent e732fbb commit 6dbca04
Show file tree
Hide file tree
Showing 23 changed files with 261 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/channels/customer_support_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def unsubscribed
end

def send_message(data)
MessageBroadcastJob.perform_later(data['message'], data['email'])
MessageBroadcastJob.perform_later(data['message'], data['name'])
# current_user.messages.create!(body: data['message'], chat_room_id: data['chat_room_id'])
end
end
8 changes: 7 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?

private
protected
def after_sign_in_path_for(resource)
chat_bot_path
end

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
devise_parameter_sanitizer.permit(:account_update, keys: [:name])
end
end
8 changes: 4 additions & 4 deletions app/jobs/message_broadcast_job.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class MessageBroadcastJob < ApplicationJob
queue_as :default

def perform(message, email)
def perform(message, name)
# ActionCable.server.broadcast "chat_rooms_#{message.chat_room.id}_channel",
ActionCable.server.broadcast "customer_support_channel",
message: render_message(message, email)
message: render_message(message, name)
end

private

def render_message(message, email)
MessagesController.render partial: 'messages/message', locals: {message: message, email: email}
def render_message(message, name)
MessagesController.render partial: 'messages/message', locals: {message: message, name: name}
end
end
2 changes: 1 addition & 1 deletion app/views/messages/_message.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- </div> -->
<div class="col-md-12">
<p class="card-text">
<span class="text-muted"><strong><%= email %></strong> at <strong><%= Time.now.strftime('%d %B %Y %H:%M:%S') %></strong> says</span><br>
<span class="text-muted"><strong><%= name %></strong> at <strong><%= Time.now.strftime('%d %B %Y %H:%M:%S') %></strong> says</span><br>
<%= message %>
</p>
</div>
Expand Down
16 changes: 16 additions & 0 deletions app/views/users/confirmations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h2>Resend confirmation instructions</h2>

<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>

<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
</div>

<div class="actions">
<%= f.submit "Resend confirmation instructions" %>
</div>
<% end %>

<%= render "users/shared/links" %>
5 changes: 5 additions & 0 deletions app/views/users/mailer/confirmation_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>Welcome <%= @email %>!</p>

<p>You can confirm your account email through the link below:</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
7 changes: 7 additions & 0 deletions app/views/users/mailer/email_changed.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>Hello <%= @email %>!</p>

<% if @resource.try(:unconfirmed_email?) %>
<p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p>
<% else %>
<p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p>
<% end %>
3 changes: 3 additions & 0 deletions app/views/users/mailer/password_change.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>Hello <%= @resource.email %>!</p>

<p>We're contacting you to notify you that your password has been changed.</p>
8 changes: 8 additions & 0 deletions app/views/users/mailer/reset_password_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>Hello <%= @resource.email %>!</p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>

<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
7 changes: 7 additions & 0 deletions app/views/users/mailer/unlock_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>Hello <%= @resource.email %>!</p>

<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>

<p>Click the link below to unlock your account:</p>

<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
25 changes: 25 additions & 0 deletions app/views/users/passwords/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h2>Change your password</h2>

<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>

<div class="field">
<%= f.label :password, "New password" %><br />
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em><br />
<% end %>
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
</div>

<div class="field">
<%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>

<div class="actions">
<%= f.submit "Change my password" %>
</div>
<% end %>

<%= render "users/shared/links" %>
16 changes: 16 additions & 0 deletions app/views/users/passwords/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h2>Forgot your password?</h2>

<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>

<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>

<div class="actions">
<%= f.submit "Send me reset password instructions" %>
</div>
<% end %>

<%= render "users/shared/links" %>
48 changes: 48 additions & 0 deletions app/views/users/registrations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>

<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name, autofocus: true %>
</div>

<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>

<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>

<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
<% if @minimum_password_length %>
<br />
<em><%= @minimum_password_length %> characters minimum</em>
<% end %>
</div>

<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>

<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
</div>

<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>

<h3>Cancel my account</h3>

<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>

<%= link_to "Back", :back %>
34 changes: 34 additions & 0 deletions app/views/users/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<h2>Sign up</h2>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>

<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name, autofocus: true %>
</div>

<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>

<div class="field">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>

<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>

<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>

<%= render "users/shared/links" %>
26 changes: 26 additions & 0 deletions app/views/users/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h2>Log in</h2>

<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>

<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>

<% if devise_mapping.rememberable? -%>
<div class="field">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end -%>

<div class="actions">
<%= f.submit "Log in" %>
</div>
<% end %>

<%= render "users/shared/links" %>
25 changes: 25 additions & 0 deletions app/views/users/shared/_links.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%- if controller_name != 'sessions' %>
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end -%>

<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>

<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>

<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>

<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>

<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>
16 changes: 16 additions & 0 deletions app/views/users/unlocks/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h2>Resend unlock instructions</h2>

<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>

<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>

<div class="actions">
<%= f.submit "Resend unlock instructions" %>
</div>
<% end %>

<%= render "users/shared/links" %>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class CustomerServiceChat extends React.Component {
if($('#messages').length > 0) {
var messages_to_bottom;
let handleNewChat = this.handleNewChat.bind(this)
let email = this.props.current_user.email
let name = this.props.current_user.name

messages_to_bottom = function() {
return messages.scrollTop(messages.prop("scrollHeight"));
Expand Down Expand Up @@ -57,7 +57,7 @@ export default class CustomerServiceChat extends React.Component {
send_message: function(message) {
this.perform('send_message', {
'message': message,
'email': email,
'name': name,
})
},
});
Expand Down
1 change: 1 addition & 0 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
# "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views.
# config.scoped_views = false
config.scoped_views = true # devise custom view by raymond

# Configure the default scope given to Warden. By default it's the first
# devise role declared in your routes (usually :user).
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170601123351_add_name_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNameToUsers < ActiveRecord::Migration[5.1]
def change
add_column :users, :name, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170531012950) do
ActiveRecord::Schema.define(version: 20170601123351) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -34,6 +34,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "admin", default: false
t.string "name"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 6dbca04

Please sign in to comment.