diff --git a/api/config/api-url.js b/api/config/api-url.js
index 199f425..58b1170 100644
--- a/api/config/api-url.js
+++ b/api/config/api-url.js
@@ -10,4 +10,5 @@ module.exports = {
signatures: '/signatures',
squads: '/squads',
users: '/users',
+ account: '/account'
};
diff --git a/api/models/app-user.js b/api/models/app-user.js
index 09083d3..b83599d 100644
--- a/api/models/app-user.js
+++ b/api/models/app-user.js
@@ -13,6 +13,11 @@ const AppUserSchema = new Schema({
type: String,
required: true
},
+ squad: {
+ type: mongoose.Schema.Types.ObjectId,
+ ref: 'Squad',
+ default: null
+ },
permission: {
type: Number,
get: v => Math.round(v),
diff --git a/api/routes/account.js b/api/routes/account.js
new file mode 100644
index 0000000..f741810
--- /dev/null
+++ b/api/routes/account.js
@@ -0,0 +1,90 @@
+"use strict";
+
+// modules
+const express = require('express');
+const logger = require('debug')('cc:awardings');
+
+// HTTP status codes by name
+const codes = require('./http-codes');
+
+const routerHandling = require('../middleware/router-handling');
+
+// Mongoose Model using mongoDB
+const AppUserModel = require('../models/app-user');
+
+const account = express.Router();
+
+
+account.route('/')
+ .get((req, res, next) => {
+ AppUserModel.find({}).populate('squad').exec((err, items) => {
+ if (err) {
+ err.status = codes.servererror;
+ return next(err);
+ }
+ res.locals.items = items;
+ res.locals.processed = true;
+ next();
+ })
+ })
+ .all(
+ routerHandling.httpMethodNotAllowed
+ );
+
+// routes **********************
+account.route('/:id')
+ .patch((req, res, next) => {
+ if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
+ // little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
+ const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + " " + req.body._id);
+ err.status = codes.notfound;
+ next(err);
+ return; // prevent node to process this function further after next() has finished.
+ }
+
+ // increment version manually as we do not use .save(.)
+ req.body.updatedAt = new Date();
+ req.body.$inc = {__v: 1};
+
+ // PATCH is easier with mongoose than PUT. You simply update by all data that comes from outside. no need to reset attributes that are missing.
+ AppUserModel.findByIdAndUpdate(req.params.id, req.body, {new: true}).populate('squad').exec((err, item) => {
+ if (err) {
+ err.status = codes.wrongrequest;
+ }
+ else if (!item) {
+ err = new Error("appUser not found");
+ err.status = codes.notfound;
+ }
+ else {
+ res.locals.items = item;
+ }
+ next(err);
+ })
+ })
+
+ .delete((req, res, next) => {
+ AppUserModel.findByIdAndRemove(req.params.id, (err, item) => {
+ if (err) {
+ err.status = codes.wrongrequest;
+ }
+ else if (!item) {
+ err = new Error("item not found");
+ err.status = codes.notfound;
+ }
+ // we don't set res.locals.items and thus it will send a 204 (no content) at the end. see last handler user.use(..)
+ res.locals.processed = true;
+ next(err); // this works because err is in normal case undefined and that is the same as no parameter
+ });
+ })
+
+ .all(
+ routerHandling.httpMethodNotAllowed
+ );
+
+
+// this middleware function can be used, if you like or remove it
+// it looks for object(s) in res.locals.items and if they exist, they are send to the client as json
+account.use(routerHandling.emptyResponse);
+
+
+module.exports = account;
diff --git a/api/routes/authenticate.js b/api/routes/authenticate.js
index dd05c6e..8ab87fa 100644
--- a/api/routes/authenticate.js
+++ b/api/routes/authenticate.js
@@ -25,7 +25,7 @@ const authenticate = express.Router();
// routes **********************
authenticate.route('/')
.post((req, res, next) => {
- authCheck(req.body.username, req.body.password)
+ authCheck(req.body.username, req.body.password, res)
.then((user) => {
if (user) {
// authentication successful
@@ -44,7 +44,7 @@ authenticate.route('/')
routerHandling.httpMethodNotAllowed
);
-let authCheck = (username, password) => {
+let authCheck = (username, password, res) => {
const deferred = Q.defer();
AppUserModel.findOne({username: username}, (err, user) => {
@@ -52,6 +52,9 @@ let authCheck = (username, password) => {
const diff = 3 * 60 * 24; // time till expiration [minutes]
+ if (user && !user.activated) {
+ res.status(codes.unauthorized).send('Account is not yet activated');
+ }
if (user && user.activated && bcrypt.compareSync(password, user.password)) {
// authentication successful
deferred.resolve({
@@ -70,44 +73,6 @@ let authCheck = (username, password) => {
return deferred.promise;
};
-
-// ******************************** EDITING USING ADMIN PANEL ************************
-
-authenticate.route('/editUser/:id')
- .patch(apiAuthenticationMiddleware, checkAdmin, (req, res, next) => {
- if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
- // little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
- const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + " " + req.body._id);
- err.status = codes.notfound;
- next(err);
- return; // prevent node to process this function further after next() has finished.
- }
-
- // increment version manually as we do not use .save(.)
- req.body.updatedAt = new Date();
- req.body.$inc = {__v: 1};
-
- // PATCH is easier with mongoose than PUT. You simply update by all data that comes from outside. no need to reset attributes that are missing.
- AppUserModel.findByIdAndUpdate(req.params.id, req.body, {new: true}, (err, item) => {
- if (err) {
- err.status = codes.wrongrequest;
- }
- else if (!item) {
- err = new Error("appUser not found");
- err.status = codes.notfound;
- }
- else {
- res.locals.items = item;
- }
- next(err);
- })
- })
-
- .all(
- routerHandling.httpMethodNotAllowed
- );
-
-
// ******************************** SIGNUP ************************
authenticate.route('/signup')
diff --git a/api/routes/users.js b/api/routes/users.js
index 1af4034..797cf72 100644
--- a/api/routes/users.js
+++ b/api/routes/users.js
@@ -187,7 +187,7 @@ users.route('/:id')
return; // prevent node to process this function further after next() has finished.
}
// main difference of PUT and PATCH is that PUT expects all data in request: checked by using the schema
- var video = new UserModel(req.body);
+ var user = new UserModel(req.body);
UserModel.findById(req.params.id, req.body, {new: true}, function (err, item) {
// with parameter {new: true} the TweetNModel will return the new and changed object from the DB and not the old one.
if (err) {
@@ -200,7 +200,7 @@ users.route('/:id')
return next(err);
}
// optional task 3b: check that version is still accurate
- else if (video.__v !== item.__v) {
+ else if (user.__v !== item.__v) {
err = new Error("version outdated. Meanwhile update on item happened. Please GET resource again")
err.status = codes.conflict;
return next(err);
@@ -209,7 +209,7 @@ users.route('/:id')
for (var field in UserModel.schema.paths) {
if ((field !== '_id') && (field !== '__v')) {
// this includes undefined. is important to reset attributes that are missing in req.body
- item.set(field, video[field]);
+ item.set(field, user[field]);
}
}
diff --git a/api/server.js b/api/server.js
index e60f222..a5fa160 100644
--- a/api/server.js
+++ b/api/server.js
@@ -21,6 +21,7 @@ const signatureCronJob = require('./cron-job/update-signatures');
// router modules
const authenticateRouter = require('./routes/authenticate');
+const accountRouter = require('./routes/account');
const overviewRouter = require('./routes/overview');
const userRouter = require('./routes/users');
const squadRouter = require('./routes/squads');
@@ -73,6 +74,7 @@ app.use(urls.ranks, rankRouter);
app.use(urls.decorations, decorationRouter);
app.use(urls.awards, apiAuthenticationMiddleware, checkHl, awardingRouter);
app.use(urls.command, apiAuthenticationMiddleware, checkAdmin, commandRouter);
+app.use(urls.account, apiAuthenticationMiddleware, checkAdmin, accountRouter);
// send index.html on all different paths
app.use(function (req, res) {
diff --git a/static/src/app/admin/admin.component.css b/static/src/app/admin/admin.component.css
new file mode 100644
index 0000000..597fa90
--- /dev/null
+++ b/static/src/app/admin/admin.component.css
@@ -0,0 +1,34 @@
+.overview {
+ position: fixed;
+ overflow-y: scroll;
+ overflow-x: hidden;
+ bottom: 20px;
+ width: 100%;
+ padding-left: 50px;
+ padding-top: 190px;
+ margin-left: 10px;
+ height: 100vh;
+}
+
+.trash {
+ cursor: pointer;
+}
+
+.table {
+ overflow-wrap: break-word;
+ table-layout: fixed;
+}
+
+.table-container {
+ margin-top: 10px;
+ overflow-x: auto;
+}
+
+.table-head {
+ background: #222222;
+ color: white;
+}
+
+.cell-outline {
+ outline: 1px solid #D4D4D4;
+}
diff --git a/static/src/app/admin/admin.component.html b/static/src/app/admin/admin.component.html
new file mode 100644
index 0000000..1538cdd
--- /dev/null
+++ b/static/src/app/admin/admin.component.html
@@ -0,0 +1,71 @@
+