From 9e632989ee8b93d1a74a83a4f6c324827fc8dfed Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Sat, 9 Sep 2017 13:24:36 +0200 Subject: [PATCH] Add user display name and menu entry --- api/models/app-user.js | 4 + api/routes/authenticate.js | 5 +- static/src/app/app.component.html | 3 + static/src/app/app.config.ts | 3 +- static/src/app/models/app-validators.ts | 114 ---------------------- static/src/app/models/model-interfaces.ts | 1 + 6 files changed, 12 insertions(+), 118 deletions(-) delete mode 100644 static/src/app/models/app-validators.ts diff --git a/api/models/app-user.js b/api/models/app-user.js index b83599d..44df729 100644 --- a/api/models/app-user.js +++ b/api/models/app-user.js @@ -9,6 +9,10 @@ const AppUserSchema = new Schema({ required: true, unique: true }, + display_name: { + type: String, + required: true + }, password: { type: String, required: true diff --git a/api/routes/authenticate.js b/api/routes/authenticate.js index e93baa5..3c41c42 100644 --- a/api/routes/authenticate.js +++ b/api/routes/authenticate.js @@ -8,9 +8,6 @@ const Q = require('q'); const _ = require('lodash'); const logger = require('debug')('cc:authenticate'); -const apiAuthenticationMiddleware = require('../middleware/auth-middleware'); -const checkAdmin = require('../middleware/permission-check').checkAdmin; - // HTTP status codes by name const codes = require('./http-codes'); @@ -60,6 +57,7 @@ let authCheck = (username, password, res) => { deferred.resolve({ _id: user._id, username: user.username, + display_name: user.display_name, permission: user.permission, squad: user.squad, token: jwt.sign({sub: user._id}, config.secret, {expiresIn: diff * 60}), @@ -115,6 +113,7 @@ let create = (userParam) => { // add hashed password to user object user.password = bcrypt.hashSync(userParam.password, 10); user.username = user.username.toLowerCase(); + user.display_name = user.username; const newUser = new AppUserModel(user); newUser.save((err, doc) => { diff --git a/static/src/app/app.component.html b/static/src/app/app.component.html index e4e67bf..1c4645c 100644 --- a/static/src/app/app.component.html +++ b/static/src/app/app.component.html @@ -77,6 +77,9 @@
  • Admin Panel
  • + diff --git a/static/src/app/app.config.ts b/static/src/app/app.config.ts index 2559dbd..de2e99c 100644 --- a/static/src/app/app.config.ts +++ b/static/src/app/app.config.ts @@ -31,5 +31,6 @@ export const RouteConfig = { requestAwardPath: 'award', requestPromotionPath: 'promotion', confirmAwardPath: 'confirm-award', - confirmPromotionPath: 'confirm-promotion' + confirmPromotionPath: 'confirm-promotion', + editProfilePath: 'edit-profile' } diff --git a/static/src/app/models/app-validators.ts b/static/src/app/models/app-validators.ts deleted file mode 100644 index dc5734a..0000000 --- a/static/src/app/models/app-validators.ts +++ /dev/null @@ -1,114 +0,0 @@ -import {Directive, forwardRef} from '@angular/core'; -import {AbstractControl, FormControl, NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '@angular/forms'; -import {UserService} from "../services/user-service/user.service"; - -export function asyncIfNotBacklogThenAssignee(control): Promise { - const promise = new Promise((resolve, reject) => { - setTimeout(() => { - resolve(ifNotBacklogThanAssignee(control)); - }, 500); - }); - return promise; -} - -export function ifNotBacklogThanAssignee(formGroup: FormControl): { [key: string]: any } { - const nameControl = formGroup.get('assignee.name'); - const stateControl = formGroup.get('state'); - if (!nameControl || !stateControl) { - return null; - } - if (stateControl.value !== 'BACKLOG' && - (!nameControl.value || nameControl.value === '')) { - return {'assigneeRequired': true}; - } - return null; -} - -@Directive({ - selector: '[ifNotBacklogThanAssignee]', - providers: [ - { - provide: NG_VALIDATORS, - useExisting: IfNotBacklogThanAssigneeValidatorDirective, multi: true - }] -}) -export class IfNotBacklogThanAssigneeValidatorDirective { - - public validate(formGroup: AbstractControl): { [key: string]: any } { - const nameControl = formGroup.get('assignee.name'); - const stateControl = formGroup.get('state'); - if (!nameControl || !stateControl) { - return null; - } - if (stateControl.value !== 'BACKLOG' && - (!nameControl.value || nameControl.value === '')) { - return {'assigneeRequired': true}; - } - return null; - } -} - -@Directive({ - selector: '[emailValidator]', - providers: [{ - provide: NG_VALIDATORS, - useExisting: EmailValidatorDirective, multi: true - }] -}) -export class EmailValidatorDirective { - validate(control: AbstractControl): { [key: string]: any } { - const re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; - if (!control.value || control.value === '' || re.test(control.value)) { - return null; - } else { - return {'invalidEMail': true}; - } - } -} - -export function emailValidator(control): { [key: string]: any } { - return new EmailValidatorDirective().validate(control); -} - -export function emailValidator2(control): { [key: string]: any } { - const re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; - if (!control.value || control.value === '' || re.test(control.value)) { - return null; - } else { - return {'invalidEMail': true}; - } -} - -@Directive({ - selector: '[pjmUserExistsValidator]', - providers: [ - { - provide: NG_ASYNC_VALIDATORS, - useExisting: forwardRef(() => UserExistsValidatorDirective), multi: true - } - ] -}) -export class UserExistsValidatorDirective { - constructor(private userService: UserService) { - } - - // validate(control: AbstractControl): Observable { - // return this.userService.checkUserExists(control.value) - // .map(userExists => { - // return (userExists === false) ? {userNotFound: true} : null; - // }); - // } -} - -@Directive({ - selector: '[emailValidator]', - providers: [ - {provide: NG_VALIDATORS, useValue: emailValidator, multi: true} - ] -}) -export class EmailValidatorWithFunctionDirective { -} - - -export const APPLICATION_VALIDATORS = [IfNotBacklogThanAssigneeValidatorDirective, - EmailValidatorDirective]; diff --git a/static/src/app/models/model-interfaces.ts b/static/src/app/models/model-interfaces.ts index a4ccc0a..bfac453 100644 --- a/static/src/app/models/model-interfaces.ts +++ b/static/src/app/models/model-interfaces.ts @@ -1,6 +1,7 @@ export interface AppUser { _id?: string; username?: string; + display_name?: string; squad?: Squad; secret?: string; activated: boolean;