Added support for link/unlick external auth sources.

This commit is contained in:
Martin Edenhofer 2013-02-12 23:37:04 +01:00
parent c960acda8e
commit cfc81477da
7 changed files with 74 additions and 14 deletions

View file

@ -1,5 +1,3 @@
$ = jQuery.sub()
class Index extends App.Controller
events:
'submit #login': 'login',
@ -39,8 +37,8 @@ class Index extends App.Controller
auth_providers.push provider
@html App.view('login')(
item: data,
auth_providers: auth_providers,
item: data
auth_providers: auth_providers
)
# set focus

View file

@ -113,7 +113,7 @@ class App.Auth
@_logout: (data) ->
App.Log.log 'Auth', 'notice', '_logout'
# update websocked auth info
# update websocket auth info
App.WebSocket.auth()
# clear store
@ -125,8 +125,8 @@ class App.Auth
# empty session
App.Session.init()
# clear store
App.Store.clear('all')
# update websocked auth info
App.WebSocket.auth()
# clear store
App.Store.clear('all')

View file

@ -1,6 +1,6 @@
<h2><%- @T( 'Link Accounts' ) %></h2>
<ul>
<li><a href="/auth/twitter">twitter</a></li>
<li><a href="/auth/facebook">facebook</a></li>
<li><a href="/auth/linked_in">linkedin</a></li>
</ul>
<% for auth_provider in @auth_providers: %>
<li><%- @T( auth_provider.name ) %> <% if !@user['accounts'] || !@user['accounts'][auth_provider.key]: %><a href="<%= auth_provider.url %>"><%- @T('Add') %></a><% else: %>"<%= @user['accounts'][auth_provider.key]['username'] %>" <a href="#" data-uid="<%= @user['accounts'][auth_provider.key]['uid'] %>" data-provider="<%= auth_provider.key %>" data-type="remove"><%- @T('Remove') %></a><% end %></li>
<% end %>
</ul>

View file

@ -454,4 +454,56 @@ curl http://localhost/api/users/preferences.json -v -u #{login}:#{password} -H "
render :json => { :message => 'ok' }, :status => :ok
end
=begin
Resource:
DELETE /api/users/account.json
Payload:
{
"provider": "twitter",
"uid": 581482342942
}
Response:
{
:message => 'ok'
}
Test:
curl http://localhost/api/users/account.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"provider": "twitter", "uid": 581482342942}'
=end
def account_remove
if !current_user
render :json => { :message => 'No current user!' }, :status => :unprocessable_entity
return
end
# provider + uid to remove
if !params[:provider]
render :json => { :message => 'provider needed!' }, :status => :unprocessable_entity
return
end
if !params[:uid]
render :json => { :message => 'uid needed!' }, :status => :unprocessable_entity
return
end
# remove from database
record = Authorization.where(
:user_id => current_user.id,
:provider => params[:provider],
:uid => params[:uid],
)
if !record.first
render :json => { :message => 'No record found!' }, :status => :unprocessable_entity
return
end
record.destroy_all
render :json => { :message => 'ok' }, :status => :ok
end
end

View file

@ -1,8 +1,11 @@
class Authorization < ApplicationModel
belongs_to :user
after_create :delete_user_cache
after_update :delete_user_cache
after_destroy :delete_user_cache
validates_presence_of :user_id, :uid, :provider
validates_uniqueness_of :uid, :scope => :provider
def self.find_from_hash(hash)
auth = Authorization.where( :provider => hash['provider'], :uid => hash['uid'] ).first
if auth
@ -55,4 +58,10 @@ class Authorization < ApplicationModel
)
return auth
end
private
def delete_user_cache
self.user.cache_delete
end
end

View file

@ -7,6 +7,7 @@ module ExtraRoutes
map.match '/api/users/password_reset_verify', :to => 'users#password_reset_verify', :via => :post
map.match '/api/users/password_change', :to => 'users#password_change', :via => :post
map.match '/api/users/preferences', :to => 'users#preferences', :via => :put
map.match '/api/users/account', :to => 'users#account_remove', :via => :delete
map.match '/api/users', :to => 'users#index', :via => :get
map.match '/api/users/:id', :to => 'users#show', :via => :get
map.match '/api/users', :to => 'users#create', :via => :post

View file

@ -1745,7 +1745,7 @@ Translation.create_if_not_exists( :locale => 'de', :source => "Week", :target =>
Translation.create_if_not_exists( :locale => 'de', :source => "Follow up possible", :target => "Nachfrage möglich", :updated_by_id => 1, :created_by_id => 1 )
Translation.create_if_not_exists( :locale => 'de', :source => "Assign Follow Ups", :target => "Zuweisung bei Nachfrage", :updated_by_id => 1, :created_by_id => 1 )
Translation.create_if_not_exists( :locale => 'de', :source => "Signature", :target => "Signatur", :updated_by_id => 1, :created_by_id => 1 )
Translation.create_if_not_exists( :locale => 'de', :source => "Change your password.", :target => "Ändern Sie Ihr Passwort.", :updated_by_id => 1, :created_by_id => 1 )
Translation.create_if_not_exists( :locale => 'de', :source => "Change your password", :target => "Ändern Sie Ihr Passwort", :updated_by_id => 1, :created_by_id => 1 )
Translation.create_if_not_exists( :locale => 'de', :source => "Current Password", :target => "Aktuelles Passwort", :updated_by_id => 1, :created_by_id => 1 )
Translation.create_if_not_exists( :locale => 'de', :source => "New Password", :target => "Neues Passwort", :updated_by_id => 1, :created_by_id => 1 )
Translation.create_if_not_exists( :locale => 'de', :source => "New Password (confirm)", :target => "Neues Passwort (bestätigen)", :updated_by_id => 1, :created_by_id => 1 )