Skip to content
Snippets Groups Projects
Commit 0a55fd65 authored by Amalie Urdshals's avatar Amalie Urdshals
Browse files

Issue: Fixed Admin access, delete posts (#19)

parent a9bd365f
No related branches found
No related tags found
1 merge request!25Resolve "Opprettelse av administrator tilgang"
......@@ -28,7 +28,7 @@ export class AuthService {
// Get user data from JWT token
const token = localStorage.getItem('token');
const user_data = JSON.parse(atob(token.split(".")[1])).data[0];
return new User(user_data);
}
return new User();
......
......@@ -27,7 +27,7 @@ export class User implements Deserializable, Serializable {
console.log(this);
return this;
}
serialize(): Object {
return {
userId: this.userId,
......@@ -35,7 +35,7 @@ export class User implements Deserializable, Serializable {
email: this.email,
password: this.password,
create_time: this.create_time,
isAdmin: 0
isAdmin: this.isAdmin,
};
}
......
......@@ -7,7 +7,12 @@
<p>Publisert: {{post.getTimestamp}}</p>
<p>Eier: {{post.getOwner}}</p>
<p>a: {{isAdmin}}</p>
<p>b: {{userId}}</p>
<div *ngIf="userId == post.getOwner">
<app-button text="Rediger annonse" (click)="editPost()"></app-button>
</div>
<div *ngIf="userId == post.getOwner || isAdmin == 1">
<app-button text="Slett annonse" (click)="deletePost()"></app-button>
</div>
......@@ -3,6 +3,7 @@ import { Post } from 'src/app/models/post.model';
import { PostService } from '../post.service';
import { ActivatedRoute, Router } from '@angular/router'
import { AuthService } from 'src/app/authentication/auth.service';
import { User } from 'src/app/models/user.model';
@Component({
selector: 'app-post-details',
......@@ -12,13 +13,18 @@ import { AuthService } from 'src/app/authentication/auth.service';
export class PostDetailsComponent implements OnInit {
post: Post = new Post();
user: User = new User();
isAdmin: number = 0;
userId: number = 0;
constructor(private postService: PostService, private activatedRoute: ActivatedRoute, private router: Router, private authService: AuthService) { }
ngOnInit(): void {
// Gets ID from current user
this.userId = this.authService.getCurrentUser(false).getUserId;
// Gets current user information
this.user = this.authService.getCurrentUser(false);
// If user is logged in, assign userId and isAdmin
this.userId = this.user.getUserId; // 0
this.isAdmin = this.user.getIsAdmin; // 0
// Gets id parameter from URL
const id = this.activatedRoute.snapshot.params["id"];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment