2013-01-25 19:18:17 +00:00
|
|
|
###
|
|
|
|
|
Setup read / write access
|
|
|
|
|
@param store
|
|
|
|
|
###
|
|
|
|
|
module.exports = (store) ->
|
|
|
|
|
|
2013-01-27 15:05:15 +00:00
|
|
|
# store.writeAccess "*", "users.*.balance", (id, newBalance, next) ->
|
|
|
|
|
# return unless @session and @session.userId # https://github.com/codeparty/racer/issues/37
|
|
|
|
|
# purchasingSomethingOnClient = newBalance < this.session.req._racerModel.get("users.#{id}.balance")
|
|
|
|
|
# isServer = not @req.socket
|
|
|
|
|
# next(purchasingSomethingOnClient or isServer)
|
2013-01-25 19:18:17 +00:00
|
|
|
|
|
|
|
|
store.writeAccess "*", "users.*.flags.ads", -> # captures, value, next ->
|
|
|
|
|
return unless @session and @session.userId # https://github.com/codeparty/racer/issues/37
|
|
|
|
|
next = arguments[arguments.length - 1]
|
|
|
|
|
isServer = not @req.socket
|
2013-01-30 20:57:36 +00:00
|
|
|
next(isServer)
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
Get user with API token
|
|
|
|
|
###
|
|
|
|
|
store.query.expose "users", "withIdAndToken", (id, api_token) ->
|
|
|
|
|
@where("id").equals(id)
|
|
|
|
|
.where('preferences.api_token').equals(api_token)
|
|
|
|
|
.limit(1)
|
|
|
|
|
|
|
|
|
|
store.queryAccess "users", "withIdAndToken", (id, token, next) ->
|
|
|
|
|
return next(false) unless @session and @session.userId # https://github.com/codeparty/racer/issues/37
|
|
|
|
|
isServer = not @req.socket
|
|
|
|
|
next(isServer)
|