Vkontakte session battle
This commit is contained in:
		
							parent
							
								
									eed7ea685c
								
							
						
					
					
						commit
						4a2f793635
					
				| @ -19,12 +19,12 @@ class Session | |||||||
| 		@user | 		@user | ||||||
| 	 | 	 | ||||||
| 	query: (url, params, callback) -> | 	query: (url, params, callback) -> | ||||||
| 		q_params = @vk_params | 		q_params = $.extend {}, @vk_params, params | ||||||
| 		$.each params, (key, val) -> |  | ||||||
| 			q_params[key] = val |  | ||||||
| 		$.post url, q_params, callback | 		$.post url, q_params, callback | ||||||
| 		false | 		false | ||||||
| 	 | 	 | ||||||
| 	reloadSession: -> | 	reloadSession: -> | ||||||
| 		_session.query '/user/auth', {}, (ar) -> | 		_session.query '/user/auth', {}, (ar) -> | ||||||
| 			_session.setUser ar.user | 			_session.setUser ar.user | ||||||
|  | 			false | ||||||
|  | 		false | ||||||
|  | |||||||
| @ -13,7 +13,8 @@ class Vkontakte | |||||||
| 		 | 		 | ||||||
| 		window.vkAsyncInit = -> | 		window.vkAsyncInit = -> | ||||||
| 			VK.init apiId: _vkontakte.getApiId() | 			VK.init apiId: _vkontakte.getApiId() | ||||||
| 			VK.Auth.getLoginStatus _vkontakte.authInfo | 			VK.Auth.getLoginStatus (response) -> | ||||||
|  | 				_vkontakte.authInfo(response) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 		setTimeout -> | 		setTimeout -> | ||||||
| @ -42,6 +43,12 @@ class Vkontakte | |||||||
| 				$('.header-container .hello').show() | 				$('.header-container .hello').show() | ||||||
| 				$('.header-container .hello .greating') | 				$('.header-container .hello .greating') | ||||||
| 					.html 'Tēnā koe, <span class="settings">' +(if _session.getUser().name then _session.getUser().name else '%username%')+ '</span>!' | 					.html 'Tēnā koe, <span class="settings">' +(if _session.getUser().name then _session.getUser().name else '%username%')+ '</span>!' | ||||||
|  | 			 | ||||||
|  | 			if response.session.expire? | ||||||
|  | 				setTimeout -> | ||||||
|  | 					_vkontakte.auth() | ||||||
|  | 					false | ||||||
|  | 				, response.session.expire * 1000 - new Date().getTime() + 1000 | ||||||
| 		else | 		else | ||||||
| 			_session = new Session({}) | 			_session = new Session({}) | ||||||
| 			_session.setUser {} | 			_session.setUser {} | ||||||
| @ -49,6 +56,13 @@ class Vkontakte | |||||||
| 			$('.header-container .hello').hide() | 			$('.header-container .hello').hide() | ||||||
| 		window._session = _session | 		window._session = _session | ||||||
| 	 | 	 | ||||||
|  | 	auth: -> | ||||||
|  | 		VK.Auth.login (response) -> | ||||||
|  | 			_vkontakte.authInfo(response) | ||||||
|  | 			false | ||||||
|  | 		, 8 | ||||||
|  | 		false | ||||||
|  | 	 | ||||||
| 	loadTracksData: (artist, track, duration, callback) -> | 	loadTracksData: (artist, track, duration, callback) -> | ||||||
| 		track_prepared = track.replace(/\(.*\)/i, '').split('/')[0]; | 		track_prepared = track.replace(/\(.*\)/i, '').split('/')[0]; | ||||||
| 		query = artist+' '+track_prepared; | 		query = artist+' '+track_prepared; | ||||||
| @ -56,18 +70,17 @@ class Vkontakte | |||||||
| 			callback url | 			callback url | ||||||
| 		else | 		else | ||||||
| 			VK.Api.call 'audio.search', q: query, (r) -> | 			VK.Api.call 'audio.search', q: query, (r) -> | ||||||
| 				r.response.splice 0, 1 |  | ||||||
| 				url = _vkontakte.matchPerfectResult r.response, artist, track, duration | 				url = _vkontakte.matchPerfectResult r.response, artist, track, duration | ||||||
| 				_vkontakte.addQR query, url | 				_vkontakte.addQR query, url | ||||||
| 				callback url | 				callback url | ||||||
| 	 | 	 | ||||||
| 	matchPerfectResult: (data, artist, track, duration) -> | 	matchPerfectResult: (data, artist, track, duration) -> | ||||||
| 		duration = duration.split ':' | 		duration = duration.split ':' | ||||||
| 
 |  | ||||||
| 		duration = parseInt(duration[0], 10) * 60 + parseInt(duration[1], 10) | 		duration = parseInt(duration[0], 10) * 60 + parseInt(duration[1], 10) | ||||||
| 		best_score = 0; | 		best_score = 0; | ||||||
| 		best_result = null; | 		best_result = null; | ||||||
| 		for item in data | 		for item in data | ||||||
|  | 			if typeof item is 'object' | ||||||
| 				score = 0; | 				score = 0; | ||||||
| 				item.artist = item.artist.trim(); | 				item.artist = item.artist.trim(); | ||||||
| 				item.title = item.title.trim(); | 				item.title = item.title.trim(); | ||||||
| @ -108,12 +121,11 @@ class Vkontakte | |||||||
| 		false | 		false | ||||||
| 
 | 
 | ||||||
| $('#vk_login').live 'click', -> | $('#vk_login').live 'click', -> | ||||||
| 	VK.Auth.login (response) -> | 	_vkontakte.auth() | ||||||
| 		_vkontakte.authInfo(response) |  | ||||||
| 		false |  | ||||||
| 	, 8 |  | ||||||
| 	false | 	false | ||||||
| $('#vk_logout').live 'click', -> | $('#vk_logout').live 'click', -> | ||||||
| 	_ajax.go '/search/'; | 	_ajax.go '/search/'; | ||||||
| 	VK.Auth.logout _vkontakte.authInfo | 	VK.Auth.logout (response) -> | ||||||
|  | 		_vkontakte.authInfo(response) | ||||||
|  | 		false | ||||||
| 	false | 	false | ||||||
|  | |||||||
| @ -5,12 +5,12 @@ | |||||||
| 		<meta charset="utf-8"/> | 		<meta charset="utf-8"/> | ||||||
| 		<link rel="shortcut icon" href="/favicon.ico" /> | 		<link rel="shortcut icon" href="/favicon.ico" /> | ||||||
| 		<link rel="stylesheet" type="text/css" media="screen" href="/stylesheets/beathaven.css" /> | 		<link rel="stylesheet" type="text/css" media="screen" href="/stylesheets/beathaven.css" /> | ||||||
| 		<%= javascript_include_tag "jquery/jquery.min.js" %> | 		<%= javascript_include_tag "jquery/jquery.min.js", :type => "text/javascript", :charset => "utf-8"  %> | ||||||
| 		<%= javascript_include_tag "jquery/jquery-ui/js/jquery-ui-1.8.13.custom.min.js" %> | 		<%= javascript_include_tag "jquery/jquery-ui/js/jquery-ui-1.8.13.custom.min.js", :type => "text/javascript", :charset => "utf-8"  %> | ||||||
| 		<%= javascript_include_tag "jquery/jquery.autocomplete.js" %> | 		<%= javascript_include_tag "jquery/jquery.autocomplete.js", :type => "text/javascript", :charset => "utf-8"  %> | ||||||
| 		<%= javascript_include_tag "jquery/jquery.contentchange.js" %> | 		<%= javascript_include_tag "jquery/jquery.contentchange.js", :type => "text/javascript", :charset => "utf-8"  %> | ||||||
| 		<%= javascript_include_tag "jquery/jquery.jplayer.js" %> | 		<%= javascript_include_tag "jquery/jquery.jplayer.js", :type => "text/javascript", :charset => "utf-8"  %> | ||||||
| 		<%= javascript_include_tag "jquery/jquery.scroll.js" %> | 		<%= javascript_include_tag "jquery/jquery.scroll.js", :type => "text/javascript", :charset => "utf-8"  %> | ||||||
| 		<%= javascript_include_tag "coffee/beathaven.js", :type => "text/javascript", :charset => "utf-8" %> | 		<%= javascript_include_tag "coffee/beathaven.js", :type => "text/javascript", :charset => "utf-8" %> | ||||||
| 		<%= javascript_include_tag "coffee/vkontakte.js", :type => "text/javascript", :charset => "utf-8" %> | 		<%= javascript_include_tag "coffee/vkontakte.js", :type => "text/javascript", :charset => "utf-8" %> | ||||||
| 		<%= javascript_include_tag "coffee/session.js", :type => "text/javascript", :charset => "utf-8" %> | 		<%= javascript_include_tag "coffee/session.js", :type => "text/javascript", :charset => "utf-8" %> | ||||||
| @ -61,7 +61,7 @@ | |||||||
| 				<div class="settings settings-button"></div> | 				<div class="settings settings-button"></div> | ||||||
| 			</div> | 			</div> | ||||||
| 			<ul class="navigation"> | 			<ul class="navigation"> | ||||||
| 				<li class="logo search">BeatHaven<div class="version">0.4</div></li> | 				<li class="logo search">BeatHaven<div class="version">0.4b</div></li> | ||||||
| 				<li class="search">Search</li> | 				<li class="search">Search</li> | ||||||
| 				<li><a href="https://twitter.com/#!/beat_haven" target="_blank">News</a></li> | 				<li><a href="https://twitter.com/#!/beat_haven" target="_blank">News</a></li> | ||||||
| 				<li class="about">About</li> | 				<li class="about">About</li> | ||||||
|  | |||||||
| @ -23,17 +23,16 @@ Session = (function() { | |||||||
|   }; |   }; | ||||||
|   Session.prototype.query = function(url, params, callback) { |   Session.prototype.query = function(url, params, callback) { | ||||||
|     var q_params; |     var q_params; | ||||||
|     q_params = this.vk_params; |     q_params = $.extend({}, this.vk_params, params); | ||||||
|     $.each(params, function(key, val) { |  | ||||||
|       return q_params[key] = val; |  | ||||||
|     }); |  | ||||||
|     $.post(url, q_params, callback); |     $.post(url, q_params, callback); | ||||||
|     return false; |     return false; | ||||||
|   }; |   }; | ||||||
|   Session.prototype.reloadSession = function() { |   Session.prototype.reloadSession = function() { | ||||||
|     return _session.query('/user/auth', {}, function(ar) { |     _session.query('/user/auth', {}, function(ar) { | ||||||
|       return _session.setUser(ar.user); |       _session.setUser(ar.user); | ||||||
|  |       return false; | ||||||
|     }); |     }); | ||||||
|  |     return false; | ||||||
|   }; |   }; | ||||||
|   return Session; |   return Session; | ||||||
| })(); | })(); | ||||||
| @ -14,7 +14,9 @@ Vkontakte = (function() { | |||||||
|       VK.init({ |       VK.init({ | ||||||
|         apiId: _vkontakte.getApiId() |         apiId: _vkontakte.getApiId() | ||||||
|       }); |       }); | ||||||
|       return VK.Auth.getLoginStatus(_vkontakte.authInfo); |       return VK.Auth.getLoginStatus(function(response) { | ||||||
|  |         return _vkontakte.authInfo(response); | ||||||
|  |       }); | ||||||
|     }; |     }; | ||||||
|     return setTimeout(function() { |     return setTimeout(function() { | ||||||
|       return $('#vk_api_transport').append('<script async="async" src="http://vkontakte.ru/js/api/openapi.js"></script>'); |       return $('#vk_api_transport').append('<script async="async" src="http://vkontakte.ru/js/api/openapi.js"></script>'); | ||||||
| @ -49,6 +51,12 @@ Vkontakte = (function() { | |||||||
|         $('.header-container .hello').show(); |         $('.header-container .hello').show(); | ||||||
|         return $('.header-container .hello .greating').html('Tēnā koe, <span class="settings">' + (_session.getUser().name ? _session.getUser().name : '%username%') + '</span>!'); |         return $('.header-container .hello .greating').html('Tēnā koe, <span class="settings">' + (_session.getUser().name ? _session.getUser().name : '%username%') + '</span>!'); | ||||||
|       }); |       }); | ||||||
|  |       if (response.session.expire != null) { | ||||||
|  |         setTimeout(function() { | ||||||
|  |           _vkontakte.auth(); | ||||||
|  |           return false; | ||||||
|  |         }, response.session.expire * 1000 - new Date().getTime() + 1000); | ||||||
|  |       } | ||||||
|     } else { |     } else { | ||||||
|       _session = new Session({}); |       _session = new Session({}); | ||||||
|       _session.setUser({}); |       _session.setUser({}); | ||||||
| @ -59,6 +67,13 @@ Vkontakte = (function() { | |||||||
|     } |     } | ||||||
|     return window._session = _session; |     return window._session = _session; | ||||||
|   }; |   }; | ||||||
|  |   Vkontakte.prototype.auth = function() { | ||||||
|  |     VK.Auth.login(function(response) { | ||||||
|  |       _vkontakte.authInfo(response); | ||||||
|  |       return false; | ||||||
|  |     }, 8); | ||||||
|  |     return false; | ||||||
|  |   }; | ||||||
|   Vkontakte.prototype.loadTracksData = function(artist, track, duration, callback) { |   Vkontakte.prototype.loadTracksData = function(artist, track, duration, callback) { | ||||||
|     var query, track_prepared, url; |     var query, track_prepared, url; | ||||||
|     track_prepared = track.replace(/\(.*\)/i, '').split('/')[0]; |     track_prepared = track.replace(/\(.*\)/i, '').split('/')[0]; | ||||||
| @ -69,7 +84,6 @@ Vkontakte = (function() { | |||||||
|       return VK.Api.call('audio.search', { |       return VK.Api.call('audio.search', { | ||||||
|         q: query |         q: query | ||||||
|       }, function(r) { |       }, function(r) { | ||||||
|         r.response.splice(0, 1); |  | ||||||
|         url = _vkontakte.matchPerfectResult(r.response, artist, track, duration); |         url = _vkontakte.matchPerfectResult(r.response, artist, track, duration); | ||||||
|         _vkontakte.addQR(query, url); |         _vkontakte.addQR(query, url); | ||||||
|         return callback(url); |         return callback(url); | ||||||
| @ -84,6 +98,7 @@ Vkontakte = (function() { | |||||||
|     best_result = null; |     best_result = null; | ||||||
|     for (_i = 0, _len = data.length; _i < _len; _i++) { |     for (_i = 0, _len = data.length; _i < _len; _i++) { | ||||||
|       item = data[_i]; |       item = data[_i]; | ||||||
|  |       if (typeof item === 'object') { | ||||||
|         score = 0; |         score = 0; | ||||||
|         item.artist = item.artist.trim(); |         item.artist = item.artist.trim(); | ||||||
|         item.title = item.title.trim(); |         item.title = item.title.trim(); | ||||||
| @ -115,6 +130,7 @@ Vkontakte = (function() { | |||||||
|           return best_result.url; |           return best_result.url; | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|  |     } | ||||||
|     return best_result.url; |     return best_result.url; | ||||||
|   }; |   }; | ||||||
|   Vkontakte.prototype.addQR = function(query, url) { |   Vkontakte.prototype.addQR = function(query, url) { | ||||||
| @ -129,14 +145,14 @@ Vkontakte = (function() { | |||||||
|   return Vkontakte; |   return Vkontakte; | ||||||
| })(); | })(); | ||||||
| $('#vk_login').live('click', function() { | $('#vk_login').live('click', function() { | ||||||
|   VK.Auth.login(function(response) { |   _vkontakte.auth(); | ||||||
|     _vkontakte.authInfo(response); |  | ||||||
|     return false; |  | ||||||
|   }, 8); |  | ||||||
|   return false; |   return false; | ||||||
| }); | }); | ||||||
| $('#vk_logout').live('click', function() { | $('#vk_logout').live('click', function() { | ||||||
|   _ajax.go('/search/'); |   _ajax.go('/search/'); | ||||||
|   VK.Auth.logout(_vkontakte.authInfo); |   VK.Auth.logout(function(response) { | ||||||
|  |     _vkontakte.authInfo(response); | ||||||
|  |     return false; | ||||||
|  |   }); | ||||||
|   return false; |   return false; | ||||||
| }); | }); | ||||||
| @ -204,7 +204,6 @@ $icons_dir: "/images/icns/"; | |||||||
| 			&.active { | 			&.active { | ||||||
| 				@include opacity(0.8); | 				@include opacity(0.8); | ||||||
| 			} | 			} | ||||||
| 		} |  | ||||||
| 			 | 			 | ||||||
| 			img { | 			img { | ||||||
| 				float: left; | 				float: left; | ||||||
| @ -225,4 +224,5 @@ $icons_dir: "/images/icns/"; | |||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
| } | } | ||||||
| @ -171,14 +171,14 @@ | |||||||
|       -ms-filter: ”alpha(opacity=80) ”; |       -ms-filter: ”alpha(opacity=80) ”; | ||||||
|       filter: alpha(opacity=80); |       filter: alpha(opacity=80); | ||||||
|       opacity: 0.8; } |       opacity: 0.8; } | ||||||
|   .player-container .additional-controls img { |     .player-container .additional-controls .item img { | ||||||
|       float: left; |       float: left; | ||||||
|       margin-top: 1px; } |       margin-top: 1px; } | ||||||
|   .player-container .additional-controls .annotation { |     .player-container .additional-controls .item .annotation { | ||||||
|       float: left; |       float: left; | ||||||
|       margin-left: 2px; } |       margin-left: 2px; } | ||||||
|   .player-container .additional-controls#empty-playlist { |     .player-container .additional-controls .item#empty-playlist { | ||||||
|       float: right; |       float: right; | ||||||
|       margin-right: 10px; } |       margin-right: 10px; } | ||||||
|     .player-container .additional-controls#empty-playlist img { |       .player-container .additional-controls .item#empty-playlist img { | ||||||
|         margin-top: 3px; } |         margin-top: 3px; } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user