Skip to content
Snippets Groups Projects
Commit 138d8c54 authored by Tormod Nygård's avatar Tormod Nygård
Browse files

Merge branch '18-se-en-bruker-sin-lokasjon' into 'master'

Resolve "Se en bruker sin lokasjon"

Closes #18

See merge request !30
parents 5cfac964 0676a191
Branches
No related tags found
1 merge request!30Resolve "Se en bruker sin lokasjon"
Pipeline #126025 passed
Showing
with 64 additions and 19 deletions
......@@ -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;
}
}
......@@ -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
......@@ -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>
......
......@@ -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;
......
......@@ -51,6 +51,13 @@ export class PostDetailsComponent implements OnInit {
});
}
/**
* Navigates to owner's profile
*/
navigateOwner() {
this.router.navigateByUrl("/user/" + this.owner.getUserId);
}
/**
* Moves to edit page
*/
......
......@@ -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>
......
......@@ -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>
......
......@@ -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>
......
......@@ -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
......
......@@ -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];
......
......@@ -8,16 +8,17 @@ 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))
);
......@@ -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");
......
......@@ -6,6 +6,7 @@ interface IUser{
password: string;
create_time?: Date;
isAdmin: number;
location: string;
}
export default IUser;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment