Add user display name and menu entry

feature/user-self-management
Florian Hartwich 2017-09-09 13:24:36 +02:00
parent 51f78bd5f3
commit 9e632989ee
6 changed files with 12 additions and 118 deletions

View File

@ -9,6 +9,10 @@ const AppUserSchema = new Schema({
required: true, required: true,
unique: true unique: true
}, },
display_name: {
type: String,
required: true
},
password: { password: {
type: String, type: String,
required: true required: true

View File

@ -8,9 +8,6 @@ const Q = require('q');
const _ = require('lodash'); const _ = require('lodash');
const logger = require('debug')('cc:authenticate'); const logger = require('debug')('cc:authenticate');
const apiAuthenticationMiddleware = require('../middleware/auth-middleware');
const checkAdmin = require('../middleware/permission-check').checkAdmin;
// HTTP status codes by name // HTTP status codes by name
const codes = require('./http-codes'); const codes = require('./http-codes');
@ -60,6 +57,7 @@ let authCheck = (username, password, res) => {
deferred.resolve({ deferred.resolve({
_id: user._id, _id: user._id,
username: user.username, username: user.username,
display_name: user.display_name,
permission: user.permission, permission: user.permission,
squad: user.squad, squad: user.squad,
token: jwt.sign({sub: user._id}, config.secret, {expiresIn: diff * 60}), token: jwt.sign({sub: user._id}, config.secret, {expiresIn: diff * 60}),
@ -115,6 +113,7 @@ let create = (userParam) => {
// add hashed password to user object // add hashed password to user object
user.password = bcrypt.hashSync(userParam.password, 10); user.password = bcrypt.hashSync(userParam.password, 10);
user.username = user.username.toLowerCase(); user.username = user.username.toLowerCase();
user.display_name = user.username;
const newUser = new AppUserModel(user); const newUser = new AppUserModel(user);
newUser.save((err, doc) => { newUser.save((err, doc) => {

View File

@ -77,6 +77,9 @@
<li *ngIf="loginService.hasPermission(4)" routerLinkActive="active"> <li *ngIf="loginService.hasPermission(4)" routerLinkActive="active">
<a routerLink='{{config.adminPanelPath}}' class="link">Admin Panel</a> <a routerLink='{{config.adminPanelPath}}' class="link">Admin Panel</a>
</li> </li>
<li *ngIf="loginService.isLoggedIn()" class="link" style="cursor: pointer">
<a routerLink="{{config.editProfilePath}}">{{loginService.getCurrentUser().display_name}}</a>
</li>
<li *ngIf="loginService.isLoggedIn()" class="link" style="cursor: pointer"> <li *ngIf="loginService.isLoggedIn()" class="link" style="cursor: pointer">
<a (click)="logout()">Abmelden</a> <a (click)="logout()">Abmelden</a>
</li> </li>

View File

@ -31,5 +31,6 @@ export const RouteConfig = {
requestAwardPath: 'award', requestAwardPath: 'award',
requestPromotionPath: 'promotion', requestPromotionPath: 'promotion',
confirmAwardPath: 'confirm-award', confirmAwardPath: 'confirm-award',
confirmPromotionPath: 'confirm-promotion' confirmPromotionPath: 'confirm-promotion',
editProfilePath: 'edit-profile'
} }

View File

@ -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<any> {
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<any> {
// 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];

View File

@ -1,6 +1,7 @@
export interface AppUser { export interface AppUser {
_id?: string; _id?: string;
username?: string; username?: string;
display_name?: string;
squad?: Squad; squad?: Squad;
secret?: string; secret?: string;
activated: boolean; activated: boolean;