Skip to content
This repository was archived by the owner on Sep 4, 2018. It is now read-only.

Commit a6fdcfd

Browse files
committed
Added an in-house sign up form vs forwarding to launchrock. Also added Devise for authenticating admins.
1 parent 90b0459 commit a6fdcfd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+986
-11
lines changed

Gemfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
source 'https://rubygems.org'
22
ruby '2.1.2'
3+
#ruby=2.1.2@operation_code #JDavis this line is for rvm otherwise it will be ignored.
4+
35
#################
46
# Server and DB #
57
#################
68

79
gem 'rails', '4.1.6'
810
gem 'sprockets-rails', '~> 2.0'
11+
#gem 'pg', '0.17.1' # JDavis: consider using the postgres gem for all environments.
912

1013
#############
1114
# Front-end #
@@ -26,6 +29,7 @@ gem 'aws-sdk', '~> 1.35.0'
2629
########################
2730

2831
gem 'stripe'
32+
gem 'devise', '3.4.1' #JDavis: devise is the Rails standard for authenticating users.
2933

3034
########
3135
# Misc #
@@ -34,6 +38,7 @@ gem 'stripe'
3438
gem 'shareable'
3539
gem 'font-awesome-rails'
3640
gem 'github-markup', '~> 1.2.1'
41+
gem 'annotate', '2.5.0' #JDavis: this adds the table fields to the model file. To use, run 'annotate --position before'
3742

3843
#####################
3944
# Development Tools #
@@ -46,11 +51,11 @@ group :development do
4651
gem 'railroady'
4752
gem 'letter_opener'
4853
gem 'spring'
49-
gem 'sqlite3'
54+
gem 'sqlite3' # JDavis: Since Heroku uses postgres, we should do the same in development.
5055
end
5156

5257
group :production do
53-
gem 'pg'
54-
gem 'rails_12factor'
55-
gem 'thin'
58+
gem 'pg'
59+
gem 'rails_12factor'
60+
gem 'thin'
5661
end

Gemfile.lock

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ GEM
2828
thread_safe (~> 0.1)
2929
tzinfo (~> 1.1)
3030
addressable (2.3.6)
31+
annotate (2.5.0)
32+
rake
3133
arel (5.0.1.20140414130214)
3234
aws-sdk (1.35.0)
3335
json (~> 1.4)
3436
nokogiri (>= 1.4.4)
3537
uuidtools (~> 2.1)
38+
bcrypt (3.1.9)
3639
better_errors (2.0.0)
3740
coderay (>= 1.0.0)
3841
erubis (>= 2.6.6)
@@ -52,6 +55,13 @@ GEM
5255
coffee-script-source (1.8.0)
5356
daemons (1.1.9)
5457
debug_inspector (0.0.2)
58+
devise (3.4.1)
59+
bcrypt (~> 3.0)
60+
orm_adapter (~> 0.1)
61+
railties (>= 3.2.6, < 5)
62+
responders
63+
thread_safe (~> 0.1)
64+
warden (~> 1.2.3)
5565
erubis (2.7.0)
5666
eventmachine (1.0.3)
5767
execjs (2.2.1)
@@ -85,6 +95,7 @@ GEM
8595
netrc (0.7.7)
8696
nokogiri (1.6.3.1)
8797
mini_portile (= 0.6.0)
98+
orm_adapter (0.5.0)
8899
pg (0.17.1)
89100
posix-spawn (0.3.9)
90101
pry (0.10.1)
@@ -118,6 +129,8 @@ GEM
118129
rake (>= 0.8.7)
119130
thor (>= 0.18.1, < 2.0)
120131
rake (10.3.2)
132+
responders (1.1.2)
133+
railties (>= 3.2, < 4.2)
121134
rest-client (1.7.2)
122135
mime-types (>= 1.16, < 3.0)
123136
netrc (~> 0.7)
@@ -141,7 +154,7 @@ GEM
141154
actionpack (>= 3.0)
142155
activesupport (>= 3.0)
143156
sprockets (~> 2.8)
144-
sqlite3 (1.3.9)
157+
sqlite3 (1.3.10)
145158
stripe (1.16.0)
146159
json (~> 1.8.1)
147160
mime-types (>= 1.25, < 3.0)
@@ -161,16 +174,20 @@ GEM
161174
execjs (>= 0.3.0)
162175
json (>= 1.8.0)
163176
uuidtools (2.1.5)
177+
warden (1.2.3)
178+
rack (>= 1.0)
164179

165180
PLATFORMS
166181
ruby
167182

168183
DEPENDENCIES
184+
annotate (= 2.5.0)
169185
aws-sdk (~> 1.35.0)
170186
better_errors
171187
binding_of_caller
172188
bootstrap-sass
173189
coffee-rails (~> 4.0.0)
190+
devise (= 3.4.1)
174191
font-awesome-rails
175192
github-markup (~> 1.2.1)
176193
jbuilder (~> 2.0)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://coffeescript.org/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the Veterans controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
class VeteransController < ApplicationController
2+
before_action :set_veteran, only: [:show, :edit, :update, :destroy]
3+
before_filter :authenticate_admin!, except: [:new, :create ]
4+
5+
# GET /veterans
6+
# GET /veterans.json
7+
def index
8+
@veterans = Veteran.all
9+
end
10+
11+
# GET /veterans/1
12+
# GET /veterans/1.json
13+
def show
14+
end
15+
16+
# GET /veterans/new
17+
def new
18+
@veteran = Veteran.new
19+
end
20+
21+
# GET /veterans/1/edit
22+
def edit
23+
end
24+
25+
# POST /veterans
26+
# POST /veterans.json
27+
def create
28+
@veteran = Veteran.new(veteran_params)
29+
30+
respond_to do |format|
31+
if @veteran.save
32+
format.html { redirect_to new_veteran_path, notice: 'Thanks for signing up!' }
33+
format.json { render :show, status: :created, location: @veteran }
34+
else
35+
format.html { render :new }
36+
format.json { render json: @veteran.errors, status: :unprocessable_entity }
37+
end
38+
end
39+
end
40+
41+
# PATCH/PUT /veterans/1
42+
# PATCH/PUT /veterans/1.json
43+
def update
44+
respond_to do |format|
45+
if @veteran.update(veteran_params)
46+
format.html { redirect_to @veteran, notice: 'Veteran was successfully updated.' }
47+
format.json { render :show, status: :ok, location: @veteran }
48+
else
49+
format.html { render :edit }
50+
format.json { render json: @veteran.errors, status: :unprocessable_entity }
51+
end
52+
end
53+
end
54+
55+
# DELETE /veterans/1
56+
# DELETE /veterans/1.json
57+
def destroy
58+
@veteran.destroy
59+
respond_to do |format|
60+
format.html { redirect_to veterans_url, notice: 'Veteran was successfully destroyed.' }
61+
format.json { head :no_content }
62+
end
63+
end
64+
65+
private
66+
# Use callbacks to share common setup or constraints between actions.
67+
def set_veteran
68+
@veteran = Veteran.find(params[:id])
69+
end
70+
71+
# Never trust parameters from the scary internet, only allow the white list through.
72+
def veteran_params
73+
params.require(:veteran).permit(:first_name, :last_name, :email, :zip, :service_branch)
74+
end
75+
end

app/helpers/veterans_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module VeteransHelper
2+
3+
def service_branches
4+
["Army", "Navy", "Marine Corps", "Air Force", "Coast Guard"]
5+
end
6+
end

app/models/admin.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Admin < ActiveRecord::Base
2+
# Include default devise modules. Others available are:
3+
# :confirmable, :lockable, :timeoutable and :omniauthable
4+
devise :database_authenticatable, :registerable,
5+
:recoverable, :rememberable, :trackable, :validatable
6+
end

app/models/veteran.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# == Schema Information
2+
#
3+
# Table name: veterans
4+
#
5+
# id :integer not null, primary key
6+
# email :string(255)
7+
# first_name :string(255)
8+
# last_name :string(255)
9+
# service_branch :string(255)
10+
# zip :string(255)
11+
# created_at :datetime
12+
# updated_at :datetime
13+
#
14+
15+
class Veteran < ActiveRecord::Base
16+
validates :email, format: { :with => /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/ , message: 'Please provide a valid e-mail address'}
17+
18+
19+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 class="field">
7+
<%= f.label :email %><br />
8+
<%= f.email_field :email, autofocus: true %>
9+
</div>
10+
11+
<div class="actions">
12+
<%= f.submit "Resend confirmation instructions" %>
13+
</div>
14+
<% end %>
15+
16+
<%= render "devise/shared/links" %>
Lines changed: 5 additions & 0 deletions
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>

0 commit comments

Comments
 (0)