/*!
 * Timekeeper
 * 2016 laudeon <audeon.louis@gmail.com>
 * MIT Licensed
 */
'use strict'

const formHandler = require('express-form-handler')
const MongooseStrategy = require('express-form-handler-mongoose')
const User = require('./../models').user
 
let form = formHandler.create([
  {
    name: 'email',
    label: 'email',
    format: formHandler.format.email(),
    rules: [
      formHandler.rule.required()
    ]
  },
  {
    name: 'oldPassword',
    label: 'old password',
    format: formHandler.format.string(),
    rules: []
  },
  {
    name: 'newPassword',
    label: 'new password',
    format: formHandler.format.string(),
    rules: [
      formHandler.rule.minlength(6)
    ]
  },
  {
    name: 'newPasswordConfirm',
    label: 'new password conformation',
    format: formHandler.format.string(),
    rules: [
      formHandler.rule.minlength(6),
      formHandler.rule.equalsto('newPassword')
    ]
  }
])

form.config({
  modelStrategy: new MongooseStrategy(User)
})

module.exports = exports = form
