diff --git a/client/src/app/models/user.model.ts b/client/src/app/models/user.model.ts index dc474cdc0c364bc3b598858307d58fa7e8cbf8c7..773c10040aace297acab374762af69d22329b4b9 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; } } @@ -26,7 +28,7 @@ export class User implements Deserializable, Serializable { Object.assign(this, input); return this; } - + serialize(): Object { return { userId: this.userId, @@ -35,6 +37,7 @@ export class User implements Deserializable, Serializable { password: this.password, create_time: this.create_time, isAdmin: this.isAdmin, + location: this.location }; } @@ -83,6 +86,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 d1fa37802e71829a1ce8ebf7cfae7c2e6c8f674d..28d51fad78cb776d5d694f0fa20779b07b9a7abb 100644 --- a/client/src/app/posts/post-details/post-details.component.html +++ b/client/src/app/posts/post-details/post-details.component.html @@ -20,9 +20,7 @@ </div> <div class="ownerInfo"> - <a [href]="'/user/'+owner.getUserId"> - <p>Owner: {{owner.getUsername}}</p> - </a> + <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 f77a1b9f48cbf8ac5483b0a3a64437728185d440..ae4a555fee5eb6f3529533b53b043452c3d29692 100644 --- a/client/src/app/posts/post-details/post-details.component.scss +++ b/client/src/app/posts/post-details/post-details.component.scss @@ -47,6 +47,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 acd63818821a9a8e6bdaf28ddd789d5036c8efd9..337853ed20b0a7f8abc1873d75955ccf6a481c34 100644 --- a/client/src/app/posts/post-details/post-details.component.ts +++ b/client/src/app/posts/post-details/post-details.component.ts @@ -23,12 +23,12 @@ export class PostDetailsComponent implements OnInit { soldToUser: 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; this.isAdmin = this.user.getIsAdmin; @@ -50,7 +50,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 7a15fb1732f4e30af69f9e4a4271da5c7d289eda..82f48b038e5e275fe5fafda741a4aed188610f01 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 @@ -14,7 +14,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> @@ -29,7 +29,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 7af062cf35fd2bd6d8d938f8ddbbe5ada86d7eb1..842251d7940e76942f8b6094c501cf74effc4d64 100644 --- a/client/src/app/users/user-profile/user-profile.component.html +++ b/client/src/app/users/user-profile/user-profile.component.html @@ -30,7 +30,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> @@ -45,7 +45,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-registration-form/user-registration-form.component.html b/client/src/app/users/user-registration-form/user-registration-form.component.html index 48a94bd69b5321aba4ebf615374662c3f44303b3..06c00e23e10238a97fad560468ade1aad331b531 100644 --- a/client/src/app/users/user-registration-form/user-registration-form.component.html +++ b/client/src/app/users/user-registration-form/user-registration-form.component.html @@ -9,6 +9,20 @@ <app-input [(inputModel)]="username" label="Brukernavn" (blur)="checkForm()"></app-input> <app-input [(inputModel)]="email" label="Epost" (blur)="checkForm()"></app-input> <app-input [(inputModel)]="phone_number" label="Mobilnummer" (blur)="checkForm()"></app-input> + <app-select [(inputModel)]="location"> + <option selected>Velg fylke . . .</option> + <option>Agder</option> + <option>Innlandet</option> + <option>Møre og Romsdal</option> + <option>Nordland</option> + <option>Oslo</option> + <option>Rogaland</option> + <option>Troms og Finnmark</option> + <option>Trøndelag</option> + <option>Vestfold og Telemark</option> + <option>Vestland</option> + <option>Viken</option> + </app-select> <app-input [(inputModel)]="password" type="password" label="Passord" (blur)="checkForm()"></app-input> <app-input [(inputModel)]="confirm_password" type="password" label="Bekreft passord" (blur)="checkForm()"></app-input> <p class="status">{{statusMessage}}</p> diff --git a/client/src/app/users/user-registration-form/user-registration-form.component.ts b/client/src/app/users/user-registration-form/user-registration-form.component.ts index 0a8bcdec00d02148ae25cd426f096df42d5d2d8f..f25cac2c21b561a15add323483c7c311783adf0f 100644 --- a/client/src/app/users/user-registration-form/user-registration-form.component.ts +++ b/client/src/app/users/user-registration-form/user-registration-form.component.ts @@ -15,6 +15,7 @@ export class UserRegistrationFormComponent implements OnInit { username: string = ""; email: string = ""; phone_number: string = ""; + location: string = "Velg fylke . . ."; password: string = ""; confirm_password: string = ""; @@ -49,6 +50,10 @@ export class UserRegistrationFormComponent implements OnInit { this.setStatusMessage("Mobilnummer kan ikke være tom"); return false; } + else if (this.location == "Velg fylke . . .") { + this.setStatusMessage("Fylke må være valgt"); + return false; + } else if (this.password == "") { this.setStatusMessage("Passordet kan ikke være tom"); return false; @@ -76,6 +81,7 @@ export class UserRegistrationFormComponent implements OnInit { email: this.email, password: this.password, isAdmin: 0, + location: this.location }); // Adds user to database and redirects to the homepage afterwards 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;