Skip to content

Commit

Permalink
Handler of Authentication failure added #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Pbasnal committed Jul 11, 2014
1 parent cdcc57c commit 86bfe0c
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 7 deletions.
11 changes: 8 additions & 3 deletions app/controllers/spreadsheets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def new
# Spreadsheets from google
@spreadsheets = get_spreadsheets(spreadsheet)
@token = spreadsheet.access_token
@msg = 'work'
else
@msg = 'no work'
# Handle if data does not get saved
end
end
Expand All @@ -28,7 +26,6 @@ def edit
token = spreadsheet_params['token']
spreadsheet = Spreadsheet.where(access_token: token)[0]
spreadsheet.add_spreadsheet_credentials(spreadsheet_params)
#binding.pry
spreadsheet.save

@spreadsheets = Spreadsheet.all.to_a
Expand All @@ -51,4 +48,12 @@ def destroy
def spreadsheet_params
params.permit(:title, :id, :token)
end

def failure
if params['message'].match('access_denied')
@msg = "Account integration Failed. User Refused to grant permissions"
end
@spreadsheets = Spreadsheet.all.to_a
render action: 'index'
end
end
1 change: 1 addition & 0 deletions app/views/spreadsheets/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
= @msg if @msg
%h4
=link_to 'Add New Spreadsheet', 'auth/google/'

Expand Down
9 changes: 6 additions & 3 deletions config/initializers/google_oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
name: 'google',
scope: 'userinfo.profile,userinfo.email,drive,https://spreadsheets.google.com/feeds',
prompt: 'consent',
access_type: 'offline',
#redirect_uri: 'http://localhost:8080/auth/google/spreadsheets'
access_type: 'offline'
}
end
end

OmniAuth.config.on_failure = Proc.new { |env|
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
}
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Rails.application.routes.draw do

get '/auth/:provider/callback', to: 'spreadsheets#new'
get '/auth/:provider/callback', to: 'spreadsheets#new'
get '/auth/failure', to: 'spreadsheets#failure'
resources :users, :newsletters, :home, :spreadsheets

root :to => 'home#index'
Expand Down
12 changes: 12 additions & 0 deletions spec/controllers/google_auth_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.1 302 Found
Content-Length: 537
Location: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=367225507767-119uvbhdadqbft2kn4759rodoiivksn9.apps.googleusercontent.com&prompt=consent&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fauth%2Fgoogle%2Fcallback&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive+https%3A%2F%2Fspreadsheets.google.com%2Ffeeds&state=df37c7da59cf8f7a4899cd5a67a612e9d18946664bc98d4f
Cache-Control: no-cache
X-Request-Id: b511bdb4-c778-4f1a-b5d7-849f1402b1a3
X-Runtime: 0.003534
Server: WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)
Date: Thu, 10 Jul 2014 10:39:34 GMT
Connection: Keep-Alive
Set-Cookie: _lightair_session=Uy9SNDQ1LzZFandLd1g4S2VVTEptR3ZRa0RBcnNFWGtZbG1VZmNKMzc5Z1F6cDFuaHBCa2lScHcxL1FBQ044RTJZMU9iUWF2UitaVjQxcGVzeUZwS0Q3NkdXdzg2SHB6S0IrcU1sR2ExelhRRVZuWFF6MFpraktBMTNCcTM4UVZ5a01ReitYSzNYT2M0dXR1NWViUjhvVGVxUnYwRUtLREtoQUVjMkJPMW1PZG14MUVUQlN0Q2hkRUh5blVLMDZRLS1OZ3JGQXFWQmJKMGNCWGszQWoyMkNRPT0%3D--8345e9f7215c9ef812febd3588c505cfaef628c1; path=/; HttpOnly

Redirecting to https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=367225507767-119uvbhdadqbft2kn4759rodoiivksn9.apps.googleusercontent.com&prompt=consent&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fauth%2Fgoogle%2Fcallback&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive+https%3A%2F%2Fspreadsheets.google.com%2Ffeeds&state=df37c7da59cf8f7a4899cd5a67a612e9d18946664bc98d4f...
121 changes: 121 additions & 0 deletions spec/controllers/host_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Etag: "b29936011c26adc86d08ede08dc03e1e"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: cdc9c224-e586-409f-adfb-8367d40f8a41
X-Runtime: 0.015686
Server: WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)
Date: Thu, 10 Jul 2014 10:21:40 GMT
Content-Length: 4406
Connection: Keep-Alive
Set-Cookie: request_method=GET; path=/
Set-Cookie: _lightair_session=aUVDRko5L1dYOFJqN2NvNmg2NkI3b2JwN01GRXduamtJdFhmM3hoU0dkR2U3WkpLS2ZUUFlqRWppOGg1NHBPYllDaVpDM2w5d0xxVlBuRFJjaHVFa0FaRVdXOUdQWDlFSGJoaUZTYkdtQnl0N3F3OVdQd1c0YU5rZjNQZ09JcTFmck1HenpMbnhxaHFRT091SnZkdUZRPT0tLTVuczRGVTZyNHdwWXVaZmliU0VxZ0E9PQ%3D%3D--f5a6ab0bbbd0ec42bc63ca27924361e391dd36b3; path=/; HttpOnly

<!DOCTYPE html>
<html>
<head></head>
<title>Lightair</title>
<link data-turbolinks-track="true" href="/assets/bootstrap_config.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/callbacks.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/home.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/newsletters.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/spreadsheets.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/users.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/assets/jquery.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery_ujs.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/turbolinks.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/bootstrap.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/callbacks.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/home.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/newsletters.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/spreadsheets.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/users.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/application.js?body=1"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="iFrf5ZPmmsx76vtT1YCDPMyTg14I306+Ee24MzDhOig=" name="csrf-token" />
<body>
<div class='nav navbar-inverse navbar-fixed-top'>
<div class='container'>
<div class='navbar-header'>
<div class='navbar-brand'>
<h4>LightAir</h4>
</div>
</div>
<div class='nav-collapse'>
<ul class='nav navbar-nav'>
<li class='active'>
<a href='/home'>
<h4>Home</h4>
</a>
</li>
<li>
<a href='#'>
<h4>Newsletters</h4>
</a>
</li>
<li>
<a href='/users'>
<h4>Show Users</h4>
</a>
</li>
<li class='dropdown'>
<a class='dropdown-toggle' data-toggle='dropdown'>
<h4>
Add Users
<span class='caret'></span>
</h4>
</a>
<ul aria-labelledby='dropdownMenu1' class='dropdown-menu' role='menu'>
<li>
<a href='/users/new' role='menuitem' tabindex='-1'>Add Manually</a>
</li>
<li>
<a href='/spreadsheets' role='menuitem' tabindex='-2'>Google Spreadsheets</a>
</li>
</ul>
</li>
</ul>
</div>
<ul class='nav navbar-nav navbar-right'>
<li class='active'>
<a href='#'>
<h4>
Subscriber count :
28
</h4>
</a>
</li>
</ul>
</div>
</div>
<div class='container'>
<div class='row'>
<div class='col-sm-9'>
<div class='carousel slide' id='myCarousel'>
<div class='carousel-inner'>
<div class='active item'>
<img alt="1" src="/images/1.jpg" />
</div>
<div class='item'>
<img alt="2" src="/images/2.jpg" />
</div>
</div>
</div>
<script type='text/javascript'>
var $ = jQuery.noConflict(); $(document).ready(function() { $('#myCarousel').carousel({ interval: 3000, cycle: true }); });
</script>
</div>
<div class='col-sm-3'>
<center>
<h3>Insight of LightAir</h3>
<p>LightAir is a mass Mailer designed to send newsletters designed in html to be sent to a few hundered to a tens of thousands of subscribers. It has an inbuilt HTML editor to create a newsletter online.</p>
</center>
</div>
</div>
</div>
</body>
</html>

0 comments on commit 86bfe0c

Please sign in to comment.