1
0
Fork 0

Last.fm connect

This commit is contained in:
Gregory Eremin 2011-09-15 14:44:44 +04:00
parent afdd9885bf
commit 024f1d7af2
3 changed files with 23 additions and 23 deletions

View File

@ -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

View File

@ -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

View File

@ -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') }