diff --git a/client/src/app/models/user.model.ts b/client/src/app/models/user.model.ts index dfff1abd10ff054840d0c091362539370328f9d9..162edef208a6da30e8ee85ad91d6dcca9f4c04c8 100644 --- a/client/src/app/models/user.model.ts +++ b/client/src/app/models/user.model.ts @@ -8,6 +8,7 @@ export class User implements Deserializable, Serializable { private password: string; private create_time: Date; private isAdmin: number; + private location: string; constructor(input: any = null) { if (input) { @@ -19,6 +20,7 @@ export class User implements Deserializable, Serializable { this.password = null; this.create_time = new Date(); this.isAdmin = 0; + this.location = null; } } @@ -27,7 +29,7 @@ export class User implements Deserializable, Serializable { console.log(this); return this; } - + serialize(): Object { return { userId: this.userId, @@ -36,6 +38,7 @@ export class User implements Deserializable, Serializable { password: this.password, create_time: this.create_time, isAdmin: this.isAdmin, + location: this.location }; } @@ -84,6 +87,14 @@ export class User implements Deserializable, Serializable { } set setIsAdmin(isAdmin: number) { - isAdmin = this.isAdmin; + this.isAdmin = isAdmin; + } + + get getLocation() { + return this.location; + } + + set setLocation(location: string){ + this.location = location; } } \ No newline at end of file diff --git a/client/src/app/posts/post-details/post-details.component.html b/client/src/app/posts/post-details/post-details.component.html index 2629f2e372adebe0496c0ddbe2417c87a5a3c444..b7379c17fd6d60616f1121ef91fbc5a20954876e 100644 --- a/client/src/app/posts/post-details/post-details.component.html +++ b/client/src/app/posts/post-details/post-details.component.html @@ -7,7 +7,7 @@ </div> <div class="ownerInfo"> - <p>Owner: {{owner.getUsername}}</p> + <u id="owner" (click)="navigateOwner()">{{owner.getUsername}}</u> <p>E-mail: {{owner.getEmail}}</p> </div> diff --git a/client/src/app/posts/post-details/post-details.component.scss b/client/src/app/posts/post-details/post-details.component.scss index 35223ab590dfa1bc8d7c52be7d6eddf7c312a549..5093bad90e342875a6951b675600f6768d5c9ae2 100644 --- a/client/src/app/posts/post-details/post-details.component.scss +++ b/client/src/app/posts/post-details/post-details.component.scss @@ -20,6 +20,12 @@ div.container{ box-shadow: inset 0px 4px 4px rgba(0, 0, 0, 0.5); padding: 20px; + u#owner{ + color: #222222; + cursor: pointer; + font-size: 20pt; + } + div.pinkBox{ background-color: #FFA1A1; padding: 15px; diff --git a/client/src/app/posts/post-details/post-details.component.ts b/client/src/app/posts/post-details/post-details.component.ts index bd2d6051038aa7e4bc9e347354d7597e5eac0a57..e5a8e59abd8c403090eb827f37f31e9a3c8524a6 100644 --- a/client/src/app/posts/post-details/post-details.component.ts +++ b/client/src/app/posts/post-details/post-details.component.ts @@ -20,12 +20,12 @@ export class PostDetailsComponent implements OnInit { userId: number = 0; constructor(private postService: PostService, private activatedRoute: ActivatedRoute, private router: Router, - private authService: AuthService, private userService: UserService) { } + private authService: AuthService, private userService: UserService) { } ngOnInit() { // 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 @@ -36,7 +36,7 @@ export class PostDetailsComponent implements OnInit { // Gets Post with id from database this.postService.getPost(id).then(post => { this.post = post; - + // Gets Post owner from database this.userService.getUser(this.post.getOwner).then(user => { this.owner = user; @@ -47,7 +47,14 @@ export class PostDetailsComponent implements OnInit { console.log(error); }); } - + + /** + * Navigates to owner's profile + */ + navigateOwner() { + this.router.navigateByUrl("/user/" + this.owner.getUserId); + } + /** * Moves to edit page */ diff --git a/client/src/app/users/user-guest-profile/user-guest-profile.component.html b/client/src/app/users/user-guest-profile/user-guest-profile.component.html index 162f714a4181182ef41b7ebe303b8d95d4cc20c4..c136b13152b8d24d5dba5312e283ca36c007b1e0 100644 --- a/client/src/app/users/user-guest-profile/user-guest-profile.component.html +++ b/client/src/app/users/user-guest-profile/user-guest-profile.component.html @@ -3,7 +3,7 @@ <div class="titleWrapper"> <div class="img"></div> <div class="info"> - <p class="name">{{user.getUsername}} Doe</p> + <p class="name">{{user.getUsername}}</p> <p class="email">{{user.getEmail}}</p> <p class="phone_number">+47 123 45 678</p> </div> @@ -18,7 +18,7 @@ <i class="material-icons">star_border</i> </div> <div class="location"> - Geografi: Trondheim, Oslo + Område: {{user.getLocation}} </div> <div class="description"> <pre> diff --git a/client/src/app/users/user-profile/user-profile.component.html b/client/src/app/users/user-profile/user-profile.component.html index 7a86d7efb778090b51069d84d9bfa4c27c8b450a..94d5820211f3ae43460a7a8f07ebaff11e38df9c 100644 --- a/client/src/app/users/user-profile/user-profile.component.html +++ b/client/src/app/users/user-profile/user-profile.component.html @@ -4,7 +4,7 @@ <div class="titleWrapper"> <div class="img"></div> <div class="info"> - <p class="name">{{user.getUsername}} Doe</p> + <p class="name">{{user.getUsername}}</p> <p class="email">{{user.getEmail}}</p> <p class="phone_number">+47 123 45 678</p> </div> @@ -19,7 +19,7 @@ <i class="material-icons">star_border</i> </div> <div class="location"> - Geografi: Trondheim, Oslo + Område: {{user.getLocation}} </div> <div class="description"> <pre> diff --git a/server/src/controllers/authController/index.ts b/server/src/controllers/authController/index.ts index cbc1157304576bc170b13b29590c0235da90f8aa..8f855f61f2e433b5a0e9de785c2800630c68808f 100644 --- a/server/src/controllers/authController/index.ts +++ b/server/src/controllers/authController/index.ts @@ -10,7 +10,7 @@ const router = express.Router(); // Post register user `/api/auth/register` router.route('/register').post(async (request: Request, response: Response) => { - const {username, email, password, isAdmin, create_time} = request.body; + const {username, email, password, isAdmin, location, create_time} = request.body; try { // Check valid request data parameters const user_data: IUser = { @@ -18,6 +18,7 @@ router.route('/register').post(async (request: Request, response: Response) => { "email": email, "password": password, "isAdmin": isAdmin || 0, + "location": location || null }; if (Object.values(user_data).filter(p => p == undefined).length > 0) return response.status(500).send("Error"); // Check for user duplicates @@ -28,7 +29,7 @@ router.route('/register').post(async (request: Request, response: Response) => { return response.status(403).send("There exists an user with the same username or emails given!"); } // If there is no duplicates, create new user - const input = (`INSERT INTO user(username, email, password, isAdmin) VALUES (?,?,?,?)`) + const input = (`INSERT INTO user(username, email, password, isAdmin, location) VALUES (?,?,?,?,?)`) return response.status(200).json( await query(input,Object.values(user_data)) ); @@ -41,7 +42,7 @@ router.route('/register').post(async (request: Request, response: Response) => { router.route('/login').post(async (request: Request, response: Response) => { const {username, password} = request.body; try { - const input = "SELECT userId, username, email, isAdmin, create_time FROM user WHERE username=? AND password=?;" + const input = "SELECT userId, username, email, isAdmin, create_time, location FROM user WHERE username=? AND password=?;" const user = await query(input,[username, password]); // Check if an user object is retrieved const userObj = Object.values(JSON.parse(JSON.stringify(user.data)))[0]; diff --git a/server/src/controllers/userController/index.ts b/server/src/controllers/userController/index.ts index d1d41e7159f568489a84ff17fae7751d0b1cf7c3..4586bc6bdf79213a5b914fc7330a70dbaad0d7ac 100644 --- a/server/src/controllers/userController/index.ts +++ b/server/src/controllers/userController/index.ts @@ -8,18 +8,19 @@ const router = express.Router(); /* ============================= CREATE ============================= */ // Create an user `/api/user/` router.route('/').post(async (request: Request, response: Response) => { - const {username, email, password, isAdmin, create_time} = request.body; // destructuring + const {username, email, password, isAdmin, location, create_time} = request.body; // destructuring try { const user: IUser = { "username": username, "email": email, "password": password, "isAdmin": isAdmin || 0, + "location": location || null }; if (Object.values(user).filter(p => p == undefined).length > 0) return response.status(500).send("Error"); - const input = (`INSERT INTO user(username, email, password, isAdmin) VALUES (?,?,?,?)`); + const input = (`INSERT INTO user(username, email, password, isAdmin, location) VALUES (?,?,?,?,?)`); return response.status(200).json( - await query(input,Object.values(user)) + await query(input, Object.values(user)) ); } catch (error) { return response.status(400).send("Bad Request"); @@ -40,7 +41,7 @@ router.route('/').get(async (_: Request, response: Response) => { router.route('/:userId').get(async (request: Request, response: Response) => { const userId = request.params.userId; try { - const input = `SELECT userId, username, email, create_time FROM user WHERE userId=?;` + const input = `SELECT userId, username, email, create_time, location FROM user WHERE userId=?;` response.status(200).json(await query(input,[userId])); } catch (error) { response.status(400).send("Bad Request"); diff --git a/server/src/models/user.ts b/server/src/models/user.ts index 80fd9651765a635aba14a6ca53bcf90a7392b4e8..041f4e521261456476596b4ade95202fe509454c 100644 --- a/server/src/models/user.ts +++ b/server/src/models/user.ts @@ -6,6 +6,7 @@ interface IUser{ password: string; create_time?: Date; isAdmin: number; + location: string; } export default IUser;