Backbone ProtectedModel, WIP
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
class BeatHaven.Models.Artist extends Backbone.Model
|
||||
class BeatHaven.Models.Artist extends BeatHaven.Modules.ProtectedModel
|
||||
urlRoot: "/api/artists"
|
||||
|
||||
@@ -2,7 +2,7 @@ class BeatHaven.Models.User extends Backbone.Model
|
||||
|
||||
auth: ->
|
||||
BH.log "Authenticating user ..."
|
||||
this.query "/api/session/auth", {}, (response) ->
|
||||
this.query "/api/session/auth", { user: @.get("vk_session")["user"] }, (response) ->
|
||||
if response.error?
|
||||
# report error
|
||||
else
|
||||
@@ -12,11 +12,20 @@ class BeatHaven.Models.User extends Backbone.Model
|
||||
# BH.VK.set_favorites()
|
||||
|
||||
query: (path, params, callback) ->
|
||||
query_params = $.extend {}, @.get("vk_session"), params
|
||||
query_params = $.extend {}, @auth_params(), params
|
||||
query_params.authenticity_token = $('meta[name="csrf-token"]').attr("content")
|
||||
$.post path, query_params, callback
|
||||
$.get path, query_params, callback
|
||||
false
|
||||
|
||||
auth_params: ->
|
||||
params = @.get("vk_session")
|
||||
vk_auth:
|
||||
expire: params["expire"]
|
||||
mid: params["mid"]
|
||||
secret: params["secret"]
|
||||
sid: params["sid"]
|
||||
sig: params["sig"]
|
||||
|
||||
set_favorites: (tracks) ->
|
||||
BH.log tracks
|
||||
BH.log "Sending your Vkontakte media collection to BeatHaven ..."
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class BeatHaven.Modules.ProtectedModel extends Backbone.Model
|
||||
|
||||
fetch: (options) ->
|
||||
options = options ? _.clone(options) : {}
|
||||
model = this
|
||||
success = options.success
|
||||
options.success = (resp, status, xhr) ->
|
||||
if (!model.set(model.parse(resp, xhr), options)) return false;
|
||||
if (success) success(model, resp);
|
||||
};
|
||||
options.error = Backbone.wrapError(options.error, model, options);
|
||||
return (this.sync || Backbone.sync).call(this, 'read', this, options);
|
||||
Reference in New Issue
Block a user