diff --git a/app/assets/javascripts/settings.coffee b/app/assets/javascripts/settings.coffee index b7c3e3c..2e94a48 100644 --- a/app/assets/javascripts/settings.coffee +++ b/app/assets/javascripts/settings.coffee @@ -22,7 +22,8 @@ class window.Settings if window.lastfm_popup.closed _session.query '/user/auth', {}, (ar) -> _session.setUser ar.user - _settings.loadFormData 'lastfm' + $('#lastfm_username').val(ar.user.lastfm_username) + $('.lastfm-connect').hide() else setTimeout _settings.updateLastfmLogin, 100 false @@ -41,7 +42,7 @@ $('#settings-tabs li').live 'click', -> false $('.lastfm-connect').live 'click', -> - window.lastfm_popup = window.open _session.getUser().lastfm_login_url + window.lastfm_popup = window.open _session.getUser().lastfm_login_url, "lastfm_popup", "status=1,width=960,height=585" setTimeout _settings.updateLastfmLogin, 100 false diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 4f13538..fd4338a 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -22,12 +22,10 @@ class UserController < ApplicationController :email => user.email, :vkid => user.vkid, :lang => user.lang, - :lastfm_username => user.lastfm_username + :lastfm_username => user.lastfm_username, + :lastfm_login_url => 'http://www.last.fm/api/auth?api_key=' << LastFmController.api_key << + '&cb=http://' << request.host << ':' << request.port.to_s << '/lastfm/connect/?sid=' << user.session.key } - unless user.lastfm_username - @res[:lastfm_login_url] = 'http://www.last.fm/api/auth?api_key='+ LastFmController.api_key + - '&cb=http://'+ request.host << '/lastfm/connect/?sid='+ user.session.key - end render :json => @res end @@ -44,17 +42,19 @@ class UserController < ApplicationController @res = {} user = User.find_by_vkid(params[:mid]) - update_params = {} - params[:params] = params[:params].each{ |k, v| update_params[k.to_sym] = v } - if (update_params.keys - allowed_params).empty? - if update_params.include? :show - update_params[:show] = update_params[:show].map{ |k, v| k.to_sym } - end + unless params[:params].nil? + update_params = {} + params[:params] = params[:params].each{ |k, v| update_params[k.to_sym] = v } + if (update_params.keys - allowed_params).empty? + if update_params.include? :show + update_params[:show] = update_params[:show].map{ |k, v| k.to_sym } + end - params[:params].each do |k, v| - user[k] = v + params[:params].each do |k, v| + user[k] = v + end + user.save end - user.save end @res[:user] = { @@ -63,12 +63,10 @@ class UserController < ApplicationController :email => user.email, :vkid => user.vkid, :lang => user.lang, - :lastfm_username => user.lastfm_username + :lastfm_username => user.lastfm_username, + :lastfm_login_url => 'http://www.last.fm/api/auth?api_key=' << LastFmController.api_key << + '&cb=http://' << request.host << ':' << request.port.to_s << '/lastfm/connect/?sid=' << user.session.key } - unless user.lastfm_username - @res[:lastfm_login_url] = 'http://www.last.fm/api/auth?api_key='+ LastFmController.api_key + - '&cb=http://'+ request.host << '/lastfm/connect/?sid='+ user.session.key - end render :json => @res end diff --git a/app/views/user/_settings.html.haml b/app/views/user/_settings.html.haml index 7232201..c18c983 100644 --- a/app/views/user/_settings.html.haml +++ b/app/views/user/_settings.html.haml @@ -66,5 +66,6 @@ %label{ :for => "lastfm_username" }= I18n.t 'settings.username' .input %input.borderless#lastfm_username{ :type => "text", :readonly => "readonly", :value => (@user.lastfm_username || I18n.t('settings.not_connected')) } - %span.help-inline - %input.btn{ :type => "submit", :value => I18n.t('settings.connect') } + - unless @user.lastfm_username + %span.help-inline + %input.btn.lastfm-connect{ :type => "submit", :value => I18n.t('settings.connect') }