       done(null, @)
   )
 
-fetchDistinguishedName = (username) ->
+fetchUserFromLDAP = (username) ->
   deferred = Q.defer()
 
   ldap = require('ldapjs')

        {
          filter:"(sAMAccountName=#{username})"
          scope: 'sub'
          attributes: ["distinguishedName"]
        },
        (err, search) ->
          theUser = null

          search.on('searchEntry', (entry) ->
            theUser = entry.object
            deferred.resolve(theUser.distinguishedName)
          )

          search.on('end', (result) ->

userSchema.statics.createFromLDAPUsername = (username) ->
  deferred = Q.defer()

  fetchUserFromLDAP(
    username
  ).then( (user) ->
    user = new User(
      email: username
      distinguishedName: user.distinguishedName
      name: user.name
    )

    Q.nsend(
      user, 'save'
