   hash = crypto.createHash 'md5'
   hash.update str
   hash.digest 'hex'
+
+validEmail = (email) ->
+  /^[a-zA-Z0-9+._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test email
+
+escapeURL = require('querystring').escape
 
 class Team
   build: (options) ->


_.extend Person, {
  login: (credentials, fn) ->
    @first { email: /^#{credentials.email}$/i }, (error, person) ->
      return fn ['Unknown email'] unless person?
      return fn ['Invalid password'] unless person.passwordHash is md5 credentials.password
      person.token = Math.uuid()

    @save fn

  validate: ->
    ['Invalid email address'] unless validEmail @email

  beforeSave: (fn) ->
    @email = @email?.trim()?.toLowerCase()
