Permalink
Browse files

Added users migration with required table schema

  • Loading branch information...
thetutlage committed Jan 15, 2016
0 parents commit ccb2edb5b8868841f289fe5ddfbc0d3bbcb39d9e
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
@@ -0,0 +1,6 @@
APP_PORT=3333
APP_HOST=0.0.0.0
SESSION_DRIVER=cookie
NODE_ENV=development
CACHE_VIEWS=false
DB_CONNECTION=sqlite
@@ -0,0 +1,26 @@
# Node modules
node_modules

# Ignoring everything inside storage directory
storage/*

# Keeping storage directory
!storage/.gitkeep

# Environment files should be seperate for each environment
.env

# When npm runs error it write logs to the below file
npm-debug.log

# Coverage directory used by tools like istanbul
coverage

# Created by nightwatch
reports

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Mac Only
.DS_Store
14 ace
@@ -0,0 +1,14 @@
#!/usr/bin/env node --harmony_proxies

'use strict'

/*
|--------------------------------------------------------------------------
| Running Console Commands
|--------------------------------------------------------------------------
|
| Here we invoke console commands registered under Ace store.
|
*/
const kernel = require('./bootstrap/kernel')
kernel()
@@ -0,0 +1,45 @@
'use strict'

const Ansi = use('Ansi')

class Greet {

/**
* @description signature defines the expectations of command
* here name is the argument command is expecting from
* terminal
* @method signature
* @return {String}
* @public
*/
static get signature () {
return '{name}'
}

/**
* @description this is the description of your command
* same is shown under help
* @method description
* @return {String}
* @public
*/
static get description () {
return 'I will greet a user'
}

/**
* @description handle method is the place where you
* take action when your command is ran
* @method handle
* @param {Object} options
* @param {Object} flags
* @return {void}
* @public
*/
* handle (options, flags) {
Ansi.success(`Hello ${options.name}`)
}

}

module.exports = Greet
@@ -0,0 +1,12 @@
'use strict'

class HomeController {

* index (request, response) {
const view = yield response.view('index')
response.send(view)
}

}

module.exports = HomeController
@@ -0,0 +1,100 @@
'use strict'

/*
|--------------------------------------------------------------------------
| Body Parser
|--------------------------------------------------------------------------
|
| Body parser parses request body to fetch post data and form uploads.
| Let this file be here if you want to parse request body
|
*/

const formidable = use('formidable')
const rawBody = use('raw-body')

class BodyParser {
/**
* @description parses request body to fetch post data and form
* @method parse
* uploads
* @param {Object} form
* @param {Object} request
* @return {void}
* @public
*/
parse (form, request) {
return new Promise(function (resolve, reject) {
/**
* here we check for request type, handle text/*
* request via raw body parser
*/
if (request.is('text/*')) {
rawBody(request.request)
.then(function (buffer) {
resolve({raw: buffer.toString()})
}).catch(reject)
return
}
/**
* here we parse json data, multipart uploads and x-form-urlencoded
* request
*/
form.parse(request.request, function (error, fields, files) {
/**
* reject with error if there is an error
*/
if (error) {
return reject(error)
}
resolve({fields, files})
})
})
}

/**
* @description this method gets called by adonis
* @method handle
* middleware layer.
* @param {Object} request
* @param {Object} response
* @param {Function} next
* @return {void}
* @public
*/
* handle (request, response, next) {
/**
* parsing incoming request form
*/
const form = new formidable.IncomingForm()

try {
const formFields = yield this.parse(form, request)
/**
* make sure to set request body, so that
* adonnis request can use it
* @type {Object}
*/

request.request._body = formFields.fields || null
/**
* make sure to set uploaded files , so that
* adonis request can return uploaded files.
* @type {Object}
*/

request._files = formFields.files || null
/**
* Setting up request raw body if available
* @type {String}
*/
request._raw = formFields.raw || null

yield next
} catch (e) {
throw e
}
}
}

module.exports = BodyParser
@@ -0,0 +1,114 @@
'use strict'

/*
|--------------------------------------------------------------------------
| CORS
|--------------------------------------------------------------------------
|
| Cors middlware will allow/disallow request based upon configuration
| defined in config/cors.js file.
|
*/

class Cors {

constructor (Config) {
this.origin = Config.get('cors.origin', false)
this.methods = Config.get('cors.methods', ['GET', 'POST', 'PUT'])
this.headers = Config.get('cors.headers', false)
this.credentials = Config.get('cors.credentials', false)
this.exposeHeaders = Config.get('cors.exposeHeaders', false)
this.maxAge = Config.get('cors.maxAge', false)
}

/**
* @description returns origin to be allowed for CORS request. It is
* calculated fron cors.origin field inside config file.
* @method _getOrigin
* @param {String} origin
* @return {Mixed}
* @public
*/
_getOrigin (origin) {
if (this.origin === true) {
return origin
}
if (typeof (this.origin) === 'function') {
return this.origin(origin)
}
return this.origin
}

/**
* @description returns headers to be allowed on cors request based
* upon input from cors.headers inside config file
* @method _getHeaders
* @param {String} headers
* @return {Mixed}
* @public
*/
_getHeaders (headers) {
if (this.headers === true) {
return headers
}
if (typeof (this.headers) === 'function') {
return this.headers(headers)
}
return this.headers
}

/**
* @description middleware handler to allow/disallow preflight requests
* based upon defined configuration for cors.
* @method handle
* @param {Object} request
* @param {Object} response
* @param {Function} next
* @return {void}
* @public
*/
* handle (request, response, next) {
/**
* required headers to be defined on every request
*/
response.header('Access-Control-Allow-Origin', this._getOrigin(request.header('origin')))
response.header('Access-Control-Allow-Methods', this.methods)
response.header('Access-Control-Allow-Credentials', this.credentials)

/**
* setting up cors headers only if they are not set to false.
*/
const corsHeaders = this._getHeaders(request.header('Access-Control-Request-Headers'))
if (corsHeaders) {
response.header('Access-Control-Allow-Headers', corsHeaders)
}

/**
* setting up exposed headers if defined
*/
if (this.exposeHeaders) {
response.header('Access-Control-Expose-Headers', this.exposeHeaders)
}

/**
* setting up max age if defined
*/
if (this.maxAge) {
response.header('Access-Control-Allow-Max-Age', this.maxAge)
}

/**
* if request is for OPTIONS send 204 otherwise yield it to
* next middleware
*/
if (request.method() === 'OPTIONS') {
response.status(204).send()
return
}

yield next
}

}

module.exports = Cors
@@ -0,0 +1,40 @@
'use strict'

/*
|--------------------------------------------------------------------------
| Flash Sessions
|--------------------------------------------------------------------------
|
| Flash sessions are one time only session values. It is helpful for
| scanerios where you want to display errors messages on form these
| errors will live for one time only.
|
*/

class Flash {

constructor (View) {
this.view = View
}

* handle (request, response, next) {
/**
* pulling flash messages from session, pull method will
* remove the flash messages from session itself
*/
const flashMessages = yield request.session.pull('flash_messages')
request._flash_messages = flashMessages || {}

/**
* adding view global method to have access to old method from current
* request
*/
this.view.global('old', function (key, defaultValue) {
return request.old(key, defaultValue)
})
yield next
}

}

module.exports = Flash
Oops, something went wrong.

0 comments on commit ccb2edb

Please sign in to comment.