Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bk22 #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
22 changes: 22 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,28 @@ const routes: Routes = [
path: 'dashboard',
component: DashboardComponent,
canActivate: [AuthGuard],
},
{
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
<app-header></app-header>
<p>You are logged into dashboard</p>
<router-outlet></router-outlet>
<!DOCTYPE html>
<html>

<head>
<title>Welcome Page</title>
</head>

<body>
<app-header></app-header>
<p>You are logged into the dashboard</p>
<h1>Welcome <span id="firstNamePlaceholder"></span></h1>
<router-outlet></router-outlet>

<script type="text/javascript">
function setFirstName() {
var firstName = "Name";
var firstNameElement = document.getElementById("firstNamePlaceholder");
firstNameElement.textContent = firstName;
}
document.addEventListener("DOMContentLoaded", setFirstName);
</script>
</body>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h2>Welcome to Address Book</h2>
</div>
<form class="login-form" [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<input placeholder="Enter the username" formControlName="username" />
<input placeholder="Enter the password" formControlName="password" />
<input placeholder="Enter the password" type="password" formControlName="password" />
<button type="submit" class="btn-login" [disabled]="!loginForm.valid">Login</button>
</form>
</div>
Expand Down
16 changes: 15 additions & 1 deletion front-end/user-app/src/app/pages/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,25 @@ export class LoginComponent {
password: formBuilder.control('', [Validators.required]),
});
}

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);

}
);
}
}


}
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="First name*" formControlName="firstName" required/>
<input placeholder="Last name" formControlName="lastName" />
<input placeholder="Email Id*" formControlName="emailId" />
<input placeholder="Password*" formControlName="password" />
<input placeholder="Confirm password*" formControlName="confirmPassword"/>
<input placeholder="Email Id*" formControlName="emailId" type="email" required/>
<input placeholder="Password*" formControlName="password" type="password" required/>
<input placeholder="Confirm password*" formControlName="confirmPassword" type="password" required/>
<button type="submit" class="btn-login" [disabled]="!loginForm.valid">SignUp</button>
</form>
</div>
Expand Down
2 changes: 2 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 @@ -40,6 +40,7 @@ export class AuthService {
}

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

logout() {
Expand Down Expand Up @@ -67,6 +68,7 @@ export class AuthService {
let decodedToken:any = jwt_decode(token);
console.log(decodedToken);
// Set the loged in user data.
this.loggedInUser['firstName']=decodedToken?.firstName;
this.loggedInUser['emailId'] = decodedToken?.userEmailId;
this.loggedInUser['id']= decodedToken.userId;
} else{
Expand Down
Binary file added tempCodeRunnerFile
Binary file not shown.
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