Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pw/pw-jwt-oauth/client/src/app/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ <h1>{{message}}</h1>
<td>{{currentNew.author}}</td>
<td>{{currentNew.category}}</td>
<td>{{currentNew.content}}</td>
<td><button class="btn" (click)="addLike(currentNew)"><img src="assets/styles/ktheme/img/like.png" /> {{currentNew.likes}}</button></td>
<td><button class="btn" (click)="deleteNews(currentNew)"><img src="assets/styles/ktheme/img/delete.png"/></button></td>
<td><button class="btn" *ngIf="isAdmin() || isUser()" (click)="addLike(currentNew)"><img src="assets/styles/ktheme/img/like.png" /> {{currentNew.likes}}</button></td> <!--uniquement authentifié-->
<td><button class="btn" *ngIF="isAdmin()" (click)="deleteNews(currentNew)"><img src="assets/styles/ktheme/img/delete.png"/></button></td> <!--uniquement admin-->
</tr>
<tr class="gradeA">
<tr *ngIF="isUser()" class="gradeA">
<td><input type="text" [(ngModel)]="nextNews.author" placeholder="author"/></td>
<td><input type="text" [(ngModel)]="nextNews.category" placeholder="category"/></td>
<td><input type="text" [(ngModel)]="nextNews.content" placeholder="content"/></td>
<td></td>
<td><button class="btn" (click)="addNews()"><img src="assets/styles/ktheme/img/add.png"/></button></td>
<td><button class="btn" (click)="addNews()"><img src="assets/styles/ktheme/img/add.png"/></button></td> <!--uniquement utilisateur-->
</tr>
</tbody>
</table>
Expand Down
11 changes: 10 additions & 1 deletion pw/pw-jwt-oauth/client/src/app/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Observable } from 'rxjs';

import { NewsService } from '../services/newsService';
import { News } from '../beans/news';
import { Principal } from '../services/auth/principal.service';

@Component({
selector: 'home',
Expand All @@ -15,7 +16,15 @@ export class Home implements OnInit {
newsOfTheDay: News = {};
nextNews: News = {};

constructor(private newsService: NewsService) {}
constructor(
private newsService: NewsService,
public principal: Principal
) {}


isAdmin(){ return this.principal.isAdmin();}
isUser(){ return this.principal.isUser();}


ngOnInit() {
this.updateNews();
Expand Down
14 changes: 14 additions & 0 deletions pw/pw-jwt-oauth/client/src/app/services/auth/principal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ export class Principal {
this.authenticationState.next(this._identity);
}

isAdmin(){
if (this._identity.include == "Admin"){
return(true)
}
return(false)
}

isUser(){
if (this._identity == "User"){
return(true)
}
return(false)
}

identity(force?: boolean): Promise<any> {
if (force === true) {
this._identity = undefined;
Expand Down