Updated auth controll
This commit is contained in:
parent
08b04b781d
commit
295811c6de
|
@ -89,4 +89,8 @@ class LastFmController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
def self.api_key
|
||||
@@api_key
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,21 +2,29 @@ class UserController < ApplicationController
|
|||
|
||||
def auth
|
||||
return unless authorized?
|
||||
@res = {}
|
||||
|
||||
@res[:status] = 'hello'
|
||||
@res = {:status => 'hello', :newbie => false}
|
||||
user = User.find_by_vkid(params[:mid])
|
||||
if user.nil?
|
||||
user = User.new
|
||||
user.vkid = params[:mid]
|
||||
user.save
|
||||
@res[:newbie] = true
|
||||
end
|
||||
@res[:id] = user.id
|
||||
@res[:username] = user.name
|
||||
session = Session.find_or_create_by_user_id(user.id)
|
||||
session.key = Digest::SHA256.hexdigest(rand(99999999).to_s + user.id.to_s + rand(99999999).to_s)
|
||||
session.save
|
||||
|
||||
@res[:user] = {
|
||||
:id => user.id,
|
||||
:name => user.name,
|
||||
:email => user.email,
|
||||
:vkid => user.vkid,
|
||||
:lastfm_username => user.lastfm_username,
|
||||
:lastfm_login_url => 'http://www.last.fm/api/auth?api_key='+ LastFmController.api_key +
|
||||
'&cb=http://'+ request.host << '/lastfm/connect/?sid='+ user.session.key
|
||||
}
|
||||
|
||||
render :json => @res
|
||||
end
|
||||
|
||||
|
@ -30,8 +38,15 @@ class UserController < ApplicationController
|
|||
user.email = params[:email]
|
||||
user.save
|
||||
end
|
||||
@res[:username] = user.name
|
||||
@res[:email] = user.email
|
||||
@res[:user] = {
|
||||
:id => user.id,
|
||||
:name => user.name,
|
||||
:email => user.email,
|
||||
:vkid => user.vkid,
|
||||
:lastfm_username => user.lastfm_username,
|
||||
:lastfm_login_url => 'http://www.last.fm/api/auth?api_key='+ LastFmController.api_key +
|
||||
'&cb=http://'+ request.host << '/lastfm/connect/?sid='+ user.session.key
|
||||
}
|
||||
|
||||
render :json => @res
|
||||
end
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
width: 80px;
|
||||
height: 30px;
|
||||
z-index: 10;
|
||||
background: -moz-linear-gradient(left, rgba(34,34,34,0) 0%, rgba(34,34,34,1) 50%, rgba(34,34,34,1) 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(34,34,34,0)), color-stop(50%,rgba(34,34,34,1)), color-stop(100%,rgba(34,34,34,1))); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(left, rgba(34,34,34,0) 0%,rgba(34,34,34,1) 50%,rgba(34,34,34,1) 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(left, rgba(34,34,34,0) 0%,rgba(34,34,34,1) 50%,rgba(34,34,34,1) 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(left, rgba(34,34,34,0) 0%,rgba(34,34,34,1) 50%,rgba(34,34,34,1) 100%); /* IE10+ */
|
||||
background: -moz-linear-gradient(left, rgba(34,34,34,0) 0%, rgba(34,34,34,1) 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(34,34,34,0)), color-stop(100%,rgba(34,34,34,1))); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(left, rgba(34,34,34,0) 0%,rgba(34,34,34,1) 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(left, rgba(34,34,34,0) 0%,rgba(34,34,34,1) 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(left, rgba(34,34,34,0) 0%,rgba(34,34,34,1) 100%); /* IE10+ */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00222222', endColorstr='#222222',GradientType=1 ); /* IE6-9 */
|
||||
background: linear-gradient(left, rgba(34,34,34,0) 0%,rgba(34,34,34,1) 50%,rgba(34,34,34,1) 100%); /* W3C */
|
||||
background: linear-gradient(left, rgba(34,34,34,0) 0%,rgba(34,34,34,1) 100%); /* W3C */
|
||||
}
|
||||
#player .progress {
|
||||
width: 330px;
|
||||
|
|
|
@ -70,7 +70,7 @@ var Ajax = {
|
|||
} else if (Ajax.getAnchor() === '' || Ajax.getAnchor().match(/\/search\//)) {
|
||||
Ajax.loadSearchPage();
|
||||
} else if (Ajax.getAnchor().match(/\/settings\//)) {
|
||||
Ajax.loadSettingsPage();
|
||||
Ajax.loadSearchPage();
|
||||
} else {
|
||||
Ajax.load404Page();
|
||||
}
|
||||
|
|
|
@ -158,11 +158,15 @@ var Player = {
|
|||
},
|
||||
|
||||
updateNowListening: function(artist, album, track) {
|
||||
Session.query('/lastfm/listening?r='+ Math.random(), {'artist': artist, 'album': album, 'track': track})
|
||||
if (Settings.user.lastfm_username) {
|
||||
Session.query('/lastfm/listening?r='+ Math.random(), {'artist': artist, 'album': album, 'track': track});
|
||||
}
|
||||
},
|
||||
|
||||
scrobble: function(artist, album, track) {
|
||||
Session.query('/lastfm/scrobble?r='+ Math.random(), {'artist': artist, 'album': album, 'track': track})
|
||||
if (Settings.user.lastfm_username) {
|
||||
Session.query('/lastfm/scrobble?r='+ Math.random(), {'artist': artist, 'album': album, 'track': track});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var Settings = {
|
||||
|
||||
lastfm_login_url: null,
|
||||
user: null,
|
||||
|
||||
getAccountInfo: function(callback) {
|
||||
Session.query('/user/update', {}, callback);
|
||||
|
@ -12,10 +12,12 @@ var Settings = {
|
|||
|
||||
loadFormData: function(form) {
|
||||
if (form == 'account') {
|
||||
this.getAccountInfo(function(data){
|
||||
$('.settings-container .form input[name$="username"]').val(data.username);
|
||||
$('.settings-container .form input[name$="email"]').val(data.email);
|
||||
})
|
||||
$('.settings-container .form input[name$="username"]').val(Settings.user.name);
|
||||
$('.settings-container .form input[name$="email"]').val(Settings.user.email);
|
||||
} else if (form == 'lastfm') {
|
||||
if (Settings.user.lastfm_username) {
|
||||
$('.form-container input[name$="username"]').first().val(Settings.user.lastfm_username);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,19 +33,10 @@ $('.settings-container .tabs .tab').live('click', function(){
|
|||
$('.form-container').html($('.forms .'+ $(this).attr('data-fieldset')).html());
|
||||
Settings.loadFormData($(this).attr('data-fieldset'));
|
||||
}
|
||||
if ($(this).attr('data-fieldset') == 'lastfm') {
|
||||
Session.query('/lastfm/getinfo', {}, function(data){
|
||||
if (data.connected) {
|
||||
$('.form-container input[name$="username"]').first().val(data.username);
|
||||
} else {
|
||||
Settings.lastfm_login_url = data.lastfm_login_url;
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
$('.lastfm-connect').live('click', function(){
|
||||
window.open(Settings.lastfm_login_url);
|
||||
window.open(Settings.user.lastfm_login_url);
|
||||
});
|
||||
|
||||
$('.settings-container .form input').live('blur', function(){
|
||||
|
|
|
@ -7,15 +7,17 @@ function authInfo(response) {
|
|||
$('#search_field').focus();
|
||||
}
|
||||
Session.query('/user/auth', {}, function(ar){
|
||||
if (!ar.username) {
|
||||
if (ar.newbie) {
|
||||
VK.Api.call('getVariable', {key: 1281}, function(r) {
|
||||
Session.query('/user/update', {'name': r.response}, function(ar2) {
|
||||
$('#header-container .hello .greating').text('Hi there, '+ (ar2.username ? ar2.username : '%username%') +'!');
|
||||
Settings.user = ar2.user;
|
||||
$('#header-container .hello .greating').text('Hi there, '+ (Settings.user.name ? Settings.user.name : '%username%') +'!');
|
||||
});
|
||||
});
|
||||
} else {
|
||||
Settings.user = ar.user;
|
||||
}
|
||||
$('#header-container .hello .greating').text('Hi there, '+ (ar.username ? ar.username : '%username%') +'!');
|
||||
Session.user_id = ar.id;
|
||||
$('#header-container .hello .greating').text('Hi there, '+ (Settings.user.name ? Settings.user.name : '%username%') +'!');
|
||||
});
|
||||
} else {
|
||||
$('#vk_login, .auth_notice').css('display', 'block');
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<div class="form">
|
||||
<div class="field">
|
||||
<div class="label">Username:</div>
|
||||
<div class="value"><input name="username" type="text" disabled="disabled" value="Not connected" /></div>
|
||||
<div class="value"><input name="username" type="text" disabled="disabled" readonly="readonly" value="Not connected" /></div>
|
||||
<div class="action-button"><input type="button" class="lastfm-connect" value="Connect"/></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue