Comparing version 0.1.0-beta-53 to 0.1.0-beta-54
@@ -5,2 +5,3 @@ "use strict"; | ||
Type = di.load('typejs'), | ||
error = di.load('error'), | ||
component = di.load('core/component'), | ||
@@ -20,3 +21,5 @@ ControllerInterface = di.load('interface/controller'), | ||
*/ | ||
Controller = ControllerInterface.inherit({}, { | ||
Controller = ControllerInterface.inherit({ | ||
__cookies__: Type.OBJECT | ||
}, { | ||
/** | ||
@@ -31,3 +34,3 @@ * @since 0.0.1 | ||
setStatusCode: function Controller_setStatusCode(code) { | ||
this._requestApi.setStatusCode(code); | ||
this.__requestApi__.setStatusCode(code); | ||
}, | ||
@@ -43,3 +46,3 @@ /** | ||
stopChain: function Controller_stopChain() { | ||
return this._requestApi.stopPromiseChain(); | ||
return this.__requestApi__.stopPromiseChain(); | ||
}, | ||
@@ -55,3 +58,3 @@ /** | ||
hasHeader: function Controller_hasHeader(key) { | ||
return this._requestApi.hasHeader(key); | ||
return this.__requestApi__.hasHeader(key); | ||
}, | ||
@@ -67,3 +70,3 @@ /** | ||
getRequestBody: function Controller_getRequestBody() { | ||
return this._requestApi.getRequestBody(); | ||
return this.__requestApi__.getRequestBody(); | ||
}, | ||
@@ -79,3 +82,3 @@ /** | ||
getRequestHeader: function Controller_getRequestHeader(key) { | ||
return this._requestApi.getRequestHeader(key); | ||
return this.__requestApi__.getRequestHeader(key); | ||
}, | ||
@@ -91,3 +94,3 @@ /** | ||
getHeaders: function Controller_getHeaders() { | ||
return this._requestApi.getHeaders(); | ||
return this.__requestApi__.getHeaders(); | ||
}, | ||
@@ -103,3 +106,3 @@ /** | ||
getMethod: function Controller_getMethod() { | ||
return this._requestApi.getMethod(); | ||
return this.__requestApi__.getMethod(); | ||
}, | ||
@@ -115,3 +118,3 @@ /** | ||
getRequestHeaders: function Controller_getRequestHeaders() { | ||
return this._requestApi.getRequestHeaders(); | ||
return this.__requestApi__.getRequestHeaders(); | ||
}, | ||
@@ -127,3 +130,3 @@ /** | ||
isHeaderCacheUnModified: function Controller_isHeaderCacheUnModified() { | ||
return this._requestApi.isHeaderCacheUnModified(); | ||
return this.__requestApi__.isHeaderCacheUnModified(); | ||
}, | ||
@@ -139,3 +142,3 @@ /** | ||
sendNoChange: function Controller_sendNoChange() { | ||
return this._requestApi.sendNoChange(); | ||
return this.__requestApi__.sendNoChange(); | ||
}, | ||
@@ -151,3 +154,3 @@ /** | ||
getParsedUrl: function Controller_getParsedUrl() { | ||
return this._requestApi.parsedUrl; | ||
return this.__requestApi__.parsedUrl; | ||
}, | ||
@@ -163,3 +166,3 @@ /** | ||
createUrl: function Controller_createUrl(route, params) { | ||
return this._requestApi.createUrl(route, params); | ||
return this.__requestApi__.createUrl(route, params); | ||
}, | ||
@@ -175,3 +178,3 @@ /** | ||
onEnd: function Controller_onEnd(callback) { | ||
return this._requestApi.onEnd(callback); | ||
return this.__requestApi__.onEnd(callback); | ||
}, | ||
@@ -187,3 +190,3 @@ /** | ||
addHeader: function Controller_addHeader(key, value) { | ||
return this._requestApi.addHeader(key, value); | ||
return this.__requestApi__.addHeader(key, value); | ||
}, | ||
@@ -199,3 +202,3 @@ /** | ||
forward: function Controller_forward(route, params) { | ||
return this._requestApi.forward(route, params); | ||
return this.__requestApi__.forward(route, params); | ||
}, | ||
@@ -210,4 +213,4 @@ /** | ||
*/ | ||
forwardUrl: function Controller_forwardUrl(route, params) { | ||
return this._requestApi.forwardUrl(route, params); | ||
forwardUrl: function Controller_forwardUrl(route, params) { | ||
return this.__requestApi__.forwardUrl(route, params); | ||
}, | ||
@@ -223,3 +226,3 @@ /** | ||
redirect: function Controller_redirect(url, isTemp) { | ||
return this._requestApi.redirect(url, isTemp); | ||
return this.__requestApi__.redirect(url, isTemp); | ||
}, | ||
@@ -235,3 +238,3 @@ /** | ||
renderFile: function Controller_renderFile(pathName, locals) { | ||
return view.renderFile(pathName, locals, this._config.viewsPath); | ||
return view.renderFile(pathName, locals, this.__config__.viewsPath); | ||
}, | ||
@@ -259,3 +262,3 @@ /** | ||
getActionName: function Controller_getActionName() { | ||
return this._config.action; | ||
return this.__config__.action; | ||
}, | ||
@@ -272,3 +275,3 @@ /** | ||
getControllerName: function Controller_getControllerName() { | ||
return this._config.controller; | ||
return this.__config__.controller; | ||
}, | ||
@@ -285,3 +288,3 @@ /** | ||
getModuleName: function Controller_getModuleName() { | ||
return this._config.module; | ||
return this.__config__.module; | ||
}, | ||
@@ -291,2 +294,127 @@ /** | ||
* @author Igor Ivanovic | ||
* @method Controller#getSession | ||
* | ||
* @description | ||
* Get session key | ||
* @return {string} | ||
*/ | ||
getSession: function (key) { | ||
var session = component.get('storage/session'), | ||
session_id = this.getCookie(session.getCookieKey()); | ||
if (Type.isString(key)) { | ||
return session.get(session_id + key); | ||
} | ||
throw new error.HttpError(500, {key: key, session_id: session_id}, 'Controller.getSession: key must be string type'); | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method Controller#setSession key value | ||
* | ||
* @description | ||
* Set session | ||
* @return {string} | ||
*/ | ||
setSession: function (key, value) { | ||
var session = component.get('storage/session'), | ||
session_id = this.getCookie(session.getCookieKey()); | ||
if (!Type.isString(key)) { | ||
throw new error.HttpError(500, {key: key, session_id: session_id}, 'Controller.getSession: key must be string type'); | ||
} else if (!session_id) { | ||
session_id = new Buffer(this.__requestApi__.uuid() + '_' + (new Date).toString() + '_' + Math.random()).toString("base64"); | ||
this.setCookie(session.getCookieKey(), session_id, session.getExpiredTime()); | ||
} | ||
session.set(session_id + key, value); | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method Controller#setCookie | ||
* | ||
* @description | ||
* Decode string | ||
*/ | ||
setCookie: function (key, value, expires, path, domain, isHttpOnly) { | ||
var cookie, date; | ||
if (Type.isUndefined(key) || Type.isUndefined(value)) { | ||
throw new error.HttpError(500, { | ||
key: key, | ||
value: value, | ||
expires: expires, | ||
path: path, | ||
domain: domain, | ||
isHttpOnly: isHttpOnly | ||
}, 'Controller.setCookie: Key and Value must be provided!'); | ||
} | ||
cookie = key + "=" + value; | ||
if (!!expires) { | ||
if (Type.isNumber(expires)) { | ||
date = new Date(); | ||
date.setTime(date.getTime() + expires); | ||
cookie += "; Expires=" + date.toGMTString(); | ||
} else if (Type.isString(expires)) { | ||
cookie += "; Expires=" + expires; | ||
} else if (Type.isDate(expires)) { | ||
cookie += "; Expires=" + expires.toGMTString(); | ||
} | ||
} | ||
if (!!path) { | ||
cookie += "; Path=" + path; | ||
} | ||
if (!!domain) { | ||
cookie += "; Domain=" + domain; | ||
} | ||
if (!!isHttpOnly) { | ||
cookie += "; HttpOnly"; | ||
} | ||
this.addHeader('Set-cookie', cookie); | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method Controller#getCookies | ||
* | ||
* @description | ||
* Parse cookies | ||
*/ | ||
getCookies: function Controller_getCookies() { | ||
var data; | ||
if (!!this.__cookies__) { | ||
return this.__cookies__; | ||
} | ||
this.__cookies__ = {}; | ||
data = this.getRequestHeader('Cookie'); | ||
if (!!data) { | ||
data.replace(/(\w+[^=]+)=([^;]+)/g, function (cookie, key, value) { | ||
this.__cookies__[key] = value; | ||
}.bind(this)); | ||
} | ||
return this.__cookies__; | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method Controller#getCookie | ||
* | ||
* @description | ||
* Get all cookies | ||
*/ | ||
getCookie: function (key) { | ||
var cookies = this.getCookies(); | ||
if (cookies.hasOwnProperty(key)) { | ||
return cookies[key]; | ||
} | ||
return null; | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method Controller#hasAction | ||
@@ -293,0 +421,0 @@ * |
@@ -577,3 +577,4 @@ "use strict"; | ||
parsedUrl: core.copy(this.parsedUrl), | ||
forwardUrl: this.forward.bind(this) | ||
forwardUrl: this.forward.bind(this), | ||
uuid: this._uuid.bind(this) | ||
}; | ||
@@ -580,0 +581,0 @@ }, |
@@ -251,23 +251,4 @@ "use strict"; | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method View#getPath | ||
* | ||
* @description | ||
* Get the path | ||
* @return {string} | ||
*/ | ||
getPath: function View_getPath(path) { | ||
var paths = this.paths.slice(), | ||
item; | ||
while (paths.length) { | ||
item = di.normalizePath(paths.pop()); | ||
if (path && path.indexOf(item) === 0) { | ||
return item; | ||
} | ||
} | ||
return false; | ||
}, | ||
/** | ||
@@ -274,0 +255,0 @@ * @since 0.0.1 |
@@ -25,3 +25,5 @@ { | ||
"interface/requestHooks": "@{framework}/interface/requestHooks", | ||
"interface/cache": "@{framework}/interface/cache", | ||
"interface/cache": "@{framework}/interface/storage", | ||
"interface/storage": "@{framework}/interface/storage", | ||
"interface/controller": "@{framework}/interface/controller", | ||
@@ -34,5 +36,7 @@ "interface/routeRule": "@{framework}/interface/routeRule", | ||
"cache/memory": "@{framework}/cache/memory", | ||
"cache/memory": "@{framework}/storage/memory", | ||
"storage/memory": "@{framework}/storage/memory", | ||
"storage/session": "@{framework}/storage/session", | ||
"typejs": "static-type-js" | ||
} |
@@ -19,8 +19,8 @@ "use strict"; | ||
ControllerInterface = Type.create({ | ||
_requestApi: Type.OBJECT, | ||
_config: Type.OBJECT | ||
__requestApi__: Type.OBJECT, | ||
__config__: Type.OBJECT | ||
}, { | ||
_invoke: function ControllerInterface(requestApi, config) { | ||
this._requestApi = requestApi; | ||
this._config = config; | ||
this.__requestApi__ = requestApi; | ||
this.__config__ = config; | ||
[ | ||
@@ -27,0 +27,0 @@ "has", "get", "redirect", |
@@ -5,3 +5,3 @@ { | ||
"description": "Powerful lightweight mvc framework for nodejs", | ||
"version": "0.1.0-beta-53", | ||
"version": "0.1.0-beta-54", | ||
"dependencies" : { | ||
@@ -8,0 +8,0 @@ "mongoose": "3.8.x", |
138701
35
4425