Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Signature middleware
class App.SignMiddleware
constructor: (@gameData, callback) ->
@name = 'requestSign'
@sessionKey = null
Psycho.ajax
url: "#{@gameData.endpointUrl}user/getSessionKey"
type: 'POST'
data: @_signRequestParams { userId: @gameData.userId }
callback: (res) =>
@sessionKey = JSON.parse(res.responseText).response.sessionkey
callback()
App.AjaxMiddleware.addBeforeHandler @name, (options) =>
@process options
process: (options) ->
options.data = {} unless options.data?
throw Error 'SessionKey not found!' unless @sessionKey?
options.data['userId'] = @gameData.userId
options.data['sessionkey'] = @sessionKey
# Sign request params
options.data = @_signRequestParams options.data
return options
_signRequestParams: (requestData) ->
encodedParams = Base64.encode JSON.stringify(requestData)
requestData =
params: encodedParams
snsig: CryptoJS.MD5(encodedParams + @gameData.SNSIG_SALT).toString()
return requestData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.