Skip to content

Commit

Permalink
Adding email authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
vinamratasingal committed Aug 16, 2012
1 parent ad8bde4 commit b59a659
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 24 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/authentications.js.coffee
@@ -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://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/authentications.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the Authentications controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
1 change: 1 addition & 0 deletions app/controllers/dorms_controller.rb
@@ -1,4 +1,5 @@
class DormsController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :about, :FAQ]
def show
@dorm = Dorm.find(params[:id])
end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/authentications_helper.rb
@@ -0,0 +1,2 @@
module AuthenticationsHelper
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -3,7 +3,7 @@ class User < ActiveRecord::Base
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
:recoverable, :rememberable, :trackable, :validatable, :confirmable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :encrypted_password
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/mailer/confirmation_instructions.html.erb
@@ -1,4 +1,4 @@
<p>Welcome <%= @resource.email %>!</p>
<p>Welcome <%= @resource.name %>!</p>

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

Expand Down
5 changes: 3 additions & 2 deletions app/views/devise/registrations/new.html.erb
Expand Up @@ -3,8 +3,9 @@
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>

<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :email %> <br />
<%= f.email_field :email %>
<p> Note: Please use school email </p></div>

<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
Expand Down
16 changes: 14 additions & 2 deletions config/environments/development.rb
Expand Up @@ -14,9 +14,21 @@
config.action_controller.perform_caching = false

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

#config.action_mailer.delivery_method = :sendmail

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => 'gmail.com',
:user_name => 'vinamrata.singal@gmail.com',
:password => '*******',
:authentication => 'plain',
:enable_starttls_auto => true }

# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log

Expand Down
8 changes: 4 additions & 4 deletions config/initializers/devise.rb
Expand Up @@ -4,10 +4,10 @@
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
config.mailer_sender = "vinamrata.singal@gmail.com"

# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
config.mailer = "Devise::Mailer"

# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
Expand Down Expand Up @@ -96,10 +96,10 @@
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed new email is stored in
# unconfirmed email column, and copied to email column on successful confirmation.
config.reconfirmable = true
config.reconfirmable = false

# Defines which key will be used when confirming an account
# config.confirmation_keys = [ :email ]
config.confirmation_keys = [ :email ]

# ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again.
Expand Down
8 changes: 1 addition & 7 deletions config/initializers/secret_token.rb
@@ -1,7 +1 @@
# Be sure to restart your server when you modify this file.

# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
Dormy::Application.config.secret_token = '0963a44ee1c4a2bb70fca810b683a4b0727d4741854d8cf7b7b4c845eb9bfb3fb018ec313aa4d63e77af6798c819f382683022ae5525fdfa336ab5e2ac178fd3'
Dormy::Application.config.secret_token = 'ddfc2279b82e90654f266df741ae854db96481359485c1a49e6d210d4ca92973927d8134e807e4e97e04e55fa20cb991cbbf9d497f49e13a7adfasdfe5a43e7a'
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -10,6 +10,7 @@
get "welcome/about"
get "welcome/FAQ"
root :to => 'welcome#index'



# The priority is based upon order of creation:
Expand Down
1 change: 0 additions & 1 deletion db/migrate/20120813022111_create_users.rb
Expand Up @@ -4,7 +4,6 @@ def change
t.string :name
t.references :dorm
t.references :school

t.timestamps
end
add_index :users, :dorm_id
Expand Down
12 changes: 6 additions & 6 deletions db/migrate/20120814012106_add_devise_to_users.rb
Expand Up @@ -19,11 +19,11 @@ def self.up
t.string :current_sign_in_ip
t.string :last_sign_in_ip

## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
##Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
#t.string :unconfirmed_email # Only if using reconfirmable

## Lockable
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
Expand All @@ -40,7 +40,7 @@ def self.up

add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
# add_index :users, :confirmation_token, :unique => true
add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
Expand Down
4 changes: 4 additions & 0 deletions db/schema.rb
Expand Up @@ -44,8 +44,12 @@
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
end

add_index "users", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true
add_index "users", ["dorm_id"], :name => "index_users_on_dorm_id"
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
Expand Down
6 changes: 6 additions & 0 deletions id:integer
@@ -0,0 +1,6 @@
 invoke active_record
 create db/migrate/20120815213511_create_authentications.rb
 create app/models/authentication.rb
 invoke test_unit
 create test/unit/authentication_test.rb
 create test/fixtures/authentications.yml
13 changes: 13 additions & 0 deletions test/fixtures/authentications.yml
@@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
user: MyString
provider: MyString
uid: MyString
token: MyString

two:
user: MyString
provider: MyString
uid: MyString
token: MyString
7 changes: 7 additions & 0 deletions test/functional/authentications_controller_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class AuthenticationsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/functional/user_mailer_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class UserMailerTest < ActionMailer::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/unit/authentication_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class AuthenticationTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
4 changes: 4 additions & 0 deletions test/unit/helpers/authentications_helper_test.rb
@@ -0,0 +1,4 @@
require 'test_helper'

class AuthenticationsHelperTest < ActionView::TestCase
end

0 comments on commit b59a659

Please sign in to comment.