Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions front-end/user-app/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ const routes: Routes = [
path: 'dashboard',
component: DashboardComponent,
canActivate: [AuthGuard],
children: [
{
path: '',
component: UserListComponent,
},
{
path: 'about-us',
component: AboutUsComponent,
},
{
path: 'contact',
component: ContactComponent,
},
{
path: 'user-detail',
component: UserDetailComponent,
canActivate: [AuthGuard],
},
{
path: 'create-user',
component: CreateUserComponent,
canActivate: [AuthGuard],
},
],
}
];

Expand Down
8 changes: 7 additions & 1 deletion front-end/user-app/src/app/guards/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import { Router } from '@angular/router';
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router){}
canActivate(): boolean {
return true;
let isAuthenticated = this.authService.isAuthenticated();
if (isAuthenticated) {
return true;
} else {
this.authService.logout();
return false;
}
}
}
10 changes: 9 additions & 1 deletion front-end/user-app/src/app/interceptors/auth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ export class AuthInterceptor implements HttpInterceptor {
}

//copy paste the code here

if (this.authService.isAuthenticated()) {
request = request.clone({
setHeaders: {
Authorization: `Bearer ${this.authService.getAuthToken()}`
}
});
} else {
this.authService.logout();
}

return next.handle(request).pipe(
catchError((error) => {
Expand Down
4 changes: 2 additions & 2 deletions front-end/user-app/src/app/pages/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ <h2>Welcome to Address Book</h2>
<img src="../../../assets/unicourt-logo.png" alt="logo" height="54" />
</div>
<form class="login-form" [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<input placeholder="Enter the username" formControlName="username" />
<input placeholder="Enter the password" formControlName="password" />
<input type="email" placeholder="Enter the username" formControlName="username" />
<input type="password" placeholder="Enter the password" formControlName="password" />
<button type="submit" class="btn-login" [disabled]="!loginForm.valid">Login</button>
</form>
</div>
Expand Down
5 changes: 4 additions & 1 deletion front-end/user-app/src/app/pages/login/login.component.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,600;0,700;1,400&display=swap');

.login-container {
max-width: 1170px;
width: 100%;
margin: 0 auto;
height: 100vh;
display: flex;
flex-direction: column;
font-family: 'Poppins', sans-serif;
}

.login-card {
Expand Down Expand Up @@ -47,7 +50,7 @@
border: solid 1px black;
font-size: 14px;
padding: 5px;
}
}

.btn-login {
width: 100px;
Expand Down
31 changes: 25 additions & 6 deletions front-end/user-app/src/app/pages/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,36 @@ import { Router } from '@angular/router';
export class LoginComponent {
loginForm: FormGroup;

constructor(private readonly formBuilder: FormBuilder, private authService: AuthService, private router: Router) {
constructor(
private readonly formBuilder: FormBuilder,
private authService: AuthService,
private router: Router
) {
this.loginForm = this.formBuilder.group({
username: formBuilder.control('', [Validators.required,Validators.email]),
username: formBuilder.control('', [
Validators.required,
Validators.email,
]),
password: formBuilder.control('', [Validators.required]),
});
}

async onSubmit(){
if(this.loginForm.valid){

async onSubmit() {
if (this.loginForm.valid) {
await this.authService.login(this.loginForm.value).then(
(response: any) => {
if (response) {
localStorage.setItem('jwt', response.Authorization);
this.authService.setLogedInUser();
this.router.navigateByUrl('/dashboard');
} else {
alert('Invalid email id password');
}
},
(error) => {
console.log(error);
}
);
}
}

}
10 changes: 5 additions & 5 deletions front-end/user-app/src/app/pages/sign-up/sign-up.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ <h2>SignUp to Address Book</h2>
<img src="../../../assets/unicourt-logo.png" alt="logo" height="54" />
</div>
<form class="login-form" (ngSubmit)="onSubmit()" [formGroup]="loginForm" novalidate>
<input placeholder="First name*" formControlName="firstName" />
<input placeholder="Last name" formControlName="lastName" />
<input placeholder="Email Id*" formControlName="emailId" />
<input placeholder="Password*" formControlName="password" />
<input placeholder="Confirm password*" formControlName="confirmPassword"/>
<input type="text" placeholder="First name*" formControlName="firstName" />
<input type="text" placeholder="Last name" formControlName="lastName" />
<input type="email" placeholder="Email Id*" formControlName="emailId" />
<input type="password" placeholder="Password*" formControlName="password" />
<input type="password" placeholder="Confirm password*" formControlName="confirmPassword"/>
<button type="submit" class="btn-login" [disabled]="!loginForm.valid">SignUp</button>
</form>
</div>
Expand Down
3 changes: 3 additions & 0 deletions front-end/user-app/src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class AuthService {
let returnedData = this.http.post(this.baseUrl+"/auth/register",data).subscribe({
next(res:any){
if(res.success){
console.log(res);
return res;
}
},
Expand All @@ -40,7 +41,9 @@ export class AuthService {
}

async login(data: any){
return await this.http.post(this.baseUrl+'/auth/login',data).toPromise()
}


logout() {
// Delete the jwt-token stored in local-storage.
Expand Down
1 change: 1 addition & 0 deletions front-end/user-app/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>UserApp</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script rel="preconnect" src="https://kit.fontawesome.com/dff89ccdda.js" crossorigin="anonymous"></script>
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- CreateEnum
CREATE TYPE "Role" AS ENUM ('CLIENT', 'ADMIN', 'ROOT');

-- CreateTable
CREATE TABLE "user" (
"id" SERIAL NOT NULL,
"first_name" TEXT NOT NULL,
"email_id" TEXT NOT NULL,
"last_name" TEXT NOT NULL,
"password" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "user_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "contact" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"email_id" TEXT NOT NULL,
"street" TEXT NOT NULL,
"city" TEXT NOT NULL,
"zipcode" INTEGER NOT NULL,
"company_name" TEXT NOT NULL,
"phone_number" TEXT NOT NULL,
"userId" INTEGER NOT NULL,

CONSTRAINT "contact_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "user_email_id_key" ON "user"("email_id");

-- AddForeignKey
ALTER TABLE "contact" ADD CONSTRAINT "contact_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@

Object.defineProperty(exports, "__esModule", { value: true });

const {
Decimal,
objectEnumValues,
makeStrictEnum,
Public,
} = require('./runtime/index-browser')


const Prisma = {}

exports.Prisma = Prisma

/**
* Prisma Client JS version: 4.16.2
* Query Engine version: 4bc8b6e1b66cb932731fb1bdbbc550d1e010de81
*/
Prisma.prismaVersion = {
client: "4.16.2",
engine: "4bc8b6e1b66cb932731fb1bdbbc550d1e010de81"
}

Prisma.PrismaClientKnownRequestError = () => {
throw new Error(`PrismaClientKnownRequestError is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)};
Prisma.PrismaClientUnknownRequestError = () => {
throw new Error(`PrismaClientUnknownRequestError is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)}
Prisma.PrismaClientRustPanicError = () => {
throw new Error(`PrismaClientRustPanicError is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)}
Prisma.PrismaClientInitializationError = () => {
throw new Error(`PrismaClientInitializationError is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)}
Prisma.PrismaClientValidationError = () => {
throw new Error(`PrismaClientValidationError is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)}
Prisma.NotFoundError = () => {
throw new Error(`NotFoundError is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)}
Prisma.Decimal = Decimal

/**
* Re-export of sql-template-tag
*/
Prisma.sql = () => {
throw new Error(`sqltag is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)}
Prisma.empty = () => {
throw new Error(`empty is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)}
Prisma.join = () => {
throw new Error(`join is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)}
Prisma.raw = () => {
throw new Error(`raw is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)}
Prisma.validator = Public.validator

/**
* Extensions
*/
Prisma.getExtensionContext = () => {
throw new Error(`Extensions.getExtensionContext is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)}
Prisma.defineExtension = () => {
throw new Error(`Extensions.defineExtension is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)}

/**
* Shorthand utilities for JSON filtering
*/
Prisma.DbNull = objectEnumValues.instances.DbNull
Prisma.JsonNull = objectEnumValues.instances.JsonNull
Prisma.AnyNull = objectEnumValues.instances.AnyNull

Prisma.NullTypes = {
DbNull: objectEnumValues.classes.DbNull,
JsonNull: objectEnumValues.classes.JsonNull,
AnyNull: objectEnumValues.classes.AnyNull
}

/**
* Enums
*/

exports.Prisma.TransactionIsolationLevel = makeStrictEnum({
ReadUncommitted: 'ReadUncommitted',
ReadCommitted: 'ReadCommitted',
RepeatableRead: 'RepeatableRead',
Serializable: 'Serializable'
});

exports.Prisma.UserScalarFieldEnum = {
id: 'id',
firstName: 'firstName',
emailId: 'emailId',
lastName: 'lastName',
password: 'password',
createdAt: 'createdAt'
};

exports.Prisma.ContactScalarFieldEnum = {
id: 'id',
name: 'name',
emailId: 'emailId',
street: 'street',
city: 'city',
zipcode: 'zipcode',
companyName: 'companyName',
phoneNumber: 'phoneNumber',
userId: 'userId'
};

exports.Prisma.SortOrder = {
asc: 'asc',
desc: 'desc'
};

exports.Prisma.QueryMode = {
default: 'default',
insensitive: 'insensitive'
};


exports.Prisma.ModelName = {
User: 'User',
Contact: 'Contact'
};

/**
* Create the Client
*/
class PrismaClient {
constructor() {
throw new Error(
`PrismaClient is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
)
}
}
exports.PrismaClient = PrismaClient

Object.assign(exports, Prisma)
Loading