Skip to content

Commit d7329f8

Browse files
committed
added devise and cleaned up the ui a bit
1 parent 6629b2d commit d7329f8

27 files changed

+644
-28
lines changed

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ end
4545
# gem 'debugger', group: [:development, :test]
4646
gem 'twitter-bootstrap-rails'
4747
gem 'haml-rails'
48-
gem 'websocket-rails', github: 'moaa/websocket-rails'
48+
gem 'websocket-rails', path: '/home/rory85/repos/websocket-rails'
49+
gem 'devise'
4950

Gemfile.lock

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
GIT
2-
remote: git://github.com/moaa/websocket-rails.git
3-
revision: a091e4cba97e4143f9fe4309b3b182c7a508d7c8
1+
PATH
2+
remote: /home/rory85/repos/websocket-rails
43
specs:
5-
websocket-rails (0.4.9)
4+
websocket-rails (0.6.1)
65
em-synchrony
76
faye-websocket
87
hiredis
@@ -40,6 +39,7 @@ GEM
4039
tzinfo (~> 0.3.37)
4140
arel (4.0.0)
4241
atomic (1.1.13)
42+
bcrypt-ruby (3.1.2)
4343
builder (3.1.4)
4444
coffee-rails (4.0.0)
4545
coffee-script (>= 2.2.0)
@@ -49,6 +49,12 @@ GEM
4949
execjs
5050
coffee-script-source (1.6.3)
5151
daemons (1.1.9)
52+
devise (3.1.0)
53+
bcrypt-ruby (~> 3.0)
54+
orm_adapter (~> 0.1)
55+
railties (>= 3.2.6, < 5)
56+
thread_safe (~> 0.1)
57+
warden (~> 1.2.3)
5258
em-synchrony (1.0.3)
5359
eventmachine (>= 1.0.0.beta.1)
5460
erubis (2.7.0)
@@ -81,6 +87,7 @@ GEM
8187
mime-types (1.24)
8288
minitest (4.7.5)
8389
multi_json (1.7.9)
90+
orm_adapter (0.4.0)
8491
polyglot (0.3.3)
8592
rack (1.5.2)
8693
rack-test (0.6.2)
@@ -146,13 +153,16 @@ GEM
146153
uglifier (2.1.2)
147154
execjs (>= 0.3.0)
148155
multi_json (~> 1.0, >= 1.0.2)
156+
warden (1.2.3)
157+
rack (>= 1.0)
149158
websocket-driver (0.2.3)
150159

151160
PLATFORMS
152161
ruby
153162

154163
DEPENDENCIES
155164
coffee-rails (~> 4.0.0)
165+
devise
156166
haml-rails
157167
jbuilder (~> 1.2)
158168
jquery-rails

app/controllers/application_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ class ApplicationController < ActionController::Base
22
# Prevent CSRF attacks by raising an exception.
33
# For APIs, you may want to use :null_session instead.
44
protect_from_forgery with: :exception
5+
before_filter :authenticate_user!
56
end

app/controllers/chat_controller.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
class ChatController < WebsocketRails::BaseController
22

33
def user_connected
4-
4+
p 'user connected'
55
end
66

77
def incoming_message
88
screen_name = connection_store[:screen_name]
9-
broadcast_message :new_message, {:user => screen_name, :text => message[:text]}
9+
broadcast_message :new_message, {:user => current_user.screen_name, :text => message[:text]}
1010
end
1111

12-
def set_name
13-
connection_store[:screen_name] = message[:name]
12+
def user_disconnected
13+
p 'user disconnected'
1414
end
1515
end

app/models/user.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class User < ActiveRecord::Base
2+
# Include default devise modules. Others available are:
3+
# :confirmable, :lockable, :timeoutable and :omniauthable
4+
devise :database_authenticatable, :registerable,
5+
:rememberable, :trackable
6+
7+
8+
def screen_name
9+
email.split('@').first
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h2>Resend confirmation instructions</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
4+
<%= devise_error_messages! %>
5+
6+
<div><%= f.label :email %><br />
7+
<%= f.email_field :email, :autofocus => true %></div>
8+
9+
<div><%= f.submit "Resend confirmation instructions" %></div>
10+
<% end %>
11+
12+
<%= render "devise/shared/links" %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p>Welcome <%= @email %>!</p>
2+
3+
<p>You can confirm your account email through the link below:</p>
4+
5+
<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @token) %></p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<p>Hello <%= @resource.email %>!</p>
2+
3+
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
4+
5+
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @token) %></p>
6+
7+
<p>If you didn't request this, please ignore this email.</p>
8+
<p>Your password won't change until you access the link above and create a new one.</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<p>Hello <%= @resource.email %>!</p>
2+
3+
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
4+
5+
<p>Click the link below to unlock your account:</p>
6+
7+
<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @token) %></p>
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<h2>Change your password</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
4+
<%= devise_error_messages! %>
5+
<%= f.hidden_field :reset_password_token %>
6+
7+
<div><%= f.label :password, "New password" %><br />
8+
<%= f.password_field :password, :autofocus => true %></div>
9+
10+
<div><%= f.label :password_confirmation, "Confirm new password" %><br />
11+
<%= f.password_field :password_confirmation %></div>
12+
13+
<div><%= f.submit "Change my password" %></div>
14+
<% end %>
15+
16+
<%= render "devise/shared/links" %>
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h2>Forgot your password?</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
4+
<%= devise_error_messages! %>
5+
6+
<div><%= f.label :email %><br />
7+
<%= f.email_field :email, :autofocus => true %></div>
8+
9+
<div><%= f.submit "Send me reset password instructions" %></div>
10+
<% end %>
11+
12+
<%= render "devise/shared/links" %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<h2>Edit <%= resource_name.to_s.humanize %></h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
4+
<%= devise_error_messages! %>
5+
6+
<div><%= f.label :email %><br />
7+
<%= f.email_field :email, :autofocus => true %></div>
8+
9+
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
10+
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
11+
<% end %>
12+
13+
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
14+
<%= f.password_field :password, :autocomplete => "off" %></div>
15+
16+
<div><%= f.label :password_confirmation %><br />
17+
<%= f.password_field :password_confirmation %></div>
18+
19+
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
20+
<%= f.password_field :current_password %></div>
21+
22+
<div><%= f.submit "Update" %></div>
23+
<% end %>
24+
25+
<h3>Cancel my account</h3>
26+
27+
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %></p>
28+
29+
<%= link_to "Back", :back %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<h2>Sign up</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
4+
<%= devise_error_messages! %>
5+
6+
<div><%= f.label :email %><br />
7+
<%= f.email_field :email, :autofocus => true %></div>
8+
9+
<div><%= f.label :password %><br />
10+
<%= f.password_field :password %></div>
11+
12+
<div><%= f.label :password_confirmation %><br />
13+
<%= f.password_field :password_confirmation %></div>
14+
15+
<div><%= f.submit "Sign up" %></div>
16+
<% end %>
17+
18+
<%= render "devise/shared/links" %>
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<h2>Sign in</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
4+
<div><%= f.label :email %><br />
5+
<%= f.email_field :email, :autofocus => true %></div>
6+
7+
<div><%= f.label :password %><br />
8+
<%= f.password_field :password %></div>
9+
10+
<% if devise_mapping.rememberable? -%>
11+
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
12+
<% end -%>
13+
14+
<div><%= f.submit "Sign in" %></div>
15+
<% end %>
16+
17+
<%= render "devise/shared/links" %>

app/views/devise/shared/_links.erb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<%- if controller_name != 'sessions' %>
2+
<%= link_to "Sign in", new_session_path(resource_name) %><br />
3+
<% end -%>
4+
5+
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6+
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
7+
<% end -%>
8+
9+
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
10+
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
11+
<% end -%>
12+
13+
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14+
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
15+
<% end -%>
16+
17+
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
18+
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
19+
<% end -%>
20+
21+
<%- if devise_mapping.omniauthable? %>
22+
<%- resource_class.omniauth_providers.each do |provider| %>
23+
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
24+
<% end -%>
25+
<% end -%>

app/views/devise/unlocks/new.html.erb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h2>Resend unlock instructions</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
4+
<%= devise_error_messages! %>
5+
6+
<div><%= f.label :email %><br />
7+
<%= f.email_field :email, :autofocus => true %></div>
8+
9+
<div><%= f.submit "Resend unlock instructions" %></div>
10+
<% end %>
11+
12+
<%= render "devise/shared/links" %>

app/views/home/index.html.haml

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
.row-fluid
2-
.span12
3-
.well#chat_history
2+
.well.span12#chat_history
43
.row-fluid
5-
.span12
6-
%input#new_message{:type => 'text', :value => 'New message'}
7-
%button#send_message Send Message
4+
.input-append.span10
5+
%input.span#new_message{:type => 'text', :value => 'New message'}
6+
%button.btn#send_message Send
87

9-
.row-fluid
10-
.span12
11-
%h4 Set screen name
12-
%input#screen_name{:type => 'text', :value => 'Anon'}
13-
%button#set_name Submit!

app/views/layouts/application.html.haml

+4-9
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,19 @@
2626
%span.icon-bar
2727
%span.icon-bar
2828
%span.icon-bar
29-
%a.brand(href="#") WebsocketRailsDemo
30-
.container.nav-collapse
31-
%ul.nav
32-
%li= link_to "Link 1", "/path1"
33-
%li= link_to "Link 2", "/path2"
34-
%li= link_to "Link 3", "/path3"
29+
%a.brand(href="#") WebsocketRails Demo
3530

3631
.container-fluid
3732

3833
.row-fluid
39-
.span3
34+
.span2
4035
.well.sidebar-nav
4136
%ul.nav.nav-list
42-
%li.nav-header Sidebar
37+
%li.nav-header Active Users
4338
%li= link_to "Link 1", "/path1"
4439
%li= link_to "Link 2", "/path2"
4540
%li= link_to "Link 3", "/path3"
46-
.span9
41+
.span10
4742
= bootstrap_flash
4843
= yield
4944

app/views/layouts/devise.html.haml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
!!! 5
2+
%html(lang="en")
3+
%head
4+
%meta(charset="utf-8")
5+
%meta(http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1")
6+
%meta(name="viewport" content="width=device-width, initial-scale=1.0")
7+
%title= content_for?(:title) ? yield(:title) : "WebsocketRailsDemo"
8+
= csrf_meta_tags
9+
/ Le HTML5 shim, for IE6-8 support of HTML elements
10+
/[if lt IE 9]
11+
= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js"
12+
= stylesheet_link_tag "application", :media => "all"
13+
= favicon_link_tag 'apple-touch-icon-144x144-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '144x144'
14+
= favicon_link_tag 'apple-touch-icon-114x114-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '114x114'
15+
= favicon_link_tag 'apple-touch-icon-72x72-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '72x72'
16+
= favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png'
17+
= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon'
18+
= javascript_include_tag "application"
19+
20+
21+
%body
22+
.container-fluid
23+
.row-fluid
24+
.span9
25+
= bootstrap_flash
26+
= yield
27+
%footer
28+
%p &copy; Company 2013

config/environments/development.rb

+2
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@
2727
# number of complex assets.
2828
config.assets.debug = true
2929
config.middleware.delete Rack::Lock
30+
31+
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
3032
end

0 commit comments

Comments
 (0)