* initial commit

This commit is contained in:
Danyi Dávid
2018-11-11 12:00:45 +01:00
commit 3a86fe09ab
174 changed files with 17197 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import { TestBed, inject } from '@angular/core/testing';
import { ProfileResolverService } from './profile-resolver.service';
describe('ProfileResolverService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [ProfileResolverService]
});
});
it('should be created', inject([ProfileResolverService], (service: ProfileResolverService) => {
expect(service).toBeTruthy();
}));
});

View File

@@ -0,0 +1,26 @@
import { Injectable } from '@angular/core';
import { HttpClient } from "@angular/common/http";
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from "@angular/router";
import { Observable } from "rxjs/Observable";
import { environment } from "../../environments/environment";
import { User } from "./shared/user";
import { AuthService } from "../auth/auth.service";
@Injectable()
export class ProfileResolverService implements Resolve<User> {
private apiEndpoint = environment.apiUrl + '/api/user';
constructor(private httpClient: HttpClient,
private authService: AuthService) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<User> {
return this.getProfile().toPromise().then(result => result ? result : false);
}
public getProfile(): Observable<User> {
let token = this.authService.tokenData;
return this.httpClient.get<User>(this.apiEndpoint + '/' + token.uid);
}
}

View File

@@ -0,0 +1,58 @@
<div class="ui main container">
<h1 class="ui dividing header">Felhasználó</h1>
<div class="ui raised segment">
<div class="ui dimmer" [class.active]="submitInProgress">
<div class="ui indeterminate text loader">Mentés</div>
</div>
<div class="ui negative message" *ngIf="error">
<div class="header">
Hiba
</div>
<p>A régi jelszó nem megfelelő.</p>
</div>
<form *ngIf="user.canChangePassword" class="ui form" (ngSubmit)="changePassword()" [class.error]="passwordFormError">
<h4 class="ui dividing header">Jelszó változtatás</h4>
<div class="four fields">
<div class="field">
<label>Jelenlegi jelszó</label>
<input type="password" placeholder="" name="password_old" [(ngModel)]="oldPassword">
</div>
<div class="field">
<label>Új jelszó</label>
<input type="password" placeholder="" name="password_new" [(ngModel)]="newPassword">
</div>
<div class="field">
<label>Új jelszó megerősítése</label>
<input type="password" placeholder="" name="password_confirm" [(ngModel)]="cnfPassword">
</div>
<div class="field">
<label>&nbsp;</label>
<button class="ui button" [class.positive]="canChangePassword" [class.disabled]="!canChangePassword" type="submit">Jelszó módosítása</button>
</div>
</div>
<div class="ui error message">
<p>A két jelszó nem egyezik.</p>
</div>
</form>
<form class="ui form" (ngSubmit)="changeSettings()">
<h4 class="ui dividing header">Beállítások</h4>
<div class="grouped fields">
<label>Kér rendszer értesít email-ben?</label>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" id="wantsEmailTrue" name="wantsEmail" [(ngModel)]="user.wantsEmail" [value]="true">
<label for="wantsEmailTrue">Igen</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" id="wantsEmailFalse" name="wantsEmail" [(ngModel)]="user.wantsEmail" [value]="false">
<label for="wantsEmailFalse">Nem</label>
</div>
</div>
</div>
<button class="ui button" [class.positive]="!submitInProgress" [class.disabled]="submitInProgress">Beállítások mentése</button>
</form>
</div>
</div>

View File

@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SettingsComponent } from './settings.component';
describe('SettingsComponent', () => {
let component: SettingsComponent;
let fixture: ComponentFixture<SettingsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SettingsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SettingsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,72 @@
import { Component, OnInit } from '@angular/core';
import { UserService } from "../user.service";
import { ActivatedRoute, Router } from "@angular/router";
import { Title } from "@angular/platform-browser";
import { User } from "../shared/user";
@Component({
selector: 'app-settings',
templateUrl: './settings.component.html',
styleUrls: ['./settings.component.css']
})
export class SettingsComponent implements OnInit {
public user: User;
public error: boolean = false;
public submitInProgress: boolean = false;
public oldPassword: string = "";
public newPassword: string = "";
public cnfPassword: string = "";
constructor(private userService: UserService,
private router: Router,
private route: ActivatedRoute,
private titleService: Title) {
}
ngOnInit() {
this.titleService.setTitle("Webnapló : Felhasználói beállítások");
this.route.data.subscribe((data: { profile: User }) => this.user = data.profile);
}
public changePassword() {
this.submitInProgress=true;
if (this.user.canChangePassword) {
this.userService.changeOwnPassword(this.oldPassword, this.newPassword)
.finally(()=>this.submitInProgress=false)
.subscribe(
ok => {
if (ok) {
this.router.navigate(['/']);
} else {
this.error = true;
}
},
err => {
console.log(err);
this.error = true;
}
);
}
}
public changeSettings() {
this.submitInProgress=true;
this.userService.changeSettings({
wantsEmail: this.user.wantsEmail
}).finally(()=>this.submitInProgress=false)
.subscribe(okResult => this.router.navigate(['/']));
}
get passwordFormError(): boolean {
return [this.newPassword, this.cnfPassword].some(field => field.trim().length > 0)
&& this.newPassword != this.cnfPassword;
}
get canChangePassword(): boolean {
return [this.oldPassword, this.newPassword, this.cnfPassword].every(field => field.trim().length > 0)
&& this.newPassword == this.cnfPassword
&& !this.submitInProgress;
}
}

View File

@@ -0,0 +1,8 @@
export class User {
public id: number;
public name: string;
public email: string;
public wantsEmail: boolean;
public roles: Array<string>;
public canChangePassword: boolean;
}

View File

@@ -0,0 +1,22 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SettingsComponent } from "./settings/settings.component";
import { ProfileResolverService } from "./profile-resolver.service";
const routes: Routes = [
{
path: 'beallitasok',
component: SettingsComponent,
resolve: {
profile: ProfileResolverService,
},
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class UserRoutingModule {
}

View File

@@ -0,0 +1,23 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from "@angular/forms";
import { UserRoutingModule } from "./user-routing.module";
import { UserService } from './user.service';
import { ProfileResolverService } from './profile-resolver.service';
import { SettingsComponent } from './settings/settings.component';
@NgModule({
imports: [
CommonModule,
FormsModule,
UserRoutingModule
],
declarations: [SettingsComponent],
providers: [
UserService,
ProfileResolverService
]
})
export class UserModule {
}

View File

@@ -0,0 +1,15 @@
import { TestBed, inject } from '@angular/core/testing';
import { UserService } from './user.service';
describe('UserService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [UserService]
});
});
it('should be created', inject([UserService], (service: UserService) => {
expect(service).toBeTruthy();
}));
});

View File

@@ -0,0 +1,38 @@
import { Injectable } from '@angular/core';
import { HttpClient } from "@angular/common/http";
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from "@angular/router";
import { Observable } from "rxjs/Observable";
import { environment } from "../../environments/environment";
import { User } from "./shared/user";
import { AuthService } from "../auth/auth.service";
@Injectable()
export class UserService implements Resolve<Array<User>> {
private apiEndpoint = environment.apiUrl + '/api/user';
private apiEndpointPassword = environment.apiUrl + '/api/user/password';
constructor(private httpClient: HttpClient,
private authService: AuthService) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<Array<User>> {
return this.getUsers().toPromise().then(result => result ? result : false);
}
public getUsers(): Observable<Array<User>> {
return this.httpClient.get<Array<User>>(this.apiEndpoint);
}
public changeOwnPassword(oldPass: string, newPass:string): Observable<User> {
return this.httpClient.post<User>(this.apiEndpointPassword,{
'old': oldPass,
'new': newPass,
});
}
public changeSettings(settings): Observable<User> {
let token = this.authService.tokenData;
return this.httpClient.put<User>(this.apiEndpoint + '/' + token.uid, settings);
}
}