Angular-Full-Stack
Angular-Full-Stack copied to clipboard
Link cats with users
How to maintain session with this so that each user can maintain their own data
The session of the login is already mantained with the token in localstorage. Each user that login have its own token.
Yes sir, But the data of one user is visible to other. How to show the data which is related to that particular user alone
But the data of one user is visible to other
What do you mean? Tell me what you need to do in details.
If X login and Enter details and then Y login, Y able to see X's details and X able to see Y's details.
Are you talking about the cat data? Add user id to each cat and amend the queries to filter data unique to each user?
On 27 Dec 2017 12:17, "felixchristo" [email protected] wrote:
If X login and Enter details and then Y login, Y able to see X's details and Y able to see X's details.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DavideViolante/Angular-Full-Stack/issues/145#issuecomment-354105825, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm_CVH7uT-I-TK3Xj0QyDJ6OX7wcp4qks5tEjVpgaJpZM4RMk4G .
I think I need to edit base.js for that?
If you could do that and update it, It will be very useful to all and the project will look meaningful
I think this would be a good challenge to learn for you as this project is a starter to build on.Base.js would be a good start.
When personalising the cat data that is held in the database, you might want to consider whether you actually need a database? Local storage would be an option.
On Wed, Dec 27, 2017 at 1:09 PM, felixchristo [email protected] wrote:
If you could do that and update it, It will be very useful to all and the project will look meaningful
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/DavideViolante/Angular-Full-Stack/issues/145#issuecomment-354111695, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm_CQI7Is_WB0yW6BYo1gNfm08ZD-R3ks5tEkGXgaJpZM4RMk4G .
The user data is private, the cat page and data is visible to all users, including the guests. I though about the cats as the "products" that can be seen by everyone. Currently there is no association between users and cats, since this is just a starter project and is meant to be simple.
If you want to create a link between them, you should edit the user schema as follows:
cats: [{ type: Schema.Types.ObjectId, ref: 'Cat' }]
The important word here to note is ref
. This creates a reference between User schema and Cat schema. So each user in this way will have an array of cats, their cats.
You can find some tutorials online about this topic, search for "mongoose ref"
http://mongoosejs.com/docs/populate.html
I am just getting this "_id" : ObjectId("5a446ab43533970b8489e1ac"), "username" : "Chris", "email" : "[email protected]", "password" : "$2a$10$ogerY6OiCRKy9TjPYERaOugUJeqelBl.yToJ4ZBX3ac2MVZQpsKOu", "role" : "user", "cats" : [ ], "__v" : 0
If I do cats: [{ type: Schema.Types.ObjectId, ref: 'Cat' }] in user.js
It's not that simple, I just gave you an hint. Every time you do the add new cat you should update the cats array of the user that added that cat.
Still I couldn't do this :(
you should add createdBy in cat model , save userid on it then use ngif to filter cats list it's already worked for me : 1- in authService for me i call it current code : get current() { return this.currentUser; } 2- in cat component add current = this.authService.current._id; add in ngOninit() : this.addCatForm = this.formBuilder.group({ . . . createdBy: this.authService.current._id });
3- in cat html file use this condition : code : tbody *ngIf="!isEditing" tr *ngFor="let cat of cats" span *ngIf="current == cat.createdBy" td>{{cat.title}}</td td>{{cat.content}}</td td> #note : don't forget to import the services and add createdby in ur server side
logically sounds good buddy.. Let me try and get back to you
yeaahhh it's working but the thing has to be done from server side buddy not from client side, which is not safe..
I'd recommend posting somewhere like stackoverflow.com for questions such as this. There are plenty of helpful people on those question sites and maybe already an answer that can help you.
On 28 Feb 2018 03:01, "felixchristo" [email protected] wrote:
yeaahhh it's working but the thing has to be done from server side buddy not from client side, which is not safe..
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/DavideViolante/Angular-Full-Stack/issues/145#issuecomment-369105455, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm_CV3DyLGQhUIFyZ9fUQSIrzuHls0Bks5tZMF6gaJpZM4RMk4G .
I think you can use the save(user) function ! I wanted to do same thing as you and I did it like that :
1)Add array property cats to user.model ( as davideviolante said above you can also use populate method, which may be more appropriate) 2) In cats.component.html add form (ngSubmit)="save(user)" and input [(ngModel)]="user.cats" 3)In cats.component.ts : import user.modele and user.service 4) In cats.component.ts : add getUser() and save(user: User) 5)Add {{user.cats}} to cats.component.html
you can check my repo I did it with film.detail.component.ts (instead of your cats I used films)
yeaahhh it's working but the thing has to be done from server side buddy not from client side, which is not safe..
Can you provide me with the project after you modifided it?