c80_news_tz 0.1.1.21 → 0.1.1.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15f192a8810ee8e908dda8d442f54e4eaf7f8f15
4
- data.tar.gz: d7aed5c07568f7a4e3c33a5c4197a54fd522faf9
3
+ metadata.gz: f176c63a7d34761544aeadf49b255c7e871ec83d
4
+ data.tar.gz: ce4470d35eaec9c3cdc5dc51ea17b0fcbd3ff37d
5
5
  SHA512:
6
- metadata.gz: 7de32164e50f27bf30c091240376769e33b519905a5bc5483b37f85fbffd0e7712dc9e1818be8e81fbbe48b535913d2c10a6ade76f27f013747f66740868fda5
7
- data.tar.gz: b207cfb134caa3fc127026c0df61b2e90531ba5351e077e8936de762cbe29d3aca72f80ffcad1c2b61944ce1fa7d392ccd3e3821545fa511d56fecafb59bf77d
6
+ metadata.gz: e17cb7c6e990ea0c756f07f43cdcc5260e615410f8be402130310e5259509e54127aea0e7f99cf1376b0fe9e5daf7efc15f8906ea7edf9f72f99f1a2d7a7a42a
7
+ data.tar.gz: 166791118577e689e52b4ccbac7a30ca807a7ac883f172e2461ab5a32654bbe8406d3e0b9653cb2c04b593015038dbfb31ee294a3557179251aa5934eccde1a9
@@ -0,0 +1,38 @@
1
+ module C80NewsTz
2
+ class SessionsController < ApplicationController
3
+
4
+ def create
5
+ #render text: request.env['omniauth.auth'].to_yaml
6
+
7
+ begin
8
+ @user = User.from_omniauth(request.env['omniauth.auth'])
9
+ session[:user_id] = @user.id
10
+ flash[:success] = "Welcome, #{@user.name}!"
11
+ rescue => e
12
+ Rails.logger.debug(e)
13
+ flash[:warning] = 'There was an error while try to authenticate you...'
14
+ end
15
+
16
+ # Rails.logger.debug("<SessionsController.create> request.env['omniauth.origin'] = " + request.env['omniauth.origin'])
17
+ redirect_to request.env['omniauth.origin']
18
+
19
+ end
20
+
21
+ def destroy
22
+ if current_user
23
+ session.delete(:user_id)
24
+ flash[:success] = 'See you!'
25
+ end
26
+
27
+ redirect_to request.referer
28
+
29
+ end
30
+
31
+ def auth_failure
32
+ # redirect_to request.referer
33
+ redirect_to request.env['omniauth.origin']
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,43 @@
1
+ module C80NewsTz
2
+ class User < ActiveRecord::Base
3
+
4
+ def self.from_omniauth(auth_hash)
5
+ user = find_or_create_by(uid: auth_hash['uid'], provider: auth_hash['provider'])
6
+ user.name = auth_hash['info']['name']
7
+ user.location = get_social_location_for user.provider, auth_hash['info']['location']
8
+ user.image_url = auth_hash['info']['image']
9
+ user.url = get_social_url_for user.provider, auth_hash['info']['urls'] #[user.provider.capitalize]
10
+ user.save!
11
+ user
12
+ end
13
+
14
+ private
15
+
16
+ # LinkedIn’s authentication hash is a bit different from the ones that we’ve seen up to now:
17
+ # * location is a nested hash with country’s code and name.
18
+ # * urls is also a nested hash, but there is no LinkedIn key. Instead, there is a
19
+ # public_profile key and probably a bunch of others (storing personal web site and things like that).
20
+ # This introduces some complexity to the parsing methods:
21
+
22
+ def self.get_social_location_for(provider, location_hash)
23
+ case provider
24
+ when 'linkedin'
25
+ location_hash['name']
26
+ else
27
+ location_hash
28
+ end
29
+ end
30
+
31
+ def self.get_social_url_for(provider, urls_hash)
32
+ case provider
33
+ when 'linkedin'
34
+ urls_hash['public_profile']
35
+ else
36
+ urls_hash[provider.capitalize]
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,24 @@
1
+ Rails.application.config.middleware.use OmniAuth::Builder do
2
+ provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
3
+
4
+ provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'],
5
+ scope: 'public_profile',
6
+ info_fields: 'id,name,link'
7
+
8
+ provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_SECRET'],
9
+ scope: 'profile',
10
+ image_aspect_ratio: 'square',
11
+ image_size: 48,
12
+ access_type: 'online',
13
+ name: 'google',
14
+ skip_jwt: true
15
+
16
+ provider :linkedin, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET'],
17
+ scope: 'r_basicprofile',
18
+ fields: %w'id first-name last-name location picture-url public_profile_url'
19
+
20
+ end
21
+
22
+ OmniAuth.config.on_failure = Proc.new do |env|
23
+ C80NewsTz::SessionsController.action(:auth_failure).call(env)
24
+ end
data/config/routes.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  C80NewsTz::Engine.routes.draw do
2
2
  match 'news_guru', :to => 'application#guru', :via => :post
3
3
  match 'rb', :to => 'banners#counter', :via => :post
4
+
5
+ get '/auth/:provider/callback', to: 'sessions#create'
6
+ delete '/logout', to: 'sessions#destroy'
7
+
4
8
  end
@@ -0,0 +1,14 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :c80_news_tz_users, :options => 'COLLATE=utf8_unicode_ci' do |t|
4
+ t.string :provider, null: false
5
+ t.string :uid, null: false
6
+ t.string :name
7
+ t.string :location
8
+ t.string :image_url
9
+ t.string :url
10
+
11
+ t.timestamps null: false
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ class AddUsersIndexes < ActiveRecord::Migration
2
+ def change
3
+
4
+ add_index :c80_news_tz_users, :provider
5
+ add_index :c80_news_tz_users, :uid
6
+ add_index :c80_news_tz_users, [:provider, :uid], unique: true
7
+
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module C80NewsTz
2
- VERSION = "0.1.1.21"
2
+ VERSION = "0.1.1.22"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c80_news_tz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.21
4
+ version: 0.1.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - C80609A
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,6 +130,7 @@ files:
130
130
  - app/assets/stylesheets/c80_news_tz/frontend/pubs_medium.scss
131
131
  - app/controllers/c80_news_tz/application_controller.rb
132
132
  - app/controllers/c80_news_tz/banners_controller.rb
133
+ - app/controllers/c80_news_tz/sessions_controller.rb
133
134
  - app/helpers/c80_news_tz/advertisers_helper.rb
134
135
  - app/helpers/c80_news_tz/application_helper.rb
135
136
  - app/helpers/c80_news_tz/banners_helper.rb
@@ -161,6 +162,7 @@ files:
161
162
  - app/models/c80_news_tz/rubric.rb
162
163
  - app/models/c80_news_tz/rubric_validator.rb
163
164
  - app/models/c80_news_tz/spot.rb
165
+ - app/models/c80_news_tz/user.rb
164
166
  - app/uploaders/c80_news_tz/bimage01_uploader.rb
165
167
  - app/uploaders/c80_news_tz/bimage02_uploader.rb
166
168
  - app/uploaders/c80_news_tz/bimage03_uploader.rb
@@ -184,6 +186,7 @@ files:
184
186
  - bin/console
185
187
  - bin/setup
186
188
  - c80_news_tz.gemspec
189
+ - config/initializers/omniauth.rb
187
190
  - config/locales/ru.yml
188
191
  - config/routes.rb
189
192
  - db/migrate/20151129000045_create_rubrics.rb
@@ -218,6 +221,8 @@ files:
218
221
  - db/migrate/20160309194444_create_banners01.rb
219
222
  - db/migrate/20160310110000_create_banners02.rb
220
223
  - db/migrate/20160310114242_create_banners03.rb
224
+ - db/migrate/20160314093945_create_users.rb
225
+ - db/migrate/20160314093946_add_users_indexes.rb
221
226
  - db/seeds/19_fill_news_props.rb.example
222
227
  - db/seeds/20_fill_rubrics.rb.example
223
228
  - db/seeds/21_fill_facts.rb.example