Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jhipster 5如何在不获取登录模式的情况下访问实体?_Jhipster - Fatal编程技术网

jhipster 5如何在不获取登录模式的情况下访问实体?

jhipster 5如何在不获取登录模式的情况下访问实体?,jhipster,Jhipster,我有我的post实体,它是从SecurityConfig打开的,因此我可以不登录就访问它,但Jhipster继续使用登录模型(如果用户试图创建注释,我只想显示它)。它是否与post.route.ts文件中的canActivate:[UserRouteAccessService]有关 import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router';

我有我的post实体,它是从SecurityConfig打开的,因此我可以不登录就访问它,但Jhipster继续使用登录模型(如果用户试图创建注释,我只想显示它)。它是否与post.route.ts文件中的canActivate:[UserRouteAccessService]有关

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { JhiDataUtils } from 'ng-jhipster';
import { HttpErrorResponse, HttpHeaders, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import * as moment from 'moment';
import { DATE_TIME_FORMAT } from 'app/shared/constants/input.constants';
import { ITEMS_PER_PAGE } from 'app/shared';
import { JhiEventManager, JhiParseLinks, JhiAlertService } from 'ng-jhipster';
import { Subscription } from 'rxjs';
import { Principal } from 'app/core';

import { IComment } from 'app/shared/model/comment.model';
import { CommentService } from 'app/entities/comment';
import { IPost } from 'app/shared/model/post.model';
import { PostService } from 'app/entities/post';
import { IProfile } from 'app/shared/model/profile.model';
import { ProfileService } from 'app/entities/profile';

@Component({
    selector: 'jhi-post-detail',
    templateUrl: './post-detail.component.html'
})
export class PostDetailComponent implements OnInit {
    id: any;
    private _comment: IComment;
    isSaving: boolean;

    post: any;
    posts: IPost[];

    profile: IProfile;
    profiles: IProfile[];

    currentAccount: any;
    creationDate: string;

    comments: IComment[];
    error: any;
    success: any;
    eventSubscriber: Subscription;
    routeData: any;
    links: any;
    totalItems: any;
    queryCount: any;
    itemsPerPage: any;
    page: any = 1;
    predicate: any = 'id';
    previousPage: any = 0;
    reverse: any = 'asc';

    constructor(
        private dataUtils: JhiDataUtils,
        private parseLinks: JhiParseLinks,
        private jhiAlertService: JhiAlertService,
        private commentService: CommentService,
        private postService: PostService,
        private principal: Principal,
        private profileService: ProfileService,
        private activatedRoute: ActivatedRoute,
        private router: Router,
        private eventManager: JhiEventManager
    ) {
        this.itemsPerPage = ITEMS_PER_PAGE;
        this.routeData = this.activatedRoute.data.subscribe(data => {
            this.page = 0;
            this.previousPage = 0;
            this.reverse = false;
            this.predicate = 'id';
        });
    }

    ngOnInit() {
        console.log('CONSOLOG: M:ngOnInit & O: this.page : ', this.page);
        console.log('CONSOLOG: M:ngOnInit & O: this.predicate : ', this.predicate);
        console.log('CONSOLOG: M:ngOnInit & O: this.previousPage : ', this.previousPage);
        console.log('CONSOLOG: M:ngOnInit & O: this.reverse : ', this.reverse);
        this.isSaving = false;
        this.activatedRoute.data.subscribe(({ post }) => {
            this.post = post;
            console.log('CONSOLOG: M:ngOnInit & O: this.post : ', this.post);
        });
        this.loadAll();
        this.principal.identity().then(account => {
            this.currentAccount = account;
        });
        this.comment = new Object();
        this.comment.commentText = '';
        this.registerChangeInComments();
    }

    saveComment() {
        this.isSaving = true;
        this.comment.creationDate = moment(this.creationDate, DATE_TIME_FORMAT);
        if (this.comment.id !== undefined) {
            this.subscribeToSaveResponse(this.commentService.update(this.comment));
        } else {
            this.comment.postId = this.post.id;
            this.loggedProfile()
            .subscribe(
                    (res: HttpResponse<IProfile[]>) => {
                        this.profiles = res.body;
                        this.comment.profileId = this.profiles[0].id;
                        this.comment.isOffensive = false;
      this.subscribeToSaveResponse(this.commentService.create(this.comment));
                    },
                    (res: HttpErrorResponse) => this.onError(res.message)
            );
        }
    }

    private loggedProfile() {
        const query = {
            };
        if ( this.currentAccount.id  != null) {
            query['userId.equals'] = this.currentAccount.id;
        }
        return this.profileService
            .query(query);
    }

    private subscribeToSaveResponse(result: Observable<HttpResponse<IComment>>) {
        result.subscribe((res: HttpResponse<IComment>) => this.onSaveSuccess(), (res: HttpErrorResponse) => this.onSaveError());
    }

    private onSaveSuccess() {
        this.isSaving = false;
        this.reload();
    }

    private onSaveError() {
        this.isSaving = false;
    }

    private onError(errorMessage: string) {
        this.jhiAlertService.error(errorMessage, null, null);
    }

    trackPostById(index: number, item: IPost) {
        return item.id;
    }

    trackProfileById(index: number, item: IProfile) {
        return item.id;
    }

    get comment() {
        return this._comment;
    }

    set comment(comment: IComment) {
        this._comment = comment;
        this.creationDate = moment(comment.creationDate).format(DATE_TIME_FORMAT);
    }

    byteSize(field) {
        return this.dataUtils.byteSize(field);
    }

    openFile(contentType, field) {
        return this.dataUtils.openFile(contentType, field);
    }

    previousState() {
        window.history.back();
    }

    reload() {
        window.location.reload();
    }

    loadPage(page) {
        this.previousPage = page;
        this.page = page;
        this.loadAll();
    }

    loadAll() {
        const query = {
                page: this.page - 1,
                size: this.itemsPerPage,
                sort: this.sort()
            };
            query['postId.equals'] = this.post.id;
        this.commentService
            .query(query)
            .subscribe(
                (res: HttpResponse<IComment[]>) => {
                    console.log('CONSOLOG: M:loadAll & O: query : ', query);
                    this.paginateComments(res.body, res.headers);
                },
                (res: HttpErrorResponse) => this.onError(res.message)
            );
    }

    transition() {
        this.loadAll();
    }

    clear() {
        this.page = 0;
        this.router.navigate([
            '/comment',
            {
                page: this.page,
                sort: this.predicate + ',' + (this.reverse ? 'asc' : 'desc')
            }
        ]);
        this.loadAll();
    }

    trackId(index: number, item: IComment) {
        return item.id;
    }

    registerChangeInComments() {
        this.eventSubscriber = this.eventManager.subscribe('commentListModification', response => this.loadAll());
    }

    sort() {
        const result = [this.predicate + ',' + (this.reverse ? 'asc' : 'desc')];
        if (this.predicate !== 'id') {
            result.push('id');
        }
        return result;
    }

    private paginateComments(data: IComment[], headers: HttpHeaders) {
        this.links = this.parseLinks.parse(headers.get('link'));
        this.totalItems = parseInt(headers.get('X-Total-Count'), 10);
        this.queryCount = this.totalItems;
        this.comments = data;
    }
}

我已经玩过canActivate的大部分部分,但仍然不起作用。谢谢你的帮助

乔恩是对的。如果没有权威人士的支持和评论,它是有效的

{
    path: 'post/:id/view',
    component: PostDetailComponent,
    resolve: {
        post: PostResolve
    },
    data: {
        authorities: [],
        pageTitle: 'jhipsterpressApp.post.home.title'
    },
//        canActivate: [UserRouteAccessService]
},

你能添加你的安全配置码吗?在那里!感谢您查看我。您是否尝试注释post.route.ts文件中的UserRouteAccessService行?您在哪里允许post实体访问而不进行身份验证?
{
    path: 'post/:id/view',
    component: PostDetailComponent,
    resolve: {
        post: PostResolve
    },
    data: {
        authorities: [],
        pageTitle: 'jhipsterpressApp.post.home.title'
    },
//        canActivate: [UserRouteAccessService]
},