Skip to content

Commit 1264232

Browse files
committed
Handler of Authentication failure added #5
1 parent db26277 commit 1264232

File tree

6 files changed

+150
-7
lines changed

6 files changed

+150
-7
lines changed

app/controllers/spreadsheets_controller.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ def new
1717
# Spreadsheets from google
1818
@spreadsheets = get_spreadsheets(spreadsheet)
1919
@token = spreadsheet.access_token
20-
@msg = 'work'
2120
else
22-
@msg = 'no work'
2321
# Handle if data does not get saved
2422
end
2523
end
@@ -28,7 +26,6 @@ def edit
2826
token = spreadsheet_params['token']
2927
spreadsheet = Spreadsheet.where(access_token: token)[0]
3028
spreadsheet.add_spreadsheet_credentials(spreadsheet_params)
31-
#binding.pry
3229
spreadsheet.save
3330

3431
@spreadsheets = Spreadsheet.all.to_a
@@ -51,4 +48,12 @@ def destroy
5148
def spreadsheet_params
5249
params.permit(:title, :id, :token)
5350
end
51+
52+
def failure
53+
if params['message'].match('access_denied')
54+
@msg = "Account integration Failed. User Refused to grant permissions"
55+
end
56+
@spreadsheets = Spreadsheet.all.to_a
57+
render action: 'index'
58+
end
5459
end

app/views/spreadsheets/index.html.haml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
= @msg if @msg
12
%h4
23
=link_to 'Add New Spreadsheet', 'auth/google/'
34

config/initializers/google_oauth.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
name: 'google',
55
scope: 'userinfo.profile,userinfo.email,drive,https://spreadsheets.google.com/feeds',
66
prompt: 'consent',
7-
access_type: 'offline',
8-
#redirect_uri: 'http://localhost:8080/auth/google/spreadsheets'
7+
access_type: 'offline'
98
}
10-
end
9+
end
10+
11+
OmniAuth.config.on_failure = Proc.new { |env|
12+
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
13+
}

config/routes.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Rails.application.routes.draw do
22

3-
get '/auth/:provider/callback', to: 'spreadsheets#new'
3+
get '/auth/:provider/callback', to: 'spreadsheets#new'
4+
get '/auth/failure', to: 'spreadsheets#failure'
45
resources :users, :newsletters, :home, :spreadsheets
56

67
root :to => 'home#index'
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
HTTP/1.1 302 Found
2+
Content-Length: 537
3+
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
4+
Cache-Control: no-cache
5+
X-Request-Id: b511bdb4-c778-4f1a-b5d7-849f1402b1a3
6+
X-Runtime: 0.003534
7+
Server: WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)
8+
Date: Thu, 10 Jul 2014 10:39:34 GMT
9+
Connection: Keep-Alive
10+
Set-Cookie: _lightair_session=Uy9SNDQ1LzZFandLd1g4S2VVTEptR3ZRa0RBcnNFWGtZbG1VZmNKMzc5Z1F6cDFuaHBCa2lScHcxL1FBQ044RTJZMU9iUWF2UitaVjQxcGVzeUZwS0Q3NkdXdzg2SHB6S0IrcU1sR2ExelhRRVZuWFF6MFpraktBMTNCcTM4UVZ5a01ReitYSzNYT2M0dXR1NWViUjhvVGVxUnYwRUtLREtoQUVjMkJPMW1PZG14MUVUQlN0Q2hkRUh5blVLMDZRLS1OZ3JGQXFWQmJKMGNCWGszQWoyMkNRPT0%3D--8345e9f7215c9ef812febd3588c505cfaef628c1; path=/; HttpOnly
11+
12+
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...

spec/controllers/host_response.json

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
HTTP/1.1 200 OK
2+
X-Frame-Options: SAMEORIGIN
3+
X-Xss-Protection: 1; mode=block
4+
X-Content-Type-Options: nosniff
5+
Content-Type: text/html; charset=utf-8
6+
Etag: "b29936011c26adc86d08ede08dc03e1e"
7+
Cache-Control: max-age=0, private, must-revalidate
8+
X-Request-Id: cdc9c224-e586-409f-adfb-8367d40f8a41
9+
X-Runtime: 0.015686
10+
Server: WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)
11+
Date: Thu, 10 Jul 2014 10:21:40 GMT
12+
Content-Length: 4406
13+
Connection: Keep-Alive
14+
Set-Cookie: request_method=GET; path=/
15+
Set-Cookie: _lightair_session=aUVDRko5L1dYOFJqN2NvNmg2NkI3b2JwN01GRXduamtJdFhmM3hoU0dkR2U3WkpLS2ZUUFlqRWppOGg1NHBPYllDaVpDM2w5d0xxVlBuRFJjaHVFa0FaRVdXOUdQWDlFSGJoaUZTYkdtQnl0N3F3OVdQd1c0YU5rZjNQZ09JcTFmck1HenpMbnhxaHFRT091SnZkdUZRPT0tLTVuczRGVTZyNHdwWXVaZmliU0VxZ0E9PQ%3D%3D--f5a6ab0bbbd0ec42bc63ca27924361e391dd36b3; path=/; HttpOnly
16+
17+
<!DOCTYPE html>
18+
<html>
19+
<head></head>
20+
<title>Lightair</title>
21+
<link data-turbolinks-track="true" href="/assets/bootstrap_config.css?body=1" media="all" rel="stylesheet" />
22+
<link data-turbolinks-track="true" href="/assets/callbacks.css?body=1" media="all" rel="stylesheet" />
23+
<link data-turbolinks-track="true" href="/assets/home.css?body=1" media="all" rel="stylesheet" />
24+
<link data-turbolinks-track="true" href="/assets/newsletters.css?body=1" media="all" rel="stylesheet" />
25+
<link data-turbolinks-track="true" href="/assets/spreadsheets.css?body=1" media="all" rel="stylesheet" />
26+
<link data-turbolinks-track="true" href="/assets/users.css?body=1" media="all" rel="stylesheet" />
27+
<link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet" />
28+
<script data-turbolinks-track="true" src="/assets/jquery.js?body=1"></script>
29+
<script data-turbolinks-track="true" src="/assets/jquery_ujs.js?body=1"></script>
30+
<script data-turbolinks-track="true" src="/assets/turbolinks.js?body=1"></script>
31+
<script data-turbolinks-track="true" src="/assets/bootstrap.js?body=1"></script>
32+
<script data-turbolinks-track="true" src="/assets/callbacks.js?body=1"></script>
33+
<script data-turbolinks-track="true" src="/assets/home.js?body=1"></script>
34+
<script data-turbolinks-track="true" src="/assets/newsletters.js?body=1"></script>
35+
<script data-turbolinks-track="true" src="/assets/spreadsheets.js?body=1"></script>
36+
<script data-turbolinks-track="true" src="/assets/users.js?body=1"></script>
37+
<script data-turbolinks-track="true" src="/assets/application.js?body=1"></script>
38+
<meta content="authenticity_token" name="csrf-param" />
39+
<meta content="iFrf5ZPmmsx76vtT1YCDPMyTg14I306+Ee24MzDhOig=" name="csrf-token" />
40+
<body>
41+
<div class='nav navbar-inverse navbar-fixed-top'>
42+
<div class='container'>
43+
<div class='navbar-header'>
44+
<div class='navbar-brand'>
45+
<h4>LightAir</h4>
46+
</div>
47+
</div>
48+
<div class='nav-collapse'>
49+
<ul class='nav navbar-nav'>
50+
<li class='active'>
51+
<a href='/home'>
52+
<h4>Home</h4>
53+
</a>
54+
</li>
55+
<li>
56+
<a href='#'>
57+
<h4>Newsletters</h4>
58+
</a>
59+
</li>
60+
<li>
61+
<a href='/users'>
62+
<h4>Show Users</h4>
63+
</a>
64+
</li>
65+
<li class='dropdown'>
66+
<a class='dropdown-toggle' data-toggle='dropdown'>
67+
<h4>
68+
Add Users
69+
<span class='caret'></span>
70+
</h4>
71+
</a>
72+
<ul aria-labelledby='dropdownMenu1' class='dropdown-menu' role='menu'>
73+
<li>
74+
<a href='/users/new' role='menuitem' tabindex='-1'>Add Manually</a>
75+
</li>
76+
<li>
77+
<a href='/spreadsheets' role='menuitem' tabindex='-2'>Google Spreadsheets</a>
78+
</li>
79+
</ul>
80+
</li>
81+
</ul>
82+
</div>
83+
<ul class='nav navbar-nav navbar-right'>
84+
<li class='active'>
85+
<a href='#'>
86+
<h4>
87+
Subscriber count :
88+
28
89+
</h4>
90+
</a>
91+
</li>
92+
</ul>
93+
</div>
94+
</div>
95+
<div class='container'>
96+
<div class='row'>
97+
<div class='col-sm-9'>
98+
<div class='carousel slide' id='myCarousel'>
99+
<div class='carousel-inner'>
100+
<div class='active item'>
101+
<img alt="1" src="/images/1.jpg" />
102+
</div>
103+
<div class='item'>
104+
<img alt="2" src="/images/2.jpg" />
105+
</div>
106+
</div>
107+
</div>
108+
<script type='text/javascript'>
109+
var $ = jQuery.noConflict(); $(document).ready(function() { $('#myCarousel').carousel({ interval: 3000, cycle: true }); });
110+
</script>
111+
</div>
112+
<div class='col-sm-3'>
113+
<center>
114+
<h3>Insight of LightAir</h3>
115+
<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>
116+
</center>
117+
</div>
118+
</div>
119+
</div>
120+
</body>
121+
</html>

0 commit comments

Comments
 (0)