devise_russian 0.0.13 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +43 -19
- data/app/controllers/authentications_controller.rb +3 -3
- data/app/models/authentication.rb +12 -25
- data/app/views/authentications/_collection.html.erb +1 -1
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/mailer/_bottom.html.erb +2 -2
- data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/devise/sessions/new.html.erb +0 -1
- data/app/views/devise/shared/_links.erb +1 -0
- data/config/initializers/devise.rb +4 -0
- data/config/locales/devise.ru.yml +0 -1
- data/config/locales/devise_russian.ru.yml +7 -0
- data/config/routes.rb +22 -0
- data/devise_russian.gemspec +2 -0
- data/lib/devise_russian/engine.rb +1 -2
- data/lib/devise_russian/models/base.rb +6 -7
- data/lib/devise_russian/version.rb +1 -1
- data/lib/devise_russian.rb +1 -0
- metadata +37 -2
data/README.md
CHANGED
@@ -18,6 +18,23 @@ devise_russian
|
|
18
18
|
|
19
19
|
Обратите внимание на метод providers модели Authentication: https://github.com/vav/devise_russian/blob/master/app/models/authentication.rb
|
20
20
|
|
21
|
+
В случае необходимости задать свой список провайдеров:
|
22
|
+
|
23
|
+
app/models/authentication_decorator.rb:
|
24
|
+
|
25
|
+
Authentication.class_eval do
|
26
|
+
def self.providers
|
27
|
+
[
|
28
|
+
['facebook', 'Facebook'],
|
29
|
+
['vkontakte', 'Vkontakte'],
|
30
|
+
['odnoklassniki', 'Odnoklassniki'],
|
31
|
+
['twitter', 'Twitter'],
|
32
|
+
['github', 'Github'],
|
33
|
+
['google_oauth2', 'Google']
|
34
|
+
]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
21
38
|
В config/initializers/omniauth.rb:
|
22
39
|
|
23
40
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
@@ -30,6 +47,8 @@ devise_russian
|
|
30
47
|
provider :odnoklassniki, "2222222", "HGF33GH3F3HGF3HGF3SD",
|
31
48
|
:public_key => "DFKSFDKJHJHFJSDSADSD", :provider_ignores_state => true
|
32
49
|
|
50
|
+
...
|
51
|
+
|
33
52
|
Миграции:
|
34
53
|
|
35
54
|
# Пользователи
|
@@ -97,26 +116,14 @@ devise_russian
|
|
97
116
|
|
98
117
|
Прописываем роуты:
|
99
118
|
|
100
|
-
|
101
|
-
:path => "auth",
|
102
|
-
:path_names => {
|
103
|
-
:sign_in => "login",
|
104
|
-
:sign_out => "logout",
|
105
|
-
:sign_up => "register"
|
106
|
-
},
|
107
|
-
:controllers => {
|
108
|
-
:registrations => "registrations"
|
109
|
-
}
|
119
|
+
config/routes.rb:
|
110
120
|
|
111
|
-
|
112
|
-
resources :authentications, :only => [:index, :create, :destroy]
|
113
|
-
|
114
|
-
# Вход через социальные сети
|
115
|
-
match "/auth/:provider/callback", :to => "authentications#create"
|
116
|
-
match "/auth/failure", :to => "authentications#failure"
|
121
|
+
mount DeviseRussian::Engine => "/auth", :as => "devise_russian"
|
117
122
|
|
118
123
|
Подключаем девайс и русский девайс в модели:
|
119
124
|
|
125
|
+
app/models/user.rb:
|
126
|
+
|
120
127
|
# Devise
|
121
128
|
devise :database_authenticatable,
|
122
129
|
:confirmable,
|
@@ -129,6 +136,25 @@ devise_russian
|
|
129
136
|
# Russian Devise
|
130
137
|
omniauthable
|
131
138
|
|
139
|
+
class << self
|
140
|
+
...
|
141
|
+
# Вывод списка провайдеров на странице входа
|
142
|
+
def omniauth_enabled
|
143
|
+
false
|
144
|
+
end
|
145
|
+
...
|
146
|
+
end
|
147
|
+
|
148
|
+
Прописывем название и адрес сайта для подвала писем от Devise:
|
149
|
+
|
150
|
+
ru:
|
151
|
+
devise_russian:
|
152
|
+
my_authentications: Мои авторизации
|
153
|
+
authentication_not_found: Авторизация не найдена
|
154
|
+
mailer:
|
155
|
+
site_name: Мега-портал
|
156
|
+
site_url: "http://www.portal.ru"
|
157
|
+
|
132
158
|
Ссылки на вход и регистрацию:
|
133
159
|
|
134
160
|
<ul>
|
@@ -136,6 +162,4 @@ devise_russian
|
|
136
162
|
<li><a href="/auth/register">Регистрация</a></li>
|
137
163
|
</ul>
|
138
164
|
|
139
|
-
Ну и так
|
140
|
-
|
141
|
-
## P.S.: Поддержку не оказываю, включайте голову.
|
165
|
+
Ну и так далее. Настраивайте под себя!
|
@@ -3,7 +3,7 @@ class AuthenticationsController < DeviseController
|
|
3
3
|
before_filter :authenticate_user!, :except => [:create, :failure]
|
4
4
|
|
5
5
|
def index
|
6
|
-
@meta_title = "
|
6
|
+
@meta_title = I18n.t("devise_russian.my_authentications")
|
7
7
|
@authentications = current_user.authentications
|
8
8
|
end
|
9
9
|
|
@@ -38,13 +38,13 @@ class AuthenticationsController < DeviseController
|
|
38
38
|
flash[:notice] = I18n.t("devise.sessions.signed_out")
|
39
39
|
redirect_to authentications_url
|
40
40
|
else
|
41
|
-
flash[:error] = "
|
41
|
+
flash[:error] = I18n.t("devise_russian.authentication_not_found")
|
42
42
|
redirect_to "/"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def failure
|
47
|
-
redirect_to new_user_session_url
|
47
|
+
redirect_to devise_russian.new_user_session_url
|
48
48
|
end
|
49
49
|
|
50
50
|
def devise_mapping
|
@@ -1,35 +1,22 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
class Authentication < ActiveRecord::Base
|
3
|
-
attr_accessible :user_id, :provider, :uid, :name, :email
|
4
3
|
validates_presence_of :provider, :uid
|
4
|
+
attr_accessible :user_id, :provider, :uid, :name, :email
|
5
|
+
|
5
6
|
belongs_to :user
|
6
7
|
|
7
8
|
xss_terminate
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def self.providers
|
21
|
-
[
|
22
|
-
['facebook', 'Facebook'],
|
23
|
-
['vkontakte', 'Vkontakte'],
|
24
|
-
['odnoklassniki', 'Odnoklassniki']
|
25
|
-
]
|
26
|
-
end
|
27
|
-
|
28
|
-
def provider_name
|
29
|
-
if provider == 'open_id'
|
30
|
-
"OpenID"
|
31
|
-
else
|
32
|
-
provider.titleize
|
10
|
+
class << self
|
11
|
+
def providers
|
12
|
+
[
|
13
|
+
["facebook", "Facebook"],
|
14
|
+
["vkontakte", "Vkontakte"],
|
15
|
+
["odnoklassniki", "Odnoklassniki"]
|
16
|
+
# ['twitter', 'Twitter'],
|
17
|
+
# ['github', 'Github'],
|
18
|
+
# ['google_oauth2', 'Google']
|
19
|
+
]
|
33
20
|
end
|
34
21
|
end
|
35
22
|
end
|
@@ -2,5 +2,5 @@
|
|
2
2
|
<p>Кто-то отправил запрос на смену пароля. Вы можете сменить пароль, перейдя по ссылке ниже.</p>
|
3
3
|
<p><%= link_to 'Сменить пароль', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
|
4
4
|
<p>Если вы не посылали запрос, то просто проигнорируйте это письмо.</p>
|
5
|
-
<p>Ваш
|
5
|
+
<p>Ваш пароль останется прежним, пока вы не перейдете по указанной выше ссылке и не укажете новый.</p>
|
6
6
|
<%= render "bottom" %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
DeviseRussian::Engine.routes.draw do
|
3
|
+
devise_for :users, {
|
4
|
+
:module => :devise,
|
5
|
+
:path => "",
|
6
|
+
:path_names => {
|
7
|
+
:sign_in => "login",
|
8
|
+
:sign_out => "logout",
|
9
|
+
:sign_up => "register"
|
10
|
+
},
|
11
|
+
:controllers => {
|
12
|
+
:registrations => "registrations"
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
# Авторизации пользователя
|
17
|
+
resources :authentications, :only => [:index, :create, :destroy]
|
18
|
+
|
19
|
+
# Вход через социальные сети
|
20
|
+
match "/:provider/callback", :to => "authentications#create"
|
21
|
+
match "/failure", :to => "authentications#failure"
|
22
|
+
end
|
data/devise_russian.gemspec
CHANGED
@@ -17,7 +17,9 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
+
gem.add_dependency "xss_terminate", ">= 0.2"
|
20
21
|
gem.add_dependency "devise", ">= 2.2.3"
|
21
22
|
gem.add_dependency "omniauth", ">= 1.1.3"
|
22
23
|
gem.add_dependency "omniauth-oauth2", ">= 1.1.1"
|
24
|
+
gem.add_dependency "useful_helpers", ">= 0.0.1"
|
23
25
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module DeviseRussian
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
isolate_namespace DeviseRussian
|
4
|
-
engine_name
|
4
|
+
engine_name "devise_russian"
|
5
5
|
|
6
6
|
initializer "devise_russian.includers" do |app|
|
7
|
-
# ActionController::Base.send :include, DeviseRussian::Controllers::Base
|
8
7
|
ActiveRecord::Base.send :include, DeviseRussian::Models::Base
|
9
8
|
end
|
10
9
|
end
|
@@ -9,6 +9,11 @@ module DeviseRussian
|
|
9
9
|
module ClassMethods
|
10
10
|
def omniauthable
|
11
11
|
has_many :authentications, :dependent => :destroy
|
12
|
+
|
13
|
+
def ommiauth_enabled
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
12
17
|
unless included_modules.include? InstanceMethods
|
13
18
|
include InstanceMethods
|
14
19
|
end
|
@@ -22,18 +27,12 @@ module DeviseRussian
|
|
22
27
|
user_email = omniauth['extra']['raw_info']['email'] rescue nil
|
23
28
|
user_name = omniauth['extra']['raw_info']['first_name'] rescue nil
|
24
29
|
|
25
|
-
# Facebook omniauth: #<OmniAuth::AuthHash credentials=#<Hashie::Mash expires=true expires_at=1368497603 token="AAAHyrzX1f8gBAEZBgtqQZCcLHgRDMbioJ6cltTxqTd3qlnvY1JXAtOivUKu8DzVfKf3f2x7ZCbZAF6qciuww2qVGVrFq6yoVxwZCHPZCn0HgZDZD"> extra=#<Hashie::Mash raw_info=#<Hashie::Mash email="lapida@ya.ru" first_name="Lipada" gender="male" hometown=#<Hashie::Mash id="111803002172556" name="Tomsk, Russia"> id="100005327070305" last_name="Ru" link="http://www.facebook.com/profile.php?id=100005327070305" locale="ru_RU" name="Lipada Ru" timezone=7 updated_time="2013-02-20T15:25:45+0000" verified=true>> info=#<OmniAuth::AuthHash::InfoHash email="lapida@ya.ru" first_name="Lipada" image="http://graph.facebook.com/100005327070305/picture?type=square" last_name="Ru" name="Lipada Ru" urls=#<Hashie::Mash Facebook="http://www.facebook.com/profile.php?id=100005327070305"> verified=true> provider="facebook" uid="100005327070305">
|
26
|
-
|
27
|
-
# Vkontakte omniauth: #<OmniAuth::AuthHash credentials=#<Hashie::Mash expires=true expires_at=1363456283 token="46de998d8c438603e0d92af694d47744260b89f1e493ffa2403c41ca98aaf9a26aae375a384e0817711c5"> extra=#<Hashie::Mash raw_info=#<Hashie::Mash city="144" country="1" first_name="Lipada" last_name="Ru" nickname="" online=0 photo="https://vk.com/images/camera_c.gif" photo_big="https://vk.com/images/camera_a.gif" screen_name="id201853841" sex=2 uid=201853841>> info=#<OmniAuth::AuthHash::InfoHash first_name="Lipada" image="https://vk.com/images/camera_c.gif" last_name="Ru" location="Россия, Томск" name="Lipada Ru" nickname="" urls=#<Hashie::Mash Vkontakte="http://vk.com/id201853841">> provider="vkontakte" uid=201853841>
|
28
|
-
|
29
|
-
# Odnoklassniki omniauth: #<OmniAuth::AuthHash credentials=#<Hashie::Mash expires=false token="2aipa.2-71160004l6v6h3r406y3k6bsrv9"> extra=#<Hashie::Mash raw_info=#<Hashie::Mash age=25 birthday="1987-07-14" first_name="Lipada" gender="male" has_email=true last_name="ru" locale="ru" location=#<Hashie::Mash city="Томск" country="RUSSIAN_FEDERATION"> name="Lipada ru" online="web" pic_1="http://i503.odnoklassniki.ru/res/stub_50x50.gif" pic_2="http://usd8.odnoklassniki.ru/res/stub_128x96.gif" uid="555839750549">> info=#<OmniAuth::AuthHash::InfoHash first_name="Lipada" image="http://i503.odnoklassniki.ru/res/stub_50x50.gif" last_name="ru" name="Lipada ru" urls=#<Hashie::Mash Odnoklassniki="http://www.odnoklassniki.ru/profile/555839750549">> provider="odnoklassniki" uid="555839750549">
|
30
|
-
|
31
30
|
if with_self
|
32
31
|
self.email = user_email if user_email && self.email.blank?
|
33
32
|
self.name = user_name if user_name && self.name.blank?
|
34
33
|
end
|
35
34
|
|
36
|
-
self.authentications.
|
35
|
+
self.authentications.new(
|
37
36
|
:provider => provider,
|
38
37
|
:uid => uid,
|
39
38
|
:email => user_email,
|
data/lib/devise_russian.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_russian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.21
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: xss_terminate
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.2'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: devise
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,6 +75,22 @@ dependencies:
|
|
59
75
|
- - ! '>='
|
60
76
|
- !ruby/object:Gem::Version
|
61
77
|
version: 1.1.1
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: useful_helpers
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.0.1
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.0.1
|
62
94
|
description: Часто используемые наработки по джему Devise. Включает решение по авторизации
|
63
95
|
в социальных сетях
|
64
96
|
email:
|
@@ -174,7 +206,10 @@ files:
|
|
174
206
|
- app/views/devise/shared/_social_links.html.erb
|
175
207
|
- app/views/devise/unlocks/new.html.erb
|
176
208
|
- config/ca-bundle.crt
|
209
|
+
- config/initializers/devise.rb
|
177
210
|
- config/locales/devise.ru.yml
|
211
|
+
- config/locales/devise_russian.ru.yml
|
212
|
+
- config/routes.rb
|
178
213
|
- devise_russian.gemspec
|
179
214
|
- lib/devise_russian.rb
|
180
215
|
- lib/devise_russian/engine.rb
|