Settings draft
This commit is contained in:
parent
1d9f527f39
commit
d7da0fa3de
|
@ -1,38 +1,50 @@
|
||||||
require 'digest'
|
require 'digest'
|
||||||
|
|
||||||
class UserController < ApplicationController
|
class UserController < ApplicationController
|
||||||
@@secret_key
|
|
||||||
def auth
|
def auth
|
||||||
# Defining secret key dependent on hostname
|
|
||||||
@@secret_key = request.host == 'beathaven.org' ? 'sdgwSbl3nNE4ZxafuPrp' : 's5zyjb693z6uV4rbhEyc'
|
|
||||||
@res = {}
|
@res = {}
|
||||||
|
check = check_auth(params)
|
||||||
|
|
||||||
unless params[:expire].nil? or params[:mid].nil? or params[:secret].nil? or params[:sid].nil? or params[:sig].nil?
|
if check == true
|
||||||
# Calculating hash
|
@res[:status] = 'hello'
|
||||||
hash = 'expire='+ params[:expire] +'mid='+ params[:mid] +'secret='+ params[:secret] +'sid='+ params[:sid] + @@secret_key
|
user = User.find_by_vkid(params[:mid])
|
||||||
hash_md5 = Digest::MD5.hexdigest(hash)
|
if user.nil?
|
||||||
|
user = User.new
|
||||||
if Digest::MD5.hexdigest(hash) == params[:sig]
|
user.vkid = params[:mid]
|
||||||
@res[:status] = 'hello'
|
user.save
|
||||||
user = User.find_by_vkid(params[:mid])
|
|
||||||
if user.nil?
|
|
||||||
user = User.new
|
|
||||||
user.vkid = params[:mid]
|
|
||||||
user.save
|
|
||||||
end
|
|
||||||
if user.name.nil? and not params[:name].nil?
|
|
||||||
user.name = params[:name]
|
|
||||||
user.save
|
|
||||||
end
|
|
||||||
@res[:id] = user.id
|
|
||||||
@res[:username] = user.name
|
|
||||||
else
|
|
||||||
@res[:status] = 'bad signature'
|
|
||||||
end
|
end
|
||||||
|
@res[:id] = user.id
|
||||||
|
@res[:username] = user.name
|
||||||
|
elsif check == false
|
||||||
|
@res[:status] = 'bad signature'
|
||||||
else
|
else
|
||||||
@res[:status] = 'bad params'
|
@res[:status] = 'bad params'
|
||||||
end
|
end
|
||||||
|
|
||||||
render :json => @res
|
render :json => @res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def check_auth params
|
||||||
|
secret_key = request.host == 'beathaven.org' ? 'sdgwSbl3nNE4ZxafuPrp' : 's5zyjb693z6uV4rbhEyc'
|
||||||
|
unless params[:expire].nil? or params[:mid].nil? or params[:secret].nil? or params[:sid].nil? or params[:sig].nil?
|
||||||
|
# Calculating hash
|
||||||
|
hash = 'expire='+ params[:expire] +'mid='+ params[:mid] +'secret='+ params[:secret] +'sid='+ params[:sid] + secret_key
|
||||||
|
hash_md5 = Digest::MD5.hexdigest(hash)
|
||||||
|
if Digest::MD5.hexdigest(hash) == params[:sig]
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return 'bad params'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
|
@ -15,6 +15,7 @@
|
||||||
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/layout.js"></script>
|
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/layout.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/ajax.js"></script>
|
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/ajax.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/search.js"></script>
|
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/search.js"></script>
|
||||||
|
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/settings.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/pages.js"></script>
|
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/pages.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/audio.js"></script>
|
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/audio.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/player.js"></script>
|
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/player.js"></script>
|
||||||
|
@ -49,7 +50,10 @@
|
||||||
|
|
||||||
<!-- START HEADER -->
|
<!-- START HEADER -->
|
||||||
<div id="header-container">
|
<div id="header-container">
|
||||||
<div class="hello"></div>
|
<div class="hello">
|
||||||
|
<span class="greating"></span>
|
||||||
|
<div class="settings"></div>
|
||||||
|
</div>
|
||||||
<ul id="navigation">
|
<ul id="navigation">
|
||||||
<li class="logo search">BeatHaven</li>
|
<li class="logo search">BeatHaven</li>
|
||||||
<li class="search">Search</li>
|
<li class="search">Search</li>
|
||||||
|
|
|
@ -36,6 +36,13 @@ var Ajax = {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
loadSettingsPage: function() {
|
||||||
|
$.get('/settings.html', function(data){
|
||||||
|
Ajax.setArchor('/settings/');
|
||||||
|
Pages.renderSettings(data);
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
loadWheePage: function() {
|
loadWheePage: function() {
|
||||||
$.get('/demo/whee.html', function(data){
|
$.get('/demo/whee.html', function(data){
|
||||||
$('#data-container .inner').html(data);
|
$('#data-container .inner').html(data);
|
||||||
|
@ -67,6 +74,8 @@ var Ajax = {
|
||||||
Ajax.loadArtistData(m[1]);
|
Ajax.loadArtistData(m[1]);
|
||||||
} else if (Ajax.getAnchor() === '' || Ajax.getAnchor().match(/\/search\//)) {
|
} else if (Ajax.getAnchor() === '' || Ajax.getAnchor().match(/\/search\//)) {
|
||||||
Ajax.loadSearchPage();
|
Ajax.loadSearchPage();
|
||||||
|
} else if (Ajax.getAnchor().match(/\/settings\//)) {
|
||||||
|
Ajax.loadSettingsPage();
|
||||||
} else {
|
} else {
|
||||||
Ajax.load404Page();
|
Ajax.load404Page();
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,5 +84,11 @@ var Pages = {
|
||||||
|
|
||||||
yaCounter7596904.hit(Ajax.getAnchor(), 'Artist Search', Ajax.referer);
|
yaCounter7596904.hit(Ajax.getAnchor(), 'Artist Search', Ajax.referer);
|
||||||
Ajax.setTitle('Artist Search');
|
Ajax.setTitle('Artist Search');
|
||||||
|
},
|
||||||
|
|
||||||
|
renderSettings: function(data) {
|
||||||
|
$('#data-container .inner').html(data);
|
||||||
|
yaCounter7596904.hit(Ajax.getAnchor(), 'Settings', Ajax.referer);
|
||||||
|
Ajax.setTitle('Settings');
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ var Search = {
|
||||||
showSpinner: function() {
|
showSpinner: function() {
|
||||||
$('#search-container input').attr('disabled', 'disabled').blur();
|
$('#search-container input').attr('disabled', 'disabled').blur();
|
||||||
$('#search-container img').show();
|
$('#search-container img').show();
|
||||||
|
$('.autocomplete-container').hide();
|
||||||
Search.hideSuggestions();
|
Search.hideSuggestions();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ var Search = {
|
||||||
|
|
||||||
showArtistPics: function(pics) {
|
showArtistPics: function(pics) {
|
||||||
$('.artist_loading, .artist_pics').show();
|
$('.artist_loading, .artist_pics').show();
|
||||||
for (var i = 0; i < pics.length; i++) {console.log(Search.pics.indexOf(pics[i]));
|
for (var i = 0; i < pics.length; i++) {
|
||||||
if (Search.pics.indexOf(pics[i]) === -1) {
|
if (Search.pics.indexOf(pics[i]) === -1) {
|
||||||
Search.pics.push(pics[i]);
|
Search.pics.push(pics[i]);
|
||||||
$('.artist_pics').append('\
|
$('.artist_pics').append('\
|
||||||
|
|
|
@ -1,5 +1,20 @@
|
||||||
var Session = {
|
var Session = {
|
||||||
|
|
||||||
user_id: null,
|
user_id: null,
|
||||||
vkid: null
|
vk_params: {},
|
||||||
|
|
||||||
|
query: function(url, params, callback) {
|
||||||
|
var q_params = this.vk_params;
|
||||||
|
for (attr in params) {
|
||||||
|
q_params[attr] = params[attr];
|
||||||
|
}
|
||||||
|
$.post(url, q_params, callback);
|
||||||
|
},
|
||||||
|
|
||||||
|
setVkParams: function(params) {
|
||||||
|
attrs = ['expire', 'mid', 'secret', 'sid', 'sig'];
|
||||||
|
for (var i = 0; i < attrs.length; i++) {
|
||||||
|
this.vk_params[attrs[i]] = params[attrs[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
var Settings = {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.settings').live('click', function() {
|
||||||
|
Ajax.loadSettingsPage();
|
||||||
|
})
|
|
@ -1,22 +1,21 @@
|
||||||
function authInfo(response) {
|
function authInfo(response) {
|
||||||
if (typeof response != 'undefined' && response.session) {
|
if (typeof response != 'undefined' && response.session) {
|
||||||
|
Session.setVkParams(response.session);
|
||||||
$('#vk_login, .auth_notice').hide();
|
$('#vk_login, .auth_notice').hide();
|
||||||
$('#vk_logout').css('display', 'block');
|
$('#vk_logout').css('display', 'block');
|
||||||
if ($('#search_field').length > 0) {
|
if ($('#search_field').length > 0) {
|
||||||
$('#search_field').focus();
|
$('#search_field').focus();
|
||||||
}
|
}
|
||||||
$.post('/user/auth', response.session, function(ar){
|
Session.query('/user/auth', {}, function(ar){
|
||||||
if (!ar.username) {
|
if (!ar.username) {
|
||||||
VK.Api.call('getVariable', {key: 1281}, function(r) {
|
VK.Api.call('getVariable', {key: 1281}, function(r) {
|
||||||
response.session.name = r.response;
|
Session.query('/user/update', {'name': r.response}, function(ar2) {
|
||||||
$.post('/user/auth', response.session, function(ar2) {
|
$('#header-container .hello .greating').text('Hi there, '+ ar2.username +'!');
|
||||||
$('#header-container .hello').text('Hi there, '+ ar2.username +'!');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$('#header-container .hello').text('Hi there, '+ (ar.username ? ar.username : '%username%') +'!');
|
$('#header-container .hello .greating').text('Hi there, '+ (ar.username ? ar.username : '%username%') +'!');
|
||||||
Session.user_id = ar.id;
|
Session.user_id = ar.id;
|
||||||
Session.vkid = response.session.mid;
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$('#vk_login, .auth_notice').css('display', 'block');
|
$('#vk_login, .auth_notice').css('display', 'block');
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
hello
|
|
@ -41,6 +41,19 @@
|
||||||
margin: 6px 10px 0 0;
|
margin: 6px 10px 0 0;
|
||||||
color: #222;
|
color: #222;
|
||||||
}
|
}
|
||||||
|
#header-container .hello .greating {
|
||||||
|
display: block;
|
||||||
|
float: left;
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
#header-container .hello .settings {
|
||||||
|
float: right;
|
||||||
|
width: 15px;
|
||||||
|
height: 15px;
|
||||||
|
margin: 1px 0;
|
||||||
|
background-image: url(/images/icns/settings.png);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
display: inline;
|
display: inline;
|
||||||
|
|
Loading…
Reference in New Issue