devise_russian 0.0.1 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/README.md +116 -1
  2. data/app/assets/images/sc/.directory +3 -0
  3. data/app/assets/images/sc/64/.directory +3 -0
  4. data/app/assets/images/sc/64/afisha.png +0 -0
  5. data/app/assets/images/sc/64/blogger.png +0 -0
  6. data/app/assets/images/sc/64/blogru.png +0 -0
  7. data/app/assets/images/sc/64/delicious.png +0 -0
  8. data/app/assets/images/sc/64/deviantart.png +0 -0
  9. data/app/assets/images/sc/64/digg.png +0 -0
  10. data/app/assets/images/sc/64/facebook.png +0 -0
  11. data/app/assets/images/sc/64/feed.png +0 -0
  12. data/app/assets/images/sc/64/flickr.png +0 -0
  13. data/app/assets/images/sc/64/formazon.png +0 -0
  14. data/app/assets/images/sc/64/friendfeed.png +0 -0
  15. data/app/assets/images/sc/64/friendster.png +0 -0
  16. data/app/assets/images/sc/64/furl.png +0 -0
  17. data/app/assets/images/sc/64/gglphone.png +0 -0
  18. data/app/assets/images/sc/64/gmail.png +0 -0
  19. data/app/assets/images/sc/64/google.png +0 -0
  20. data/app/assets/images/sc/64/habrahabr.png +0 -0
  21. data/app/assets/images/sc/64/icq.png +0 -0
  22. data/app/assets/images/sc/64/lastfm.png +0 -0
  23. data/app/assets/images/sc/64/linkedin.png +0 -0
  24. data/app/assets/images/sc/64/livejournal.png +0 -0
  25. data/app/assets/images/sc/64/magnolia.png +0 -0
  26. data/app/assets/images/sc/64/mailru.png +0 -0
  27. data/app/assets/images/sc/64/memori.png +0 -0
  28. data/app/assets/images/sc/64/mixx.png +0 -0
  29. data/app/assets/images/sc/64/moikrug.png +0 -0
  30. data/app/assets/images/sc/64/myspace.png +0 -0
  31. data/app/assets/images/sc/64/netvibes.png +0 -0
  32. data/app/assets/images/sc/64/newsvine.png +0 -0
  33. data/app/assets/images/sc/64/odnoklassniki.png +0 -0
  34. data/app/assets/images/sc/64/open_id.png +0 -0
  35. data/app/assets/images/sc/64/picasa.png +0 -0
  36. data/app/assets/images/sc/64/plurk.png +0 -0
  37. data/app/assets/images/sc/64/pownce.png +0 -0
  38. data/app/assets/images/sc/64/reddit.png +0 -0
  39. data/app/assets/images/sc/64/skype.png +0 -0
  40. data/app/assets/images/sc/64/stumbleupon.png +0 -0
  41. data/app/assets/images/sc/64/technorati.png +0 -0
  42. data/app/assets/images/sc/64/twitter.png +0 -0
  43. data/app/assets/images/sc/64/vimeo.png +0 -0
  44. data/app/assets/images/sc/64/vkontakte.png +0 -0
  45. data/app/assets/images/sc/64/webshots.png +0 -0
  46. data/app/assets/images/sc/64/wordpress.png +0 -0
  47. data/app/assets/images/sc/64/yahoo.png +0 -0
  48. data/app/assets/images/sc/64/yandex.png +0 -0
  49. data/app/assets/images/sc/64/yelp.png +0 -0
  50. data/app/assets/images/sc/64/you_tube.png +0 -0
  51. data/app/assets/images/sc/brand/facebook/facebook_128.png +0 -0
  52. data/app/assets/images/sc/brand/facebook/facebook_256.png +0 -0
  53. data/app/assets/images/sc/brand/facebook/facebook_32.png +0 -0
  54. data/app/assets/images/sc/brand/facebook/facebook_64.png +0 -0
  55. data/app/assets/images/sc/brand/github/github_128.png +0 -0
  56. data/app/assets/images/sc/brand/github/github_256.png +0 -0
  57. data/app/assets/images/sc/brand/github/github_32.png +0 -0
  58. data/app/assets/images/sc/brand/github/github_64.png +0 -0
  59. data/app/assets/images/sc/brand/google/google_128 copy.png +0 -0
  60. data/app/assets/images/sc/brand/google/google_128.png +0 -0
  61. data/app/assets/images/sc/brand/google/google_256 copy.png +0 -0
  62. data/app/assets/images/sc/brand/google/google_256.png +0 -0
  63. data/app/assets/images/sc/brand/google/google_32.png +0 -0
  64. data/app/assets/images/sc/brand/google/google_64 copy.png +0 -0
  65. data/app/assets/images/sc/brand/google/google_apps_32.png +0 -0
  66. data/app/assets/images/sc/brand/google/google_apps_64.png +0 -0
  67. data/app/assets/images/sc/brand/mailru/MailRuApi_32.png +0 -0
  68. data/app/assets/images/sc/brand/mailru/mailru-iphone.png +0 -0
  69. data/app/assets/images/sc/brand/mailru/mailru_64.png +0 -0
  70. data/app/assets/images/sc/brand/mailru/openid_128.png +0 -0
  71. data/app/assets/images/sc/brand/mailru/openid_256.png +0 -0
  72. data/app/assets/images/sc/brand/mailru/openid_32.png +0 -0
  73. data/app/assets/images/sc/brand/mailru/openid_64.png +0 -0
  74. data/app/assets/images/sc/brand/twitter/twitter_128.png +0 -0
  75. data/app/assets/images/sc/brand/twitter/twitter_256.png +0 -0
  76. data/app/assets/images/sc/brand/twitter/twitter_32.png +0 -0
  77. data/app/assets/images/sc/brand/twitter/twitter_64.png +0 -0
  78. data/app/assets/images/sc/brand/vkontakte/vkontakte_128.png +0 -0
  79. data/app/assets/images/sc/brand/vkontakte/vkontakte_256.png +0 -0
  80. data/app/assets/images/sc/brand/vkontakte/vkontakte_32.png +0 -0
  81. data/app/assets/images/sc/brand/vkontakte/vkontakte_64.png +0 -0
  82. data/app/assets/stylesheets/sc.css +12 -0
  83. data/app/controllers/authentications_controller.rb +66 -0
  84. data/app/controllers/registrations_controller.rb +31 -0
  85. data/app/models/authentication.rb +35 -0
  86. data/app/views/authentications/_collection.html.erb +37 -0
  87. data/app/views/authentications/index.html.erb +2 -0
  88. data/app/views/devise/confirmations/new.html.erb +11 -0
  89. data/app/views/devise/mailer/_bottom.html.erb +5 -0
  90. data/app/views/devise/mailer/confirmation_instructions.html.erb +4 -0
  91. data/app/views/devise/mailer/reset_password_instructions.html.erb +6 -0
  92. data/app/views/devise/mailer/unlock_instructions.html.erb +5 -0
  93. data/app/views/devise/passwords/edit.html.erb +14 -0
  94. data/app/views/devise/passwords/new.html.erb +11 -0
  95. data/app/views/devise/registrations/edit.html.erb +18 -0
  96. data/app/views/devise/registrations/new.html.erb +19 -0
  97. data/app/views/devise/sessions/new.html.erb +16 -0
  98. data/app/views/devise/shared/_links.erb +17 -0
  99. data/app/views/devise/shared/_social_links.html.erb +10 -0
  100. data/app/views/devise/unlocks/new.html.erb +11 -0
  101. data/config/ca-bundle.crt +5182 -0
  102. data/config/locales/devise.ru.yml +41 -0
  103. data/devise_russian.gemspec +2 -0
  104. data/lib/devise_russian/engine.rb +11 -0
  105. data/lib/devise_russian/models/base.rb +50 -0
  106. data/lib/devise_russian/version.rb +1 -1
  107. data/lib/devise_russian.rb +3 -4
  108. metadata +137 -2
data/README.md CHANGED
@@ -1,4 +1,119 @@
1
1
  devise_russian
2
2
  ==============
3
3
 
4
- Часто используемые наработки по джему Devise для авторизации. Включает решение по авторизации в социальных сетях
4
+ Часто используемые наработки по джему Devise для авторизации. Включает решение по авторизации в социальных сетях
5
+
6
+ ## Установка
7
+
8
+ Ставим джемы:
9
+
10
+ gem "devise"
11
+ gem "devise_russian"
12
+
13
+ Миграции:
14
+
15
+ # Пользователи
16
+ create_table :users do |t|
17
+
18
+ t.datetime :deleted_at # Дата удаления
19
+
20
+ # Основная информация
21
+ t.string :name # Имя
22
+ t.string :role # Роль
23
+ t.decimal :balance, :precision => 10, :scale => 4, :null => false, :default => 0
24
+
25
+ ## Database authenticatable
26
+ t.string :email, :null => false, :default => ""
27
+ t.string :encrypted_password, :null => false, :default => ""
28
+
29
+ ## Recoverable
30
+ t.string :reset_password_token
31
+ t.datetime :reset_password_sent_at
32
+
33
+ ## Rememberable
34
+ t.datetime :remember_created_at
35
+
36
+ ## Trackable
37
+ t.integer :sign_in_count, :default => 0
38
+ t.datetime :current_sign_in_at
39
+ t.datetime :last_sign_in_at
40
+ t.string :current_sign_in_ip
41
+ t.string :last_sign_in_ip
42
+
43
+ ## Confirmable
44
+ t.string :confirmation_token
45
+ t.datetime :confirmed_at
46
+ t.datetime :confirmation_sent_at
47
+ t.string :unconfirmed_email # Only if using reconfirmable
48
+
49
+ ## Lockable
50
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
51
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
52
+ # t.datetime :locked_at
53
+
54
+ ## Token authenticatable
55
+ # t.string :authentication_token
56
+
57
+ t.timestamps
58
+ end
59
+
60
+ add_index :users, :email, :unique => true
61
+ add_index :users, :reset_password_token, :unique => true
62
+ add_index :users, :confirmation_token, :unique => true
63
+ # add_index :users, :unlock_token, :unique => true
64
+ # add_index :users, :authentication_token, :unique => true
65
+
66
+ # Авторизации
67
+ create_table :authentications do |t|
68
+ t.integer :user_id
69
+ t.string :provider
70
+ t.string :uid
71
+ t.string :email
72
+ t.string :name
73
+ t.timestamps
74
+ end
75
+
76
+ add_index :authentications, :user_id
77
+
78
+ Прописываем роуты:
79
+
80
+ devise_for :users,
81
+ :path => "auth",
82
+ :path_names => {
83
+ :sign_in => "login",
84
+ :sign_out => "logout",
85
+ :sign_up => "register"
86
+ },
87
+ :controllers => {
88
+ :registrations => "registrations"
89
+ }
90
+
91
+ # Авторизации пользователя
92
+ resources :authentications, :only => [:index, :create, :destroy]
93
+
94
+ # Вход через социальные сети
95
+ match "/auth/:provider/callback", :to => "authentications#create"
96
+ match "/auth/failure", :to => "authentications#failure"
97
+
98
+ Подключаем девайс и русский девайс в модели:
99
+
100
+ # Devise
101
+ devise :database_authenticatable,
102
+ :confirmable,
103
+ :registerable,
104
+ :recoverable,
105
+ :rememberable,
106
+ :trackable,
107
+ :validatable
108
+
109
+ # Russian Devise
110
+ omniauthable
111
+
112
+ Ссылки на вход и регистрацию:
113
+
114
+ <ul>
115
+ <li><a href="/auth/login">Вход</a></li>
116
+ <li><a href="/auth/register">Регистрация</a></li>
117
+ </ul>
118
+
119
+ Ну и так двлее. Настраивайте под себя!
@@ -0,0 +1,3 @@
1
+ [Dolphin]
2
+ ShowPreview=true
3
+ Timestamp=2011,7,3,23,29,42
@@ -0,0 +1,3 @@
1
+ [Dolphin]
2
+ ShowPreview=true
3
+ Timestamp=2011,7,3,23,45,17
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,12 @@
1
+ .sc {
2
+ margin:20px 0 20px 0;
3
+ display:block;
4
+ }
5
+
6
+ .sc a {
7
+ text-decoration:none;
8
+ }
9
+
10
+ .sc img {
11
+ margin-right:5px;
12
+ }
@@ -0,0 +1,66 @@
1
+ # coding: utf-8
2
+ class AuthenticationsController < DeviseController
3
+ before_filter :authenticate_user!, :except => [:create, :failure]
4
+
5
+ def index
6
+ @meta_title = "Мои авторизации"
7
+ @authentications = current_user.authentications
8
+ end
9
+
10
+ def create
11
+ omniauth = request.env["omniauth.auth"]
12
+ authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'].to_s)
13
+ if authentication
14
+ flash[:notice] = I18n.t("devise.sessions.signed_in")
15
+ sign_in_and_redirect(:user, authentication.user)
16
+ elsif current_user
17
+ current_user.apply_omniauth(omniauth, false)
18
+ current_user.save
19
+ flash[:notice] = I18n.t("devise.sessions.signed_already")
20
+ redirect_to authentications_url
21
+ else
22
+ @user = User.new
23
+ @user.apply_omniauth(omniauth, true)
24
+ if @user.save
25
+ flash[:notice] = I18n.t("devise.confirmations.send_instructions")
26
+ sign_in_and_redirect(:user, @user)
27
+ else
28
+ session[:omniauth] = omniauth.except('extra')
29
+ render :controller => "registrations", :template => "devise/registrations/new"
30
+ end
31
+ end
32
+ end
33
+
34
+ def destroy
35
+ @authentication = current_user.authentications.find_by_id(params[:id])
36
+ if @authentication
37
+ @authentication.destroy
38
+ flash[:notice] = I18n.t("devise.sessions.signed_out")
39
+ redirect_to authentications_url
40
+ else
41
+ flash[:error] = "Авторизация не найдена"
42
+ redirect_to "/"
43
+ end
44
+ end
45
+
46
+ def failure
47
+ redirect_to new_user_session_url #, :flash => {:error => "Не могу вас авторизовать: #{params[:message]}"}
48
+ end
49
+
50
+ def devise_mapping
51
+ @devise_mapping ||= Devise.mappings[:user]
52
+ end
53
+
54
+ protected
55
+
56
+ def authenticate_user!
57
+ permission_denied if current_user.nil?
58
+ end
59
+
60
+ # This is necessary since Rails 3.0.4
61
+ # See https://github.com/intridea/omniauth/issues/185
62
+ # and http://www.arailsdemo.com/posts/44
63
+ def handle_unverified_request
64
+ true
65
+ end
66
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ class RegistrationsController < Devise::RegistrationsController
3
+ def new
4
+ build_resource
5
+ render :new
6
+ end
7
+
8
+ def edit
9
+ redirect_to edit_dashboard_user_path
10
+ end
11
+
12
+ def create
13
+ build_resource
14
+ super
15
+ session[:omniauth] = nil unless @user.new_record?
16
+ end
17
+
18
+ private
19
+
20
+ def build_resource(*args)
21
+ super
22
+ if session[:omniauth]
23
+ @user.apply_omniauth(session[:omniauth])
24
+ @user.valid?
25
+ end
26
+ end
27
+
28
+ def after_update_path_for(scope)
29
+ session[:referrer] ? session[:referrer] : root_path
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ class Authentication < ActiveRecord::Base
3
+ attr_accessible :user_id, :provider, :uid, :name, :email
4
+ validates_presence_of :provider, :uid
5
+ belongs_to :user
6
+
7
+ xss_terminate
8
+
9
+ # PROVIDERS = [
10
+ # ['facebook', 'Facebook'],
11
+ # ['twitter', 'Twitter'],
12
+ # ['vkontakte','Vkontakte'],
13
+ # ['mailru','Mail.ru'],
14
+ # ['open_id','OpenID'],
15
+ # ['flickr','Flickr'],
16
+ # ['odnoklassniki','Odnoklassniki'],
17
+ # ['you_tube','YouTube']
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
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ <% if @authentications.size > 0 %>
2
+ <table class="authentications resource">
3
+ <thead>
4
+ <tr>
5
+ <th class="t-left">Провайдер</th>
6
+ <th>UID</th>
7
+ <th>Email</th>
8
+ <th>Имя</th>
9
+ <th>Управление</th>
10
+ </tr>
11
+ </thead>
12
+ <% @authentications.each do |authentication| %>
13
+ <tr>
14
+ <td class="t-left provider">
15
+ <img width="16" height="16" src="/assets/sc/64/<%= authentication.provider %>.png" alt="<%= authentication.provider %>" />
16
+ <div><%= authentication.provider.titleize %></div>
17
+ </td>
18
+ <td>
19
+ <%= authentication.uid %>
20
+ </td>
21
+ <td>
22
+ <%= truncate authentication.email, :length => 30 %>
23
+ </td>
24
+ <td>
25
+ <%= truncate authentication.name, :length => 30 %>
26
+ </td>
27
+ <td>
28
+ <%= link_to t("delete"), authentication, :confirm => t("shure"), :method => :delete, :class => "delete" %>
29
+ </td>
30
+ </tr>
31
+ <% end %>
32
+ </table>
33
+ <div class="clear"></div>
34
+ <% else %>
35
+ <p>Авторизаций не найдено.</p>
36
+ <% end %>
37
+ <%= render "devise/shared/social_links" %>
@@ -0,0 +1,2 @@
1
+ <% page_title "Мои авторизации" %>
2
+ <%= render "collection" %>
@@ -0,0 +1,11 @@
1
+ <% @meta_title = "Отправка инструкций по активации" %>
2
+ <% page_title "Отправка инструкций по активации" %>
3
+ <div class="ct-box">
4
+ <%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
5
+ <%= devise_error_messages! %>
6
+ <p><%= f.label :email %>
7
+ <%= f.email_field :email %></p>
8
+ <p><%= f.submit "Отправить" %></p>
9
+ <% end %>
10
+ <%= render :partial => "devise/shared/links" %>
11
+ </div>
@@ -0,0 +1,5 @@
1
+ <p>===</p>
2
+
3
+ <p>С уважением, администрация Доски объявлений Lipada</p>
4
+
5
+ <p>http://lipada.ru</p>
@@ -0,0 +1,4 @@
1
+ <p>Уважаемый <%= @resource.email %>!</p>
2
+ <p>Вы можете подтвердить ваш аккаунт по следующей ссылке:</p>
3
+ <p><%= link_to 'Подтвердить аккаунт', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
4
+ <%= render "bottom" %>
@@ -0,0 +1,6 @@
1
+ <p>Уважаемый <%= @resource.email %>!</p>
2
+ <p>Кто-то отправил запрос на смену пароля. Вы можете сменить пароль, перейдя по ссылке ниже.</p>
3
+ <p><%= link_to 'Сменить пароль', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
4
+ <p>Если вы не посылали запрос, то просто проигнорируйте это письмо.</p>
5
+ <p>Ваш парол останется прежним, пока вы не перейдете по указанной выше ссылке и не укажете новый.</p>
6
+ <%= render "bottom" %>
@@ -0,0 +1,5 @@
1
+ <p>Уважаемый <%= @resource.email %>!</p>
2
+ <p>Ваш аккаунт был заблокирован за превышение числа попыток входа.</p>
3
+ <p>Перейдите по следующей ссылке для разблокировки вашего аккаунта:</p>
4
+ <p><%= link_to 'Разблокировать аккаунт', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
5
+ <%= render "bottom" %>
@@ -0,0 +1,14 @@
1
+ <% @meta_title = "Смена пароля" %>
2
+ <% page_title "Смена пароля" %>
3
+ <div class="ct-box">
4
+ <%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
5
+ <%= devise_error_messages! %>
6
+ <%= f.hidden_field :reset_password_token %>
7
+ <p><%= f.label :password, "Новый пароль" %>
8
+ <%= f.password_field :password %></p>
9
+ <p><%= f.label :password_confirmation, "Подтвердить пароль" %>
10
+ <%= f.password_field :password_confirmation %></p>
11
+ <p><%= f.submit "Сменить пароль" %></p>
12
+ <% end %>
13
+ <%= render :partial => "devise/shared/links" %>
14
+ </div>
@@ -0,0 +1,11 @@
1
+ <% @meta_title = "Забыли пароль?" %>
2
+ <% page_title "Забыли пароль?" %>
3
+ <div class="ct-box">
4
+ <%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
5
+ <%= devise_error_messages! %>
6
+ <p><%= f.label :email %>
7
+ <%= f.email_field :email %></p>
8
+ <p><%= f.submit "Отправить инструкции" %></p>
9
+ <% end %>
10
+ <%= render :partial => "devise/shared/links" %>
11
+ </div>
@@ -0,0 +1,18 @@
1
+ <% @meta_title = "Редактировать профиль" %>
2
+ <% page_title "Редактировать профиль" %>
3
+ <div class="ct-box">
4
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
5
+ <%= devise_error_messages! %>
6
+ <p><%= f.label :email %>
7
+ <%= f.email_field :email %></p>
8
+ <p><%= f.label :password %> <i>(оставьте пустым, если не хотите менять)</i><br />
9
+ <%= f.password_field :password %></p>
10
+ <p><%= f.label :password_confirmation %>
11
+ <%= f.password_field :password_confirmation %></p>
12
+ <p><%= f.label :current_password %> <i>(введите текущий пароль, чтобы сохранить изменения)</i><br />
13
+ <%= f.password_field :current_password %></p>
14
+ <p><%= f.submit "Обновить" %></p>
15
+ <% end %>
16
+ <p>Или <%= link_to "удалить профиль", registration_path(resource_name), :confirm => t('sure?'), :method => :delete %>.</p>
17
+ <%= link_to "Назад", :back %>
18
+ </div>
@@ -0,0 +1,19 @@
1
+ <% @meta_title = "Регистрация" %>
2
+ <% page_title "Регистрация" %>
3
+ <div class="ct-box">
4
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
5
+ <%= devise_error_messages! %>
6
+ <p><%= f.label :email %><abbr title="Обязательный">*</abbr>
7
+ <%= f.email_field :email %></p>
8
+ <p><%= f.label :name %><abbr title="Обязательный">*</abbr>
9
+ <%= f.text_field :name %></p>
10
+ <% if resource.password_required? %>
11
+ <p><%= f.label :password %><abbr title="Обязательный">*</abbr>
12
+ <%= f.password_field :password %></p>
13
+ <p><%= f.label :password_confirmation %><abbr title="Обязательный">*</abbr>
14
+ <%= f.password_field :password_confirmation %></p>
15
+ <% end %>
16
+ <p class="submit"><%= f.submit "Отправить" %></p>
17
+ <% end %>
18
+ <%#= render :partial => "devise/shared/links" %>
19
+ </div>