mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
implementing user creation at admin page
This commit is contained in:
parent
5b00de3c10
commit
67d4d2be71
@ -41,5 +41,19 @@ export class Utils {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static enumToArray(EnumType):Array<{key:number;value:string;}>{
|
||||||
|
let arr:Array<{key:number;value:string;}> = [];
|
||||||
|
for(let enumMember in EnumType){
|
||||||
|
if(!EnumType.hasOwnProperty(enumMember)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let key = parseInt(enumMember, 10);
|
||||||
|
if (key >= 0) {
|
||||||
|
arr.push({key: key, value: EnumType[enumMember]});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,10 @@ export enum UserRoles{
|
|||||||
Guest = 1,
|
Guest = 1,
|
||||||
User = 2,
|
User = 2,
|
||||||
Admin = 3,
|
Admin = 3,
|
||||||
Developer = 4
|
Developer = 4,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class User {
|
export class User {
|
||||||
constructor(public id?:number,public name?:string,public email?:string, public password?:string, public role?:UserRoles){}
|
constructor(public id?:number,public name?:string,public email?:string, public password?:string, public role?:UserRoles){}
|
||||||
}
|
}
|
@ -5,7 +5,41 @@
|
|||||||
<h3 class="panel-title">User management</h3>
|
<h3 class="panel-title">User management</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<button class="button button-primary" (click)="addUser()">+ add user</button>
|
<button class="btn btn-default" data-toggle="modal" data-target="#myModal" (click)="initNewUser()">+ add
|
||||||
|
user
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal -->
|
||||||
|
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
|
||||||
|
aria-hidden="true">×</span></button>
|
||||||
|
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
|
||||||
|
</div>
|
||||||
|
<form (ngSubmit)="onSubmit()" #NewUserForm="ngForm">
|
||||||
|
<div class="modal-body">
|
||||||
|
<input type="text" class="form-control" placeholder="Username" autofocus
|
||||||
|
[(ngModel)]="newUser.name" ngControl="name" #name="ngForm" required>
|
||||||
|
<input type="password" class="form-control" placeholder="Password"
|
||||||
|
[(ngModel)]="newUser.password" ngControl="password" #name="ngForm" required>
|
||||||
|
<select class="form-control" [(ngModel)]="newUser.role" required>
|
||||||
|
<option *ngFor="let repository of userRoles" [value]="repository.key">{{repository.value}}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||||
|
<button type="button" class="btn btn-primary" data-dismiss="modal"
|
||||||
|
(click)="addNewUser()"
|
||||||
|
[disabled]="!NewUserForm.form.valid">Add User
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,27 +1,44 @@
|
|||||||
///<reference path="../../browser.d.ts"/>
|
///<reference path="../../browser.d.ts"/>
|
||||||
|
|
||||||
import {Component, OnInit} from 'angular2/core';
|
import {Component, OnInit} from "angular2/core";
|
||||||
import {AuthenticationService} from "../model/network/authentication.service.ts";
|
import {AuthenticationService} from "../model/network/authentication.service.ts";
|
||||||
import {Router} from "angular2/router";
|
import {Router} from "angular2/router";
|
||||||
import {FrameComponent} from "../frame/frame.component";
|
import {FrameComponent} from "../frame/frame.component";
|
||||||
|
import {User, UserRoles} from "../../../common/entities/User";
|
||||||
|
import {FORM_DIRECTIVES} from "angular2/common";
|
||||||
|
import {Utils} from "../../../common/Utils";
|
||||||
|
import {AdminService} from "./admin.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'admin',
|
selector: 'admin',
|
||||||
templateUrl: 'app/admin/admin.component.html',
|
templateUrl: 'app/admin/admin.component.html',
|
||||||
styleUrls:['app/admin/admin.component.css'],
|
styleUrls: ['app/admin/admin.component.css'],
|
||||||
directives:[FrameComponent]
|
directives: [FrameComponent, FORM_DIRECTIVES],
|
||||||
|
providers: [AdminService]
|
||||||
})
|
})
|
||||||
export class AdminComponent implements OnInit{
|
export class AdminComponent implements OnInit {
|
||||||
constructor(private _authService: AuthenticationService, private _router: Router) {
|
|
||||||
|
private newUser = new User();
|
||||||
|
private userRoles:Array<any>;
|
||||||
|
|
||||||
|
constructor(private _authService:AuthenticationService, private _router:Router, private _adminService:AdminService) {
|
||||||
|
this.userRoles = Utils.enumToArray(UserRoles);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(){
|
ngOnInit() {
|
||||||
if (!this._authService.isAuthenticated()) {
|
if (!this._authService.isAuthenticated() || this._authService.getUser().role < UserRoles.Admin) {
|
||||||
this._router.navigate(['Login']);
|
this._router.navigate(['Login']);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initNewUser() {
|
||||||
|
this.newUser = new User();
|
||||||
|
this.newUser.role = UserRoles.User;
|
||||||
|
}
|
||||||
|
|
||||||
|
addNewUser(){
|
||||||
|
this._adminService.createUser(this.newUser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,19 +3,19 @@
|
|||||||
import {Injectable} from 'angular2/core';
|
import {Injectable} from 'angular2/core';
|
||||||
import {NetworkService} from "../model/network/network.service.ts";
|
import {NetworkService} from "../model/network/network.service.ts";
|
||||||
import {Http} from "angular2/http";
|
import {Http} from "angular2/http";
|
||||||
import {Message} from "../../../common/entities/Message";
|
import {Message} from "../../../common/entities/Message";
|
||||||
import {Directory} from "../../../common/entities/Directory";
|
import {User} from "../../../common/entities/User";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GalleryService extends NetworkService{
|
export class AdminService extends NetworkService{
|
||||||
|
|
||||||
|
|
||||||
constructor(_http:Http){
|
constructor(_http:Http){
|
||||||
super(_http);
|
super(_http);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getDirectory(directoryName:string): Promise<Message<Directory>>{
|
public createUser(user:User): Promise<Message<string>>{
|
||||||
return this.getJson("/gallery/"+directoryName);
|
return this.putJson("/user",{newUser:user});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1 @@
|
|||||||
<app-frame>
|
|
||||||
<md-card>
|
|
||||||
<md-card-title>User management</md-card-title>
|
|
||||||
<md-card-content>
|
|
||||||
|
|
||||||
<button md-button (click)="addUser()">+ add user</button>
|
|
||||||
</md-card-content>
|
|
||||||
</md-card>
|
|
||||||
</app-frame>
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="col-sm-offset-3 col-sm-6 col-lg-4 col-lg-offset-4">
|
<div class="col-sm-offset-3 col-sm-6 col-lg-4 col-lg-offset-4">
|
||||||
<form class="form-signin" (ngSubmit)="onSubmit()" #LoginForm="ngForm">
|
<form class="form-signin" #LoginForm="ngForm">
|
||||||
<h2 class="form-signin-heading">Please sign in</h2>
|
<h2 class="form-signin-heading">Please sign in</h2>
|
||||||
<input type="email" class="form-control" placeholder="Email address" autofocus
|
<input type="text" class="form-control" placeholder="Username" autofocus
|
||||||
[(value)]="loginCredential.username" ngControl="name" #name="ngForm" required>
|
[(ngModel)]="loginCredential.username" ngControl="name" #name="ngForm" required>
|
||||||
<input type="password" class="form-control" placeholder="Password"
|
<input type="password" class="form-control" placeholder="Password"
|
||||||
[(value)]="loginCredential.password" ngControl="password" #name="ngForm" required>
|
[(ngModel)]="loginCredential.password" ngControl="password" #name="ngForm" required>
|
||||||
<br/>
|
<br/>
|
||||||
<button class="btn btn-lg btn-primary btn-block" [disabled]="!LoginForm.form.valid" (click)="onLogin()">Sign in</button>
|
<button class="btn btn-lg btn-primary btn-block" [disabled]="!LoginForm.form.valid" (click)="onLogin()">Sign in</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -62,6 +62,9 @@ export class AuthenticationService{
|
|||||||
return (this._user && this._user != null) ? true : false;
|
return (this._user && this._user != null) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getUser(){
|
||||||
|
return this._user;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,9 @@ DatabaseManager.getInstance((err)=>{
|
|||||||
DatabaseManager.getInstance().disconnect();
|
DatabaseManager.getInstance().disconnect();
|
||||||
process.exit()
|
process.exit()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
userManager.createUser(new User(0,"admin","admin@admin.hu","admin",UserRoles.Developer),(err)=>{
|
||||||
|
DatabaseManager.getInstance().disconnect();
|
||||||
|
process.exit()
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user