* initial commit
This commit is contained in:
15
src/app/user/profile-resolver.service.spec.ts
Normal file
15
src/app/user/profile-resolver.service.spec.ts
Normal 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();
|
||||
}));
|
||||
});
|
||||
26
src/app/user/profile-resolver.service.ts
Normal file
26
src/app/user/profile-resolver.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
0
src/app/user/settings/settings.component.css
Normal file
0
src/app/user/settings/settings.component.css
Normal file
58
src/app/user/settings/settings.component.html
Normal file
58
src/app/user/settings/settings.component.html
Normal 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> </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>
|
||||
25
src/app/user/settings/settings.component.spec.ts
Normal file
25
src/app/user/settings/settings.component.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
72
src/app/user/settings/settings.component.ts
Normal file
72
src/app/user/settings/settings.component.ts
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
8
src/app/user/shared/user.ts
Normal file
8
src/app/user/shared/user.ts
Normal 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;
|
||||
}
|
||||
22
src/app/user/user-routing.module.ts
Normal file
22
src/app/user/user-routing.module.ts
Normal 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 {
|
||||
}
|
||||
23
src/app/user/user.module.ts
Normal file
23
src/app/user/user.module.ts
Normal 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 {
|
||||
}
|
||||
15
src/app/user/user.service.spec.ts
Normal file
15
src/app/user/user.service.spec.ts
Normal 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();
|
||||
}));
|
||||
});
|
||||
38
src/app/user/user.service.ts
Normal file
38
src/app/user/user.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user