Added the ability to assign a user an iOS UDID, and login with it.

This commit is contained in:
Scott Erickson 2014-11-20 15:54:15 -08:00
parent fae09aad00
commit a18537b065
4 changed files with 36 additions and 4 deletions

View file

@ -50,6 +50,7 @@ visa = c.shortString
_.extend UserSchema.properties,
email: c.shortString({title: 'Email', format: 'email'})
iosUDID: c.shortString({format: 'hidden'})
firstName: c.shortString({title: 'First Name'})
lastName: c.shortString({title: 'Last Name'})
gender: {type: 'string', 'enum': ['male', 'female']}

View file

@ -15,7 +15,14 @@ module.exports.setup = (app) ->
authentication.use(new LocalStrategy(
(username, password, done) ->
User.findOne({emailLower: username.toLowerCase()}).exec((err, user) ->
# kind of a hacky way to make it possible for iPads to 'log in' with their unique device id
if username.length is 40 and '@' not in username # must be a UDID
q = { iosUDID: username }
else
q = { emailLower: username.toLowerCase() }
User.findOne(q).exec((err, user) ->
return done(err) if err
return done(null, false, {message: 'not found', property: 'email'}) if not user
passwordReset = (user.get('passwordReset') or '').toLowerCase()

View file

@ -200,7 +200,7 @@ UserSchema.statics.editableProperties = [
'firstName', 'lastName', 'gender', 'facebookID', 'gplusID', 'emails',
'testGroupNumber', 'music', 'hourOfCode', 'hourOfCodeComplete', 'preferredLanguage',
'wizard', 'aceConfig', 'autocastDelay', 'lastLevel', 'jobProfile', 'savedEmployerFilterAlerts',
'heroConfig'
'heroConfig', 'iosUDID'
]
UserSchema.plugin plugins.NamedPlugin

View file

@ -15,7 +15,31 @@ describe '/auth/whoami', ->
describe '/auth/login', ->
it 'clears Users first', (done) ->
it 'clears Users', (done) ->
clearModels [User], (err) ->
throw err if err
request.get getURL('/auth/whoami'), ->
throw err if err
done()
it 'allows logging in by iosUDID', (done) ->
req = request.post(getURL('/db/user'),
(error, response) ->
expect(response).toBeDefined()
expect(response.statusCode).toBe(200)
req = request.post(urlLogin, (error, response) ->
expect(response.statusCode).toBe(200)
done()
)
form = req.form()
form.append('username', '0123456789012345678901234567890123456789')
form.append('password', '12345')
)
form = req.form()
form.append('iosUDID', '0123456789012345678901234567890123456789')
form.append('password', '12345')
it 'clears Users', (done) ->
clearModels [User], (err) ->
throw err if err
request.get getURL('/auth/whoami'), ->
@ -84,7 +108,7 @@ describe '/auth/reset', ->
form = req.form()
form.append('username', 'scott@gmail.com')
it 'can\'t reset an unknow user', (done) ->
it 'can\'t reset an unknown user', (done) ->
req = request.post(urlReset, (error, response) ->
expect(response).toBeDefined()
expect(response.statusCode).toBe(404)