citygate 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +66 -1
- data/Rakefile +0 -1
- data/app/assets/javascripts/citygate/admin_users.coffee +1 -13
- data/app/assets/javascripts/citygate/application.js +3 -2
- data/app/assets/javascripts/citygate/jquery.pjax.js +688 -0
- data/app/controllers/citygate/admin/application_controller.rb +9 -1
- data/app/controllers/citygate/admin/users_controller.rb +1 -1
- data/app/controllers/citygate/application_controller.rb +2 -0
- data/app/controllers/citygate/users/omniauth_callbacks_controller.rb +10 -8
- data/app/controllers/citygate/users_controller.rb +2 -2
- data/app/models/citygate/user.rb +8 -1
- data/app/views/citygate/admin/users/index.html.erb +12 -1
- data/app/views/citygate/admin/users/show.html.erb +4 -2
- data/app/views/citygate/shared/_navigation.html.erb +2 -1
- data/app/views/citygate/users/show.html.erb +13 -2
- data/app/views/{citygate/devise → devise}/_links.erb +0 -0
- data/app/views/devise/registrations/edit.html.erb +32 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/layouts/admin/application.html.erb +1 -0
- data/config/accounts.yml +5 -0
- data/config/initializers/01_load_config.rb +1 -0
- data/config/initializers/devise.rb +22 -12
- data/config/routes.rb +9 -4
- data/lib/citygate/engine.rb +15 -1
- data/lib/citygate/version.rb +1 -1
- data/lib/gravatar.rb +8 -0
- metadata +67 -57
- data/app/assets/javascripts/citygate/global.coffee +0 -14
- data/app/views/citygate/admin/users/_user_show.html.erb +0 -2
- data/app/views/citygate/admin/users/_users.html.erb +0 -12
- data/app/views/citygate/admin/users/index.js.erb +0 -1
- data/app/views/citygate/admin/users/show.js.erb +0 -1
- data/app/views/citygate/devise/registrations/edit.html.haml +0 -31
@@ -1,13 +1,18 @@
|
|
1
|
+
# @author Zamith
|
2
|
+
# Encapsulates all the omniauth authorization logic
|
1
3
|
class Citygate::Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
2
4
|
|
5
|
+
# Authorize user with his facebook account
|
3
6
|
def facebook
|
4
7
|
oauthorize "Facebook"
|
5
8
|
end
|
6
9
|
|
10
|
+
# Authorize user with his google (openid) account
|
7
11
|
def google
|
8
12
|
oauthorize "Google"
|
9
13
|
end
|
10
14
|
|
15
|
+
# In case of error renders 404
|
11
16
|
def passthru
|
12
17
|
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
|
13
18
|
end
|
@@ -15,7 +20,8 @@ class Citygate::Users::OmniauthCallbacksController < Devise::OmniauthCallbacksCo
|
|
15
20
|
private
|
16
21
|
|
17
22
|
def oauthorize(kind)
|
18
|
-
|
23
|
+
current_user ||= (params[:user]) ? Citygate::User.find(params[:user]) : nil
|
24
|
+
@user = find_for_oauth(kind, request.env["omniauth.auth"], current_user)
|
19
25
|
if @user.persisted?
|
20
26
|
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => kind
|
21
27
|
session["devise.#{kind.downcase}_data"] = request.env["omniauth.auth"]
|
@@ -26,7 +32,7 @@ class Citygate::Users::OmniauthCallbacksController < Devise::OmniauthCallbacksCo
|
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
29
|
-
def
|
35
|
+
def find_for_oauth(provider, access_token, resource=nil)
|
30
36
|
user, email, name, uid, auth_attr = nil, nil, nil, {}
|
31
37
|
case provider
|
32
38
|
when "Facebook"
|
@@ -50,7 +56,7 @@ class Citygate::Users::OmniauthCallbacksController < Devise::OmniauthCallbacksCo
|
|
50
56
|
:name => access_token['info']['name'],
|
51
57
|
}
|
52
58
|
else
|
53
|
-
raise
|
59
|
+
raise "Provider #{provider} not handled"
|
54
60
|
end
|
55
61
|
if resource.nil?
|
56
62
|
if email
|
@@ -64,12 +70,8 @@ class Citygate::Users::OmniauthCallbacksController < Devise::OmniauthCallbacksCo
|
|
64
70
|
else
|
65
71
|
user = resource
|
66
72
|
end
|
67
|
-
|
68
73
|
auth = user.authorizations.find_by_provider(provider)
|
69
|
-
|
70
|
-
auth = user.authorizations.build(:provider => provider)
|
71
|
-
user.authorizations << auth
|
72
|
-
end
|
74
|
+
auth ||= user.authorizations.build(:provider => provider)
|
73
75
|
auth.update_attributes auth_attr
|
74
76
|
|
75
77
|
return user
|
@@ -1,7 +1,7 @@
|
|
1
|
-
class Citygate::UsersController < ApplicationController
|
1
|
+
class Citygate::UsersController < Citygate::ApplicationController
|
2
2
|
load_and_authorize_resource :class => "Citygate::User"
|
3
3
|
|
4
4
|
def show
|
5
|
-
@
|
5
|
+
@providers = Citygate::User.omniauth_providers
|
6
6
|
end
|
7
7
|
end
|
data/app/models/citygate/user.rb
CHANGED
@@ -20,7 +20,7 @@ module Citygate
|
|
20
20
|
has_many :authorizations, :dependent => :destroy
|
21
21
|
belongs_to :role
|
22
22
|
|
23
|
-
# Get the json object for an user
|
23
|
+
# Get the json object for an user. Used by to_json.
|
24
24
|
# @example
|
25
25
|
# {
|
26
26
|
# "email": "user@example.com",
|
@@ -28,6 +28,7 @@ module Citygate
|
|
28
28
|
# "link": null,
|
29
29
|
# "image": "https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png/rating=g"
|
30
30
|
# }
|
31
|
+
# @return [Hash] the json object in the form of an hash
|
31
32
|
def as_json(options = {})
|
32
33
|
authorization = self.authorizations.first
|
33
34
|
{
|
@@ -37,5 +38,11 @@ module Citygate
|
|
37
38
|
image: (authorization.image_url if authorization) || self.gravatar_url
|
38
39
|
}
|
39
40
|
end
|
41
|
+
|
42
|
+
# Get the name if it is present or else get the email
|
43
|
+
# @return [String] the name or email of the user
|
44
|
+
def name_or_email
|
45
|
+
self.name || self.email
|
46
|
+
end
|
40
47
|
end
|
41
48
|
end
|
@@ -1,3 +1,14 @@
|
|
1
1
|
<div id="users">
|
2
|
-
|
2
|
+
<% @users.each do |user| %>
|
3
|
+
<div class="user">
|
4
|
+
<span class="email"><%= user.email %></span>
|
5
|
+
<%= content_tag(:span, user.name) if user.name %>
|
6
|
+
<div class="user-links">
|
7
|
+
<%= link_to "Show", admin_user_path(user), :class => "show-link" %>
|
8
|
+
<%= link_to "Edit", edit_admin_user_path(user), :class => "edit-link" if can? :update, user %>
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
<% end %>
|
12
|
+
|
13
|
+
<%= will_paginate @users %>
|
3
14
|
</div>
|
@@ -1,5 +1,6 @@
|
|
1
1
|
<ul id="citygate-navigation">
|
2
2
|
<% if user_signed_in? %>
|
3
|
+
<li><%= link_to('Profile', profile_path) %></li>
|
3
4
|
<li><%= link_to('Edit account', edit_user_registration_path) %></li>
|
4
5
|
|
5
6
|
<li><%= link_to('Log out', destroy_user_session_path, :method=>'delete') %></li>
|
@@ -9,7 +10,7 @@
|
|
9
10
|
<li><%= link_to('Sign up', new_user_registration_path) %></li>
|
10
11
|
|
11
12
|
<% Citygate::User.omniauth_providers.each do |provider| %>
|
12
|
-
<li><%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(Citygate::User.new, provider) %></li>
|
13
|
+
<li><%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(Citygate::User.new, provider), :id => "#{provider.to_s}" %></li>
|
13
14
|
<% end -%>
|
14
15
|
<% end %>
|
15
16
|
|
@@ -1,3 +1,14 @@
|
|
1
|
-
<
|
1
|
+
<h2 class="name"><%= current_user.name_or_email %></h2>
|
2
2
|
|
3
|
-
<
|
3
|
+
<div id="social-accounts">
|
4
|
+
<% connected_providers = current_user.authorizations.map(&:provider) %>
|
5
|
+
|
6
|
+
<%= connected_providers %>
|
7
|
+
<% @providers.each do |provider| %>
|
8
|
+
<% class_str = "#{provider}-connect " %>
|
9
|
+
<% class_str += (connected_providers.include? provider.to_s.capitalize) ? "connected" : "can-connect" %>
|
10
|
+
<div class="<%= class_str %>" >
|
11
|
+
<%= link_to "#{provider.to_s.capitalize}", user_omniauth_authorize_path(provider,{user: current_user}) %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
</div>
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<h2>Edit Profile</h2>
|
2
|
+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
|
3
|
+
<%= devise_error_messages! %>
|
4
|
+
<p>
|
5
|
+
<%= f.label :name %>
|
6
|
+
<%= f.text_field :name %>
|
7
|
+
</p>
|
8
|
+
<p>
|
9
|
+
<%= f.label :email %>
|
10
|
+
<%= f.email_field :email %>
|
11
|
+
</p>
|
12
|
+
<p>
|
13
|
+
<%= f.label :password %>
|
14
|
+
<%= f.password_field :password %>
|
15
|
+
<p class="hint">(leave blank if you don't want to change it)</p>
|
16
|
+
</p>
|
17
|
+
<p>
|
18
|
+
<%= f.label :password_confirmation %>
|
19
|
+
<%= f.password_field :password_confirmation %>
|
20
|
+
</p>
|
21
|
+
<p>
|
22
|
+
<%= f.label :current_password %>
|
23
|
+
<%= f.password_field :current_password %>
|
24
|
+
<p class="hint">(we need your current password to confirm your changes)</p>
|
25
|
+
</p>
|
26
|
+
<p><%= f.submit "Update" %></p>
|
27
|
+
<% end %>
|
28
|
+
<h3>Cancel my account</h3>
|
29
|
+
<p>
|
30
|
+
Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>.
|
31
|
+
</p>
|
32
|
+
<%= link_to "Back", :back %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<h2>Sign up</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<div><%= f.label :email %><br />
|
7
|
+
<%= f.email_field :email %></div>
|
8
|
+
|
9
|
+
<div><%= f.label :password %><br />
|
10
|
+
<%= f.password_field :password %></div>
|
11
|
+
|
12
|
+
<div><%= f.label :password_confirmation %><br />
|
13
|
+
<%= f.password_field :password_confirmation %></div>
|
14
|
+
|
15
|
+
<div><%= f.submit "Sign up" %></div>
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
<%= render :partial => "devise/shared/links" %>
|
data/config/accounts.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ACCOUNTS = YAML.load_file("#{Citygate.root}/config/accounts.yml") unless Rails.env.test?
|
@@ -205,15 +205,27 @@ Devise.setup do |config|
|
|
205
205
|
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
206
206
|
# up on your models and hooks.
|
207
207
|
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
208
|
+
unless Rails.env.test?
|
209
|
+
config.omniauth :facebook, ACCOUNTS['facebook']['app_id'], ACCOUNTS['facebook']['app_secret'],
|
210
|
+
{ :scope => 'email, offline_access' }
|
211
|
+
|
212
|
+
require 'openid/store/filesystem'
|
213
|
+
config.omniauth :open_id,
|
214
|
+
:store => OpenID::Store::Filesystem.new('/tmp'),
|
215
|
+
:name => 'google',
|
216
|
+
:identifier => ACCOUNTS['google']['identifier'],
|
217
|
+
:require => 'omniauth-openid'
|
218
|
+
else
|
219
|
+
config.omniauth :facebook, "foo", "bar",
|
220
|
+
{ :scope => 'email, offline_access' }
|
221
|
+
|
222
|
+
require 'openid/store/filesystem'
|
223
|
+
config.omniauth :open_id,
|
224
|
+
:store => OpenID::Store::Filesystem.new('/tmp'),
|
225
|
+
:name => 'google',
|
226
|
+
:identifier => "foobar",
|
227
|
+
:require => 'omniauth-openid'
|
228
|
+
end
|
217
229
|
|
218
230
|
|
219
231
|
# ==> Warden configuration
|
@@ -225,7 +237,5 @@ Devise.setup do |config|
|
|
225
237
|
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
226
238
|
# end
|
227
239
|
|
228
|
-
|
229
|
-
config.router_name = :citygate
|
230
|
-
end
|
240
|
+
config.router_name = :citygate
|
231
241
|
end
|
data/config/routes.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
Citygate::Engine.routes.draw do
|
2
2
|
root :to => "home#index"
|
3
3
|
|
4
|
+
match "/user/profile" => "users#show", :as => "profile"
|
5
|
+
|
6
|
+
match '/confirm/:confirmation_token', :to => "devise/confirmations#show", :as => "user_confirm", :only_path => false
|
7
|
+
|
4
8
|
devise_for :users,
|
5
|
-
:controllers => {
|
9
|
+
:controllers => {
|
10
|
+
:omniauth_callbacks => "citygate/users/omniauth_callbacks"
|
11
|
+
},
|
6
12
|
:class_name => "Citygate::User",
|
7
13
|
:module => :devise
|
8
|
-
|
9
|
-
|
10
|
-
namespace "admin", constraints: { format: /(json|html|js| )/ } do
|
14
|
+
|
15
|
+
namespace "admin", constraints: { format: /(json|html| )/ } do
|
11
16
|
resources :users
|
12
17
|
end
|
13
18
|
|
data/lib/citygate/engine.rb
CHANGED
@@ -2,7 +2,6 @@ require "rails"
|
|
2
2
|
|
3
3
|
require "rubygems"
|
4
4
|
require "devise"
|
5
|
-
require "devise"
|
6
5
|
require "devise_invitable"
|
7
6
|
require "devise-encryptable"
|
8
7
|
require 'omniauth'
|
@@ -12,6 +11,9 @@ require 'uuidtools'
|
|
12
11
|
require 'will_paginate'
|
13
12
|
require 'cancan'
|
14
13
|
|
14
|
+
# Make Devise "see" the changes made in the citygate appilication controller
|
15
|
+
Devise.parent_controller = "Citygate::ApplicationController"
|
16
|
+
|
15
17
|
module Citygate
|
16
18
|
def self.root
|
17
19
|
File.expand_path '../../..', __FILE__
|
@@ -19,5 +21,17 @@ module Citygate
|
|
19
21
|
|
20
22
|
class Engine < ::Rails::Engine
|
21
23
|
isolate_namespace Citygate
|
24
|
+
|
25
|
+
mattr_accessor :will_paginate_options
|
26
|
+
@@will_paginate_options = {per_page: 1}
|
27
|
+
|
28
|
+
mattr_accessor :mount_path
|
29
|
+
@@mount_path = ""
|
30
|
+
|
31
|
+
def configure
|
32
|
+
yield self
|
33
|
+
end
|
22
34
|
end
|
23
35
|
end
|
36
|
+
|
37
|
+
|
data/lib/citygate/version.rb
CHANGED
data/lib/gravatar.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
require 'digest/md5'
|
2
2
|
|
3
|
+
# @author Zamith
|
4
|
+
# This module provides helper methods to be include in a class which has an email
|
5
|
+
# such as User
|
3
6
|
module Gravatar
|
4
7
|
|
8
|
+
# Generates the gravatar id from the object's email
|
9
|
+
# @return [String] gravatar id
|
5
10
|
def gravatar_id
|
6
11
|
Digest::MD5.hexdigest(self.email.to_s.downcase)
|
7
12
|
end
|
8
13
|
|
14
|
+
# Generates the full gravatar url for the user (always uses https)
|
15
|
+
# @param [Hash] options The only available option is the avatar rating you which to fetch
|
16
|
+
# @return [String] gravatar url
|
9
17
|
def gravatar_url(options = { rating: 'g'})
|
10
18
|
"https://secure.gravatar.com/avatar/#{self.gravatar_id}.png/rating=#{options[:rating]}"
|
11
19
|
end
|