mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
17 lines
564 B
CoffeeScript
17 lines
564 B
CoffeeScript
angular.module("ofn.admin").factory "SpreeApiAuth", ($q, $http, SpreeApiKey) ->
|
|
new class SpreeApiAuth
|
|
authorise: ->
|
|
deferred = $q.defer()
|
|
|
|
$http.get("/api/users/authorise_api?token=" + SpreeApiKey)
|
|
.success (response) ->
|
|
if response?.success == "Use of API Authorised"
|
|
$http.defaults.headers.common["X-Spree-Token"] = SpreeApiKey
|
|
deferred.resolve()
|
|
|
|
.error (response) ->
|
|
error = response?.error || "You are unauthorised to access this page."
|
|
deferred.reject(error)
|
|
|
|
deferred.promise
|