Skip to content

Commit

Permalink
User accounts! See #22 for exciting next steps =)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfly committed May 4, 2015
1 parent 918c3fe commit 996c019
Show file tree
Hide file tree
Showing 28 changed files with 1,030 additions and 333 deletions.
2 changes: 2 additions & 0 deletions WcaOnRails/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ gem 'will_paginate'
gem 'bootstrap-will_paginate'
gem 'local_time'
gem 'google-analytics-rails'
gem 'devise'
gem 'devise-bootstrap-views'

# Drupal defines some table columns that conflict with ActiveRecord.
# This gem lets us ignore those columns. Eventually we'll migrate this
Expand Down
16 changes: 16 additions & 0 deletions WcaOnRails/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ GEM
tzinfo (~> 1.1)
addressable (2.3.8)
arel (6.0.0)
bcrypt (3.1.10)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.2.0.0)
Expand Down Expand Up @@ -65,6 +66,14 @@ GEM
coffee-script-source (1.9.1.1)
columnize (0.9.0)
debug_inspector (0.0.2)
devise (3.4.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
responders
thread_safe (~> 0.1)
warden (~> 1.2.3)
devise-bootstrap-views (0.0.4)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.5.2)
Expand Down Expand Up @@ -136,6 +145,7 @@ GEM
notiffany (0.0.6)
nenv (~> 0.1)
shellany (~> 0.0)
orm_adapter (0.5.0)
pluginator (1.3.0)
pre-commit (0.23.0)
pluginator (~> 1.1)
Expand Down Expand Up @@ -177,6 +187,8 @@ GEM
rdoc (4.2.0)
recaptcha (0.4.0)
ref (1.0.5)
responders (2.1.0)
railties (>= 4.2.0, < 5)
rspec (3.2.0)
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
Expand Down Expand Up @@ -239,6 +251,8 @@ GEM
valid_email (0.0.11)
activemodel
mail (~> 2.6.1)
warden (1.2.3)
rack (>= 1.0)
web-console (2.1.2)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
Expand All @@ -256,6 +270,8 @@ DEPENDENCIES
bootstrap-will_paginate
byebug
capybara
devise
devise-bootstrap-views
factory_girl_rails
faker
fcgi
Expand Down
2 changes: 2 additions & 0 deletions WcaOnRails/app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

/* New stuff */
@import "nodes";
/* Courtesy of https://github.com/hisea/devise-bootstrap-views */
@import "devise_bootstrap_views";

/* Gross stuff copied over from the old site */
@import "navbar-static-top";
Expand Down
6 changes: 6 additions & 0 deletions WcaOnRails/app/assets/stylesheets/navbar-static-top.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ div.navbar-collapse {
.navbar a:link {
font-weight: normal;
}

@media (min-width: 768px) {
.navbar-nav.navbar-right:last-child {
margin-right: 0px;
}
}
4 changes: 4 additions & 0 deletions WcaOnRails/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def bootstrap_class_for(flash_type)
warning: "alert-warning",
info: "alert-info",

# For devise
notice: "alert-success",
alert: "alert-danger",

recaptcha_error: "alert-danger"
}[flash_type.to_sym] || flash_type.to_s
end
Expand Down
5 changes: 5 additions & 0 deletions WcaOnRails/app/models/devise_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DeviseUser < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable
end
18 changes: 18 additions & 0 deletions WcaOnRails/app/views/devise/confirmations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="container">
<%= bootstrap_devise_error_messages! %>
<div class="panel panel-default">
<div class="panel-heading">
<h4><%= t('.resend_confirmation_instructions', :default => 'Resend confirmation instructions') %></h4>
</div>
<div class="panel-body">
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post, role: "form" }) do |f| %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, autofocus: true, class: "form-control" %>
</div>

<%= f.submit t('.resend_confirmation_instructions', :default => 'Resend confirmation instructions'), class: "btn btn-primary" %>
<% end %>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p><%= t('.greeting', :recipient => @resource.email, :default => "Welcome #{@resource.email}!") %></p>

<p><%= t('.instruction', :default => "You can confirm your account email through the link below:") %></p>

<p><%= link_to t('.action', :default => "Confirm my account"),
confirmation_url(@resource, :confirmation_token => @token, locale: I18n.locale) %></p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p><%= t('.greeting', :recipient => @resource.email, :default => "Hello #{@resource.email}!") %></p>

<p><%= t('.instruction', :default => "Someone has requested a link to change your password, and you can do this through the link below.") %></p>

<p><%= link_to t('.action', :default => "Change my password"), edit_password_url(@resource, :reset_password_token => @token, locale: I18n.locale) %></p>

<p><%= t('.instruction_2', :default => "If you didn't request this, please ignore this email.") %></p>
<p><%= t('.instruction_3', :default => "Your password won't change until you access the link above and create a new one.") %></p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p><%= t('.greeting', :recipient => @resource.email, :default => "Hello #{@resource.email}!") %></p>

<p><%= t('.message', :default => "Your account has been locked due to an excessive amount of unsuccessful sign in attempts.") %></p>

<p><%= t('.instruction', :default => "Click the link below to unlock your account:") %></p>

<p><%= link_to t('.action', :default => "Unlock my account"), unlock_url(@resource, :unlock_token => @resource.unlock_token, locale: I18n.locale) %></p>
26 changes: 26 additions & 0 deletions WcaOnRails/app/views/devise/passwords/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="container">
<%= bootstrap_devise_error_messages! %>
<div class="panel panel-default">
<div class="panel-heading">
<h4><%= t('.change_your_password', :default => 'Change your password') %></h4>
</div>
<div class="panel-body">
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put, role: "form" }) do |f| %>
<%= f.hidden_field :reset_password_token %>

<div class="form-group">
<%= f.label :password, t('.new_password', :default => 'New password') %>
<%= f.password_field :password, autofocus: true, class: "form-control" %>
</div>

<div class="form-group">
<%= f.label :password_confirmation, t('.confirm_new_password', :default => 'Confirm new password') %>
<%= f.password_field :password_confirmation, class: "form-control" %>
</div>

<%= f.submit t('.change_my_password', :default => 'Change my password'), class: "btn btn-primary" %>
<% end %>
</div>
</div>
<%= render "devise/shared/links" %>
</div>
18 changes: 18 additions & 0 deletions WcaOnRails/app/views/devise/passwords/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="container">
<%= bootstrap_devise_error_messages! %>
<div class="panel panel-default">
<div class="panel-heading">
<h4><%= t('.forgot_your_password', :default => 'Forgot your password?') %></h4>
</div>
<div class="panel-body">
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post, role: "form" }) do |f| %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, autofocus: true, class: "form-control" %>
</div>

<%= f.submit t('.send_me_reset_password_instructions', :default => "Send me reset password instructions"), class: "btn btn-primary" %>
<% end %>
</div>
</div>
</div>
30 changes: 30 additions & 0 deletions WcaOnRails/app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="container">
<%= bootstrap_devise_error_messages! %>
<div class="panel panel-default">
<div class="panel-heading">
<h4><%= t('.title', :resource => resource_class.model_name.human , :default => 'Edit #{resource_name.to_s.humanize}') %></h4>
</div>
<div class="panel-body">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, autofocus: true, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :password %> <i>(<%= t('.leave_blank_if_you_don_t_want_to_change_it', :default => "leave blank if you don't want to change it") %>)</i><br />
<%= f.password_field :password, :autocomplete => "off", class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :current_password %> <i>(<%= t('.we_need_your_current_password_to_confirm_your_changes', :default => 'we need your current password to confirm your changes') %>)</i>
<%= f.password_field :current_password, class: "form-control" %>
</div>
<%= f.submit t('.update', :default => "Update"), class: "btn btn-primary" %></div>
<% end %>
</div>

<p><%= t('.unhappy', :default => 'Unhappy') %>? <%= link_to t('.cancel_my_account', :default => "Cancel my account"), registration_path(resource_name), :data => { :confirm => t('.are_you_sure', :default => "Are you sure?") }, :method => :delete %>.</p>
</div>
25 changes: 25 additions & 0 deletions WcaOnRails/app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="container">
<%= bootstrap_devise_error_messages! %>
<div class="panel panel-default">
<div class="panel-heading">
<h4><%= t('.sign_up', :default => "Sign up") %></h4>
</div>
<div class="panel-body">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: { role: "form" }) do |f| %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, autofocus: true, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :password %><br />
<%= f.password_field :password, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, class: "form-control" %>
</div>
<%= f.submit t('.sign_up', :default => "Sign up"), class: "btn btn-primary" %>
<% end %>
</div>
</div>
</div>
29 changes: 29 additions & 0 deletions WcaOnRails/app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<h4><%= t('.sign_in', :default => "Sign in") %></h4>
</div>
<div class="panel-body">
<%= form_for(resource, as: resource_name, url: session_path(resource_name), html: { role: "form" }) do |f| %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, autofocus: true, class: "form-control", tabindex: "1" %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= link_to t(".forgot_your_password", :default => "Forgot your password?"), new_password_path(resource_name) %><br />
<%= f.password_field :password, autocomplete: "off", class: "form-control", tabindex: "2" %>
</div>
<% if devise_mapping.rememberable? %>
<div class="checkbox">
<label>
<%= f.check_box :remember_me, tabindex: "3" %>
<%= f.label :remember_me %>
</div>
<% end %>
<%= f.submit t('.sign_in', :default => "Sign in"), class: "btn btn-primary", tabindex: "3" %>
No account? <%= link_to t(".sign_up", :default => "Sign up"), new_registration_path(resource_name) %>!
<% end %>
</div>
</div>
</div>
17 changes: 17 additions & 0 deletions WcaOnRails/app/views/devise/unlocks/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="container">
<%= bootstrap_devise_error_messages! %>
<div class="panel panel-default">
<div class="panel-heading">
<h4><%= t('.resend_unlock_instructions', :default => "Resend unlock instructions") %></h4>
</div>
<div class="panel-body">
<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post, html: { role: "form" } }) do |f| %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, autofocus: true, class: "form-control" %>
</div>
<%= f.submit t('.resend_unlock_instructions', :default => "Resend unlock instructions"), class: "btn btn-primary"%>
<% end %>
</div>
</div>
</div>
27 changes: 25 additions & 2 deletions WcaOnRails/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
<div class="navbar-collapse collapse disabled">
<ul class="nav navbar-nav">
<li class="dropdown <%= params[:controller] == 'static_pages' ? 'active' : '' %>">
<li class="dropdown <%= params[:controller] == 'static_pages' || params[:controller] == 'nodes' ? 'active' : '' %>">
<a href="/" class="dropdown-toggle top-nav" data-toggle="dropdown" data-hover="dropdown">Information <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="/">Home</a></li>
Expand All @@ -46,7 +46,7 @@
</ul>
</li>
<li class="dropdown">
<a href="/" class="dropdown-toggle top-nav" data-toggle="dropdown" data-hover="dropdown">Results <span class="caret"></span></a>
<a href="/results/" class="dropdown-toggle top-nav" data-toggle="dropdown" data-hover="dropdown">Results <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="/results/competitions.php">Competitions</a></li>
<li><a href="/results/events.php">Rankings</a></li>
Expand All @@ -73,6 +73,29 @@
</li>
<li><a href="/forum/" class="top-nav">Forum</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle top-nav" data-toggle="dropdown" data-hover="dropdown">
<% if current_devise_user %>
<%= current_devise_user.email %>
<% else %>
Sign in
<% end %>
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<% if devise_user_signed_in? %>
<li><%= link_to "Edit account", edit_devise_user_registration_path %></li>
<li class="divider"></li>
<li><%= link_to('Sign out', destroy_devise_user_session_path, :method => :delete) %></li>
<% else %>
<li><%= link_to('Sign in', new_devise_user_session_path, class: "top-nav") %></li>
<li class="divider"></li>
<li><%= link_to t('.didn_t_receive_confirmation_instructions', :default => "Didn't receive confirmation instructions?"), new_devise_user_confirmation_path %></li>
<% end %>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions WcaOnRails/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
Expand Down
1 change: 1 addition & 0 deletions WcaOnRails/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: 'www.worldcubeassociation.org' }
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
Expand Down

0 comments on commit 996c019

Please sign in to comment.