Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: code-newbies/ruby-committed
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: code-newbies/ruby-committed
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: authenticate
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 15 commits
  • 48 files changed
  • 1 contributor

Commits on Oct 4, 2015

  1. Copy the full SHA
    f302508 View commit details
  2. Copy the full SHA
    5a60106 View commit details
  3. Copy the full SHA
    a9fab26 View commit details
  4. Copy the full SHA
    f6c4ea3 View commit details
  5. Removed rspec-pride

    claytonflesher committed Oct 4, 2015
    Copy the full SHA
    af59594 View commit details
  6. Gemlock

    claytonflesher committed Oct 4, 2015
    Copy the full SHA
    6ce97df View commit details
  7. Copy the full SHA
    e5d107a View commit details
  8. Copy the full SHA
    b6adc71 View commit details

Commits on Oct 5, 2015

  1. Copy the full SHA
    5208fd0 View commit details
  2. Copy the full SHA
    41f04bb View commit details
  3. Copy the full SHA
    95d384c View commit details
  4. Copy the full SHA
    602ca08 View commit details
  5. Copy the full SHA
    b1bff37 View commit details
  6. Copy the full SHA
    48c584a View commit details

Commits on Oct 6, 2015

  1. Copy the full SHA
    14f9f09 View commit details
Showing with 590 additions and 3 deletions.
  1. +2 −0 .rspec
  2. +6 −0 Gemfile
  3. +31 −2 Gemfile.lock
  4. +3 −0 app/assets/javascripts/dashboards.coffee
  5. +3 −0 app/assets/javascripts/sessions.coffee
  6. +3 −0 app/assets/javascripts/users.coffee
  7. +3 −0 app/assets/javascripts/verifications.coffee
  8. +3 −0 app/assets/stylesheets/dashboards.scss
  9. +3 −0 app/assets/stylesheets/sessions.scss
  10. +3 −0 app/assets/stylesheets/users.scss
  11. +3 −0 app/assets/stylesheets/verifications.scss
  12. +5 −0 app/controllers/dashboards_controller.rb
  13. +24 −0 app/controllers/sessions_controller.rb
  14. +21 −0 app/controllers/users_controller.rb
  15. +18 −0 app/controllers/verifications_controller.rb
  16. +2 −0 app/helpers/dashboards_helper.rb
  17. +2 −0 app/helpers/sessions_helper.rb
  18. +2 −0 app/helpers/users_helper.rb
  19. +2 −0 app/helpers/verifications_helper.rb
  20. +4 −0 app/mailers/application_mailer.rb
  21. +13 −0 app/mailers/user_mailer.rb
  22. +8 −0 app/models/user.rb
  23. +3 −0 app/views/dashboards/new.html.erb
  24. +5 −0 app/views/layouts/mailer.html.erb
  25. +1 −0 app/views/layouts/mailer.text.erb
  26. +13 −0 app/views/sessions/new.html.erb
  27. +3 −0 app/views/user_mailer/verify.text.erb
  28. +14 −0 app/views/users/new.html.erb
  29. +2 −0 app/views/verifications/new.html.erb
  30. +16 −0 bin/rspec
  31. +1 −1 config/database.yml.sample
  32. +2 −0 config/environments/development.rb
  33. +17 −0 config/routes.rb
  34. +12 −0 db/migrate/20151004184620_create_users.rb
  35. +31 −0 db/schema.rb
  36. +5 −0 spec/controllers/dashboards_controller_spec.rb
  37. +17 −0 spec/controllers/sessions_controller_spec.rb
  38. +22 −0 spec/controllers/users_controller_spec.rb
  39. +5 −0 spec/controllers/verifications_controller_spec.rb
  40. +8 −0 spec/factories/users.rb
  41. +14 −0 spec/helpers/dashboards_helper_spec.rb
  42. +14 −0 spec/helpers/sessions_helper_spec.rb
  43. +14 −0 spec/helpers/verifications_helper_spec.rb
  44. +4 −0 spec/mailers/previews/user_mailer_preview.rb
  45. +4 −0 spec/mailers/user_mailer_spec.rb
  46. +55 −0 spec/models/user_spec.rb
  47. +52 −0 spec/rails_helper.rb
  48. +92 −0 spec/spec_helper.rb
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ source 'https://rubygems.org'
gem 'rails', '4.2.3'
# Use postgresql as the database for Active Record
gem 'pg'
# Use bcrypt for password encryption
gem 'bcrypt'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
@@ -41,5 +43,9 @@ group :development, :test do

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'

# Use rpsec and Factory Girl for tests
gem 'rspec-rails'
gem 'factory_girl_rails'
end

33 changes: 31 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
bcrypt (3.1.10)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
@@ -49,12 +50,18 @@ GEM
execjs
coffee-script-source (1.9.1.1)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.6.0)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.5.0)
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
globalid (0.3.6)
activesupport (>= 4.1.0)
i18n (0.7.0)
jbuilder (2.3.1)
jbuilder (2.3.2)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (4.0.5)
@@ -102,7 +109,23 @@ GEM
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rdoc (4.2.0)
json (~> 1.4)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-rails (3.3.3)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
sass (3.4.18)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
@@ -140,15 +163,21 @@ PLATFORMS
ruby

DEPENDENCIES
bcrypt
byebug
coffee-rails (~> 4.1.0)
factory_girl_rails
jbuilder (~> 2.0)
jquery-rails
pg
rails (= 4.2.3)
rspec-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
spring
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)

BUNDLED WITH
1.10.6
3 changes: 3 additions & 0 deletions app/assets/javascripts/dashboards.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/sessions.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/users.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/verifications.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/dashboards.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the dashboards controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sessions.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/users.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/verifications.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Verifications controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
5 changes: 5 additions & 0 deletions app/controllers/dashboards_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DashboardsController < ApplicationController
def new
@user = User.find(session[:user_id])
end
end
24 changes: 24 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class SessionsController < ApplicationController
def new
@user = User.new
end

def create
@user = User.where(
"email = ? AND verified_at IS NOT NULL",
params[:email]
).first
if @user && @user.authenticate(params[:password])
session[:user_id] = @user.id
redirect_to dashboard_path
else
flash.now[:alert] = "Email or password didn't match"
render :new
end
end

def destroy
reset_session
redirect_to signin_path
end
end
21 changes: 21 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class UsersController < ApplicationController
def new
@user = User.new
end

def create
@user = User.new(user_params)
if @user && @user.password == @user.password_confirmation
@user.save!
redirect_to verify_path(user_id: @user.id)
else
redirect_to signup_path
end
end

private

def user_params
params.require(:user).permit(:email, :password, :password_confirmation)
end
end
18 changes: 18 additions & 0 deletions app/controllers/verifications_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "securerandom"

class VerificationsController < ApplicationController
def new
@user = User.find(params[:user_id])
@user.verification_token = SecureRandom.hex(20)
@user.save!
UserMailer.verify(@user).deliver_now
end

def create
@user = User.find_by(verification_token: params[:token])
@user.verified_at = Time.now
@user.save!
flash[:notice] = "Email verified. Please sign in."
redirect_to signin_path
end
end
2 changes: 2 additions & 0 deletions app/helpers/dashboards_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module DashboardsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SessionsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
2 changes: 2 additions & 0 deletions app/helpers/verifications_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module VerificationsHelper
end
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout 'mailer'
end
13 changes: 13 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class UserMailer < ApplicationMailer
default from: "donotreply@rubycommited.com"

def verify(user)
@user = user
mail to: @user.email, subject: "[Ruby Committed] Verify Email"
end

def reset_password(user)
@user = user
mail to: @user.email, subect: "[Ruby Committed] Reset Password"
end
end
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class User < ActiveRecord::Base
has_secure_password

validates :email,
presence: true,
format: /\A[^@\s]+@[^@\s]+\z/,
uniqueness: true
end
3 changes: 3 additions & 0 deletions app/views/dashboards/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Dashboard</h1>

<%= link_to "Sign Out", signout_path, method: "DELETE" %>
5 changes: 5 additions & 0 deletions app/views/layouts/mailer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions app/views/layouts/mailer.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= yield %>
13 changes: 13 additions & 0 deletions app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Sign In

<%= form_tag do %>
<%= label_tag :email, "Email" %>
<%= email_field_tag :email %>
<br>
<%= label_tag :password, "Password" %>
<%= password_field_tag :password %>
<br>
<%= submit_tag "Sign In" %>
<% end %>
<br>
<br>
3 changes: 3 additions & 0 deletions app/views/user_mailer/verify.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Please click the following link to verify your email:

<%= confirm_url(token: @user.verification_token) %>
14 changes: 14 additions & 0 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Sign Up!

<%= form_for @user, url: signup_path do |f| %>
<%= f.label :email, "Email" %>
<%= f.email_field :email %>
<br>
<%= f.label :password, "Password" %>
<%= f.password_field :password %>
<br>
<%= f.label :password_confirmation, "Confirm Password" %>
<%= f.password_field :password_confirmation %>
<br>
<%= f.submit %>
<% end %>
2 changes: 2 additions & 0 deletions app/views/verifications/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Please Verify Your Email</h1>
<p>An email has been sent to <%= @user.email %>. Please click on the link in that message to verify your email address.</p>
16 changes: 16 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('rspec-core', 'rspec')
2 changes: 1 addition & 1 deletion config/database.yml.sample
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ development:
# Do not set this db to the same as development or production.
test:
<<: *default
database: committed_test
database: committed_development

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -38,4 +38,6 @@

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

config.action_mailer.default_url_options = { :host => "localhost:3000" }
end
17 changes: 17 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
Rails.application.routes.draw do

get "signup" => "users#new", as: :signup
post "signup" => "users#create"
get "signin" => "sessions#new", as: :signin
post "signin" => "sessions#create"
delete "signout" => "sessions#destroy"
get "verify/:user_id" => "verifications#new", as: :verify
get "verify/confirm/:token" => "verifications#create", as: :confirm
get "reset_password" => "password_resets#new", as: :reset_password
post "reset_password" => "password_resets#create"
get "reset_password/:token/edit" => "password_resets#edit", as: :edit_reset_password
post "reset_password/:token/edit" => "password_resets#update"
get "dashboard" => "dashboards#new", as: :dashboard




# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

12 changes: 12 additions & 0 deletions db/migrate/20151004184620_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :email, null: false, index: :unique
t.string :password_digest, null: false
t.string :verification_token
t.datetime :verified_at
t.string :password_reset_token
t.timestamps null: false
end
end
end
31 changes: 31 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20151004184620) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "users", force: :cascade do |t|
t.string "email", null: false
t.string "password_digest", null: false
t.string "verification_token"
t.datetime "verified_at"
t.string "password_reset_token"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "users", ["email"], name: "index_users_on_email", using: :btree

end
5 changes: 5 additions & 0 deletions spec/controllers/dashboards_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe DashboardsController, type: :controller do

end
Loading