diff --git a/app/controllers/user.js b/app/controllers/user.js index 999a6b40..f152ca50 100644 --- a/app/controllers/user.js +++ b/app/controllers/user.js @@ -45,16 +45,16 @@ exports.create = (req, res) => { }; exports.generate = async (req, res) => { - const { legoUser, email, ignoreExistingUser } = req.body; + const { identifier, email, ignoreExistingUser } = req.body; - if (!legoUser) throw new errors.InvalidPayloadError('legoUser'); + if (!identifier) throw new errors.InvalidPayloadError('identifier'); if (!email) throw new errors.InvalidPayloadError('email'); // Try to fetch an entry from the register with this username - const entry = await Register.findOne({ legoUser }).exec(); + const entry = await Register.findOne({ identifier }).exec(); if (entry && ignoreExistingUser) { - return res.status(409).json(legoUser); + return res.status(409).json(identifier); } // Entry has no user this user is allready activated @@ -63,7 +63,7 @@ exports.generate = async (req, res) => { .then(() => res.status(409).json({ status: 'allready signed in', - user: legoUser, + user: identifier, }) ) .catch((err) => { @@ -86,7 +86,7 @@ exports.generate = async (req, res) => { .then(() => res.status(201).json({ status: 'regenerated', - user: legoUser, + user: identifier, }) ) .catch((err) => { @@ -109,9 +109,9 @@ exports.generate = async (req, res) => { return User.register(user, password) .then((createdUser) => mailHandler('send', { email, username: createdUser.username, password }) - .then(() => new Register({ legoUser, email, user }).save()) + .then(() => new Register({ identifier, email, user }).save()) .then(() => - res.status(201).json({ status: 'generated', user: legoUser }) + res.status(201).json({ status: 'generated', user: identifier }) ) .catch((err) => { throw new errors.MailError(err); diff --git a/app/errors/index.js b/app/errors/index.js index 97e85d53..75d2ea87 100644 --- a/app/errors/index.js +++ b/app/errors/index.js @@ -203,16 +203,16 @@ class DuplicateUsernameError extends Error { exports.DuplicateUsernameError = DuplicateUsernameError; -class DuplicateLegoUserError extends Error { +class DuplicateIdentifierError extends Error { constructor() { super(); - this.name = 'DuplicateLegoUserError'; - this.message = 'This LEGO user has allready gotten a user.'; + this.name = 'DuplicateIdentifierError'; + this.message = 'This identifier has allready gotten a user.'; this.status = 409; } } -exports.DuplicateLegoUserError = DuplicateLegoUserError; +exports.DuplicateIdentifierError = DuplicateIdentifierError; class AlreadyActiveElectionError extends Error { constructor() { diff --git a/app/models/register.js b/app/models/register.js index 0b1f0a8f..de258b4f 100644 --- a/app/models/register.js +++ b/app/models/register.js @@ -3,7 +3,7 @@ const mongoose = require('mongoose'); const Schema = mongoose.Schema; const registerSchema = new Schema({ - legoUser: { + identifier: { type: String, required: true, unique: true, diff --git a/app/views/partials/moderator/generateUser.pug b/app/views/partials/moderator/generateUser.pug index a76ecf31..743937e2 100644 --- a/app/views/partials/moderator/generateUser.pug +++ b/app/views/partials/moderator/generateUser.pug @@ -2,12 +2,12 @@ .col-xs-12.col-sm-offset-3.col-sm-6.col-md-offset-4.col-md-4.text-center form.form-group(ng-submit='generateUser(user)', name='generateUserForm') .form-group - label LEGO User + label Identifikator input.form-control( type='text', - name='legoUser', - placeholder='Skriv inn LEGO User', - ng-model='user.legoUser' + name='identifier', + placeholder='Skriv inn identifikator', + ng-model='user.identifier' ) .form-group diff --git a/app/views/partials/moderator/manageRegister.pug b/app/views/partials/moderator/manageRegister.pug index f815ab63..cceb8ad5 100644 --- a/app/views/partials/moderator/manageRegister.pug +++ b/app/views/partials/moderator/manageRegister.pug @@ -7,7 +7,7 @@ | laget med "Registrer bruker" eller "QR" vil ikke vises under. .center(style='margin-top: 50px') hr - .usage-flex + .usage-flex(style='margin: 0') h4(style='text-align:right') Totalt {{ registers.length }} genererte brukere label Search: input(ng-model='searchText') @@ -15,12 +15,12 @@ table(style='width:100%; margin-top: 30px') thead(style='border-bottom:2px solid black') tr - th Brukernavn + th Identifikator th Email th(style='text-align:center') Fullført registrering tbody(style='font-size:18px') tr(ng-repeat='register in registers | filter:searchText') - th {{ register.legoUser }} + th {{ register.identifier }} th {{ register.email }} th(style='text-align:center') {{ register.user ? "Nei" : "Ja" }} th(style='text-align:right') diff --git a/client/controllers/generateUserCtrl.js b/client/controllers/generateUserCtrl.js index a6018b42..aec6efc9 100644 --- a/client/controllers/generateUserCtrl.js +++ b/client/controllers/generateUserCtrl.js @@ -19,7 +19,7 @@ module.exports = [ switch (response.status) { case 409: alertService.addError( - 'Denne LEGO brukeren har allerede fått en bruker.' + 'Denne idenfikatoren har allerede fått en bruker.' ); break; default: diff --git a/deployment/sync/main.go b/deployment/sync/main.go index e7613477..42dd8093 100644 --- a/deployment/sync/main.go +++ b/deployment/sync/main.go @@ -193,11 +193,11 @@ func runLegoToVoteSync(interrupt chan os.Signal, url *url.URL, jwt string) error } voteFormData := struct { - Email string `json:"email"` - LegoUser string `json:"legoUser"` + Email string `json:"email"` + Identifier string `json:"identifier"` }{ - Email: legoUserData.Email, - LegoUser: action.Payload.User.Username, + Email: legoUserData.Email, + Identifier: action.Payload.User.Username, } out, err := json.Marshal(voteFormData) diff --git a/test/api/register.test.js b/test/api/register.test.js index 0cf7d8e3..d66a3660 100644 --- a/test/api/register.test.js +++ b/test/api/register.test.js @@ -19,7 +19,7 @@ describe('Register API', () => { passportStub.login(this.moderatorUser.username); await request(app) .post('/api/user/generate') - .send({ legoUser: 'username', email: 'email@domain.com' }); + .send({ identifier: 'username', email: 'email@domain.com' }); }); after(() => { @@ -34,7 +34,7 @@ describe('Register API', () => { .expect(200) .expect('Content-Type', /json/); body.length.should.equal(1); - body[0].legoUser.should.equal('username'); + body[0].identifier.should.equal('username'); body[0].email.should.equal('email@domain.com'); }); diff --git a/test/api/user.test.js b/test/api/user.test.js index 1c0076ec..ccccf83f 100644 --- a/test/api/user.test.js +++ b/test/api/user.test.js @@ -42,7 +42,7 @@ describe('User API', () => { }; const genUserData = { - legoUser: 'legoUsername', + identifier: 'identifiername', email: 'test@user.com', }; @@ -376,7 +376,7 @@ describe('User API', () => { .expect(201) .expect('Content-Type', /json/); body.status.should.equal('generated'); - body.user.should.equal(genUserData.legoUser); + body.user.should.equal(genUserData.identifier); }); it('should be not be possible to generate a user for a user', async function () { @@ -390,7 +390,7 @@ describe('User API', () => { error.status.should.equal(403); }); - it('should get an error when generating user with no legoUser', async function () { + it('should get an error when generating user with no identifier', async function () { passportStub.login(this.moderatorUser.username); const { body: error } = await request(app) .post('/api/user/generate') @@ -399,14 +399,14 @@ describe('User API', () => { .expect('Content-Type', /json/); error.name.should.equal('InvalidPayloadError'); error.status.should.equal(400); - error.message.should.equal('Missing property legoUser from payload.'); + error.message.should.equal('Missing property identifier from payload.'); }); it('should get an error when generating user with no email', async function () { passportStub.login(this.moderatorUser.username); const { body: error } = await request(app) .post('/api/user/generate') - .send({ legoUser: 'correct', password: 'wrong' }) + .send({ identifier: 'correct', password: 'wrong' }) .expect(400) .expect('Content-Type', /json/); error.name.should.equal('InvalidPayloadError'); @@ -422,11 +422,13 @@ describe('User API', () => { .expect(201) .expect('Content-Type', /json/); bodyOne.status.should.equal('generated'); - bodyOne.user.should.equal(genUserData.legoUser); + bodyOne.user.should.equal(genUserData.identifier); // Check that the register index and the user was created - const register = await Register.findOne({ legoUser: genUserData.legoUser }); - register.legoUser.should.equal(genUserData.legoUser); + const register = await Register.findOne({ + identifier: genUserData.identifier, + }); + register.identifier.should.equal(genUserData.identifier); register.email.should.equal(genUserData.email); const user = await User.findOne({ _id: register.user }); should.exist(user); @@ -439,7 +441,7 @@ describe('User API', () => { .expect(201) .expect('Content-Type', /json/); bodyTwo.status.should.equal('regenerated'); - bodyTwo.user.should.equal(genUserData.legoUser); + bodyTwo.user.should.equal(genUserData.identifier); }); it('should not be possible to generate the same user twice if they are active', async function () { @@ -450,10 +452,12 @@ describe('User API', () => { .expect(201) .expect('Content-Type', /json/); bodyOne.status.should.equal('generated'); - bodyOne.user.should.equal(genUserData.legoUser); + bodyOne.user.should.equal(genUserData.identifier); // Get the register and fake that they have logged in - const register = await Register.findOne({ legoUser: genUserData.legoUser }); + const register = await Register.findOne({ + identifier: genUserData.identifier, + }); register.user = null; await register.save();