diff --git a/app/assets/javascripts/app/controllers/login.js.coffee b/app/assets/javascripts/app/controllers/login.js.coffee index aff9c0736..b5b841719 100644 --- a/app/assets/javascripts/app/controllers/login.js.coffee +++ b/app/assets/javascripts/app/controllers/login.js.coffee @@ -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 diff --git a/app/assets/javascripts/app/lib/app_post/auth.js.coffee b/app/assets/javascripts/app/lib/app_post/auth.js.coffee index a70f0d846..d6cf4c855 100644 --- a/app/assets/javascripts/app/lib/app_post/auth.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/auth.js.coffee @@ -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') \ No newline at end of file diff --git a/app/assets/javascripts/app/views/profile/linked_accounts.jst.eco b/app/assets/javascripts/app/views/profile/linked_accounts.jst.eco index ea55f0b7a..74a5cde8b 100644 --- a/app/assets/javascripts/app/views/profile/linked_accounts.jst.eco +++ b/app/assets/javascripts/app/views/profile/linked_accounts.jst.eco @@ -1,6 +1,6 @@

<%- @T( 'Link Accounts' ) %>

+ <% for auth_provider in @auth_providers: %> +
  • <%- @T( auth_provider.name ) %> <% if !@user['accounts'] || !@user['accounts'][auth_provider.key]: %><%- @T('Add') %><% else: %>"<%= @user['accounts'][auth_provider.key]['username'] %>" <%- @T('Remove') %><% end %>
  • + <% end %> + \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 71ff4dc0f..84401339e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/models/authorization.rb b/app/models/authorization.rb index 79d2572ca..2885f222a 100644 --- a/app/models/authorization.rb +++ b/app/models/authorization.rb @@ -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 \ No newline at end of file diff --git a/config/routes/user.rb b/config/routes/user.rb index 17373fa96..dba6b6997 100644 --- a/config/routes/user.rb +++ b/config/routes/user.rb @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index e77744220..efd5bf8a2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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 )