Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flight-agency-app
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Heber Cordova
flight-agency-app
Commits
80a3e93f
Commit
80a3e93f
authored
Oct 24, 2023
by
Heber Cordova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: added auth config
parent
606adc58
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
765 additions
and
22 deletions
+765
-22
package.json
package.json
+1
-1
db.json
server/db.json
+6
-5
routes.json
server/routes.json
+5
-0
app-routing.module.ts
src/app/app-routing.module.ts
+5
-0
agent-authorize.interface.ts
src/app/security/models/agent-authorize.interface.ts
+209
-0
passenger-authorize.interface.ts
src/app/security/models/passenger-authorize.interface.ts
+217
-0
supervisor-authorize.interface.ts
src/app/security/models/supervisor-authorize.interface.ts
+205
-0
user-logged.interface.ts
src/app/security/models/user-logged.interface.ts
+8
-0
sign-in.component.ts
src/app/security/pages/sign-in/sign-in.component.ts
+68
-12
security.service.ts
src/app/security/services/security.service.ts
+30
-2
navigation-user.component.html
...components/navigation-user/navigation-user.component.html
+1
-1
navigation-user.component.ts
...d/components/navigation-user/navigation-user.component.ts
+10
-1
No files found.
package.json
View file @
80a3e93f
...
...
@@ -7,7 +7,7 @@
"build"
:
"ng build"
,
"watch"
:
"ng build --watch --configuration development"
,
"test"
:
"ng test"
,
"server"
:
"json-server-auth --port 3000 --watch ./server/db.json"
"server"
:
"json-server-auth --port 3000 --watch ./server/db.json
-r ./server/routes.json
"
},
"private"
:
true
,
"dependencies"
:
{
...
...
server/db.json
View file @
80a3e93f
...
...
@@ -30,19 +30,20 @@
],
"agents"
:
[
{
"name"
:
"
Heber
"
,
"lastname"
:
"
Cordova Jimenez
"
,
"name"
:
"
Julio
"
,
"lastname"
:
"
Garcia
"
,
"detail"
:
""
,
"email"
:
"hcordova@gmail.com"
,
"password"
:
"heber123"
,
"userId"
:
2
,
"id"
:
1
}
],
"passengers"
:
[
{
"name"
:
"
Heber
"
,
"name"
:
"
Roberto
"
,
"secondName"
:
""
,
"lastname"
:
"
Cordov
a"
,
"lastname"
:
"
Loayz
a"
,
"country"
:
"Peru"
,
"city"
:
"Lima"
,
"address"
:
"Calle 123"
,
...
...
@@ -362,4 +363,4 @@
"name"
:
"Primera Clase"
}
]
}
\ No newline at end of file
}
server/routes.json
0 → 100644
View file @
80a3e93f
{
"/passengers/*"
:
"/664/passengers/*"
,
"/supervisors/*"
:
"/664/supervisors/*"
,
"/agents/*"
:
"/664/agents/*"
}
src/app/app-routing.module.ts
View file @
80a3e93f
...
...
@@ -6,6 +6,11 @@ import { HomePageComponent as SupervisorHomePageComponent } from './supervisor/p
import
{
SignInComponent
}
from
'./security/pages/sign-in/sign-in.component'
;
const
routes
:
Routes
=
[
{
path
:
''
,
pathMatch
:
'full'
,
redirectTo
:
'sign-in'
,
},
{
path
:
'passengers'
,
component
:
PassengerHomePageComponent
,
...
...
src/app/security/models/agent-authorize.interface.ts
0 → 100644
View file @
80a3e93f
// To parse this data:
//
// import { Convert, AgentAuthorize } from "./file";
//
// const agentAuthorize = Convert.toAgentAuthorize(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export
interface
AgentAuthorize
{
name
:
string
;
lastname
:
string
;
detail
:
string
;
email
:
string
;
password
:
string
;
userId
:
number
;
id
:
number
;
user
:
User
;
}
export
interface
User
{
id
:
number
;
email
:
string
;
password
:
string
;
role
:
string
;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export
class
Convert
{
public
static
toAgentAuthorize
(
json
:
string
):
AgentAuthorize
{
return
cast
(
JSON
.
parse
(
json
),
r
(
"AgentAuthorize"
));
}
public
static
agentAuthorizeToJson
(
value
:
AgentAuthorize
):
string
{
return
JSON
.
stringify
(
uncast
(
value
,
r
(
"AgentAuthorize"
)),
null
,
2
);
}
}
function
invalidValue
(
typ
:
any
,
val
:
any
,
key
:
any
,
parent
:
any
=
''
):
never
{
const
prettyTyp
=
prettyTypeName
(
typ
);
const
parentText
=
parent
?
` on
${
parent
}
`
:
''
;
const
keyText
=
key
?
` for key "
${
key
}
"`
:
''
;
throw
Error
(
`Invalid value
${
keyText
}${
parentText
}
. Expected
${
prettyTyp
}
but got
${
JSON
.
stringify
(
val
)}
`
);
}
function
prettyTypeName
(
typ
:
any
):
string
{
if
(
Array
.
isArray
(
typ
))
{
if
(
typ
.
length
===
2
&&
typ
[
0
]
===
undefined
)
{
return
`an optional
${
prettyTypeName
(
typ
[
1
])}
`
;
}
else
{
return
`one of [
${
typ
.
map
(
a
=>
{
return
prettyTypeName
(
a
);
}).
join
(
", "
)}]
`;
}
} else if (typeof typ === "object" && typ.literal !== undefined) {
return typ.literal;
} else {
return typeof typ;
}
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key, parent);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) {}
}
return invalidValue(typs, val, key, parent);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue(l("Date"), val, key, parent);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue(l(ref || "object"), val, key, parent);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key, ref);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val, key, parent);
}
if (typ === false) return invalidValue(typ, val, key, parent);
let ref: any = undefined;
while (typeof typ === "object" && typ.ref !== undefined) {
ref = typ.ref;
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val, key, parent);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function l(typ: any) {
return { literal: typ };
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"AgentAuthorize": o([
{ json: "name", js: "name", typ: "" },
{ json: "lastname", js: "lastname", typ: "" },
{ json: "detail", js: "detail", typ: "" },
{ json: "email", js: "email", typ: "" },
{ json: "password", js: "password", typ: "" },
{ json: "userId", js: "userId", typ: 0 },
{ json: "id", js: "id", typ: 0 },
{ json: "user", js: "user", typ: r("User") },
], false),
"User": o([
{ json: "id", js: "id", typ: 0 },
{ json: "email", js: "email", typ: "" },
{ json: "password", js: "password", typ: "" },
{ json: "role", js: "role", typ: "" },
], false),
};
src/app/security/models/passenger-authorize.interface.ts
0 → 100644
View file @
80a3e93f
// To parse this data:
//
// import { Convert, PassengerAuthorize } from "./file";
//
// const passengerAuthorize = Convert.toPassengerAuthorize(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export
interface
PassengerAuthorize
{
name
:
string
;
secondName
:
string
;
lastname
:
string
;
country
:
string
;
city
:
string
;
address
:
string
;
phone
:
string
;
email
:
string
;
password
:
string
;
userId
:
number
;
id
:
number
;
user
:
User
;
}
export
interface
User
{
id
:
number
;
email
:
string
;
password
:
string
;
role
:
string
;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export
class
Convert
{
public
static
toPassengerAuthorize
(
json
:
string
):
PassengerAuthorize
{
return
cast
(
JSON
.
parse
(
json
),
r
(
"PassengerAuthorize"
));
}
public
static
passengerAuthorizeToJson
(
value
:
PassengerAuthorize
):
string
{
return
JSON
.
stringify
(
uncast
(
value
,
r
(
"PassengerAuthorize"
)),
null
,
2
);
}
}
function
invalidValue
(
typ
:
any
,
val
:
any
,
key
:
any
,
parent
:
any
=
''
):
never
{
const
prettyTyp
=
prettyTypeName
(
typ
);
const
parentText
=
parent
?
` on
${
parent
}
`
:
''
;
const
keyText
=
key
?
` for key "
${
key
}
"`
:
''
;
throw
Error
(
`Invalid value
${
keyText
}${
parentText
}
. Expected
${
prettyTyp
}
but got
${
JSON
.
stringify
(
val
)}
`
);
}
function
prettyTypeName
(
typ
:
any
):
string
{
if
(
Array
.
isArray
(
typ
))
{
if
(
typ
.
length
===
2
&&
typ
[
0
]
===
undefined
)
{
return
`an optional
${
prettyTypeName
(
typ
[
1
])}
`
;
}
else
{
return
`one of [
${
typ
.
map
(
a
=>
{
return
prettyTypeName
(
a
);
}).
join
(
", "
)}]
`;
}
} else if (typeof typ === "object" && typ.literal !== undefined) {
return typ.literal;
} else {
return typeof typ;
}
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key, parent);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) {}
}
return invalidValue(typs, val, key, parent);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue(l("Date"), val, key, parent);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue(l(ref || "object"), val, key, parent);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key, ref);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val, key, parent);
}
if (typ === false) return invalidValue(typ, val, key, parent);
let ref: any = undefined;
while (typeof typ === "object" && typ.ref !== undefined) {
ref = typ.ref;
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val, key, parent);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function l(typ: any) {
return { literal: typ };
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"PassengerAuthorize": o([
{ json: "name", js: "name", typ: "" },
{ json: "secondName", js: "secondName", typ: "" },
{ json: "lastname", js: "lastname", typ: "" },
{ json: "country", js: "country", typ: "" },
{ json: "city", js: "city", typ: "" },
{ json: "address", js: "address", typ: "" },
{ json: "phone", js: "phone", typ: "" },
{ json: "email", js: "email", typ: "" },
{ json: "password", js: "password", typ: "" },
{ json: "userId", js: "userId", typ: 0 },
{ json: "id", js: "id", typ: 0 },
{ json: "user", js: "user", typ: r("User") },
], false),
"User": o([
{ json: "id", js: "id", typ: 0 },
{ json: "email", js: "email", typ: "" },
{ json: "password", js: "password", typ: "" },
{ json: "role", js: "role", typ: "" },
], false),
};
src/app/security/models/supervisor-authorize.interface.ts
0 → 100644
View file @
80a3e93f
// To parse this data:
//
// import { Convert, Supervisor } from "./file";
//
// const supervisor = Convert.toSupervisor(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export
interface
SupervisorAuthorize
{
id
:
number
;
name
:
string
;
lastname
:
string
;
detail
:
string
;
userId
:
number
;
user
:
User
;
}
export
interface
User
{
id
:
number
;
email
:
string
;
password
:
string
;
role
:
string
;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export
class
Convert
{
public
static
toSupervisor
(
json
:
string
):
SupervisorAuthorize
{
return
cast
(
JSON
.
parse
(
json
),
r
(
"Supervisor"
));
}
public
static
supervisorToJson
(
value
:
SupervisorAuthorize
):
string
{
return
JSON
.
stringify
(
uncast
(
value
,
r
(
"Supervisor"
)),
null
,
2
);
}
}
function
invalidValue
(
typ
:
any
,
val
:
any
,
key
:
any
,
parent
:
any
=
''
):
never
{
const
prettyTyp
=
prettyTypeName
(
typ
);
const
parentText
=
parent
?
` on
${
parent
}
`
:
''
;
const
keyText
=
key
?
` for key "
${
key
}
"`
:
''
;
throw
Error
(
`Invalid value
${
keyText
}${
parentText
}
. Expected
${
prettyTyp
}
but got
${
JSON
.
stringify
(
val
)}
`
);
}
function
prettyTypeName
(
typ
:
any
):
string
{
if
(
Array
.
isArray
(
typ
))
{
if
(
typ
.
length
===
2
&&
typ
[
0
]
===
undefined
)
{
return
`an optional
${
prettyTypeName
(
typ
[
1
])}
`
;
}
else
{
return
`one of [
${
typ
.
map
(
a
=>
{
return
prettyTypeName
(
a
);
}).
join
(
", "
)}]
`;
}
} else if (typeof typ === "object" && typ.literal !== undefined) {
return typ.literal;
} else {
return typeof typ;
}
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key, parent);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) {}
}
return invalidValue(typs, val, key, parent);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue(l("Date"), val, key, parent);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue(l(ref || "object"), val, key, parent);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key, ref);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val, key, parent);
}
if (typ === false) return invalidValue(typ, val, key, parent);
let ref: any = undefined;
while (typeof typ === "object" && typ.ref !== undefined) {
ref = typ.ref;
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val, key, parent);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function l(typ: any) {
return { literal: typ };
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"Supervisor": o([
{ json: "id", js: "id", typ: 0 },
{ json: "name", js: "name", typ: "" },
{ json: "lastname", js: "lastname", typ: "" },
{ json: "detail", js: "detail", typ: "" },
{ json: "userId", js: "userId", typ: 0 },
{ json: "user", js: "user", typ: r("User") },
], false),
"User": o([
{ json: "id", js: "id", typ: 0 },
{ json: "email", js: "email", typ: "" },
{ json: "password", js: "password", typ: "" },
{ json: "role", js: "role", typ: "" },
], false),
};
src/app/security/models/user-logged.interface.ts
0 → 100644
View file @
80a3e93f
export
interface
UserLogged
{
id
:
number
;
name
:
string
;
lastname
:
string
;
email
:
string
;
token
:
string
;
role
:
string
;
}
src/app/security/pages/sign-in/sign-in.component.ts
View file @
80a3e93f
...
...
@@ -4,6 +4,10 @@ import { SecurityService } from '../../services/security.service';
import
{
SecurityCredentials
}
from
'../../models/security-credentials.interface'
;
import
{
SecurityResponse
}
from
'../../models/security-response.interface'
;
import
{
Router
}
from
'@angular/router'
;
import
{
UserLogged
}
from
'../../models/user-logged.interface'
;
import
{
SupervisorAuthorize
}
from
'../../models/supervisor-authorize.interface'
;
import
{
AgentAuthorize
}
from
'../../models/agent-authorize.interface'
;
import
{
PassengerAuthorize
}
from
'../../models/passenger-authorize.interface'
;
@
Component
({
selector
:
'app-sign-in'
,
...
...
@@ -58,19 +62,71 @@ export class SignInComponent {
const
credentials
:
SecurityCredentials
=
this
.
signInForm
.
value
;
this
.
securityService
.
login
(
credentials
)
.
subscribe
(
securityResponse
=>
{
switch
(
securityResponse
.
user
.
role
)
{
case
'supervisor'
:
this
.
router
.
navigate
([
'/supervisors'
]);
break
;
case
'agent'
:
this
.
router
.
navigate
([
'/agents'
]);
break
;
case
'passenger'
:
this
.
router
.
navigate
([
'/passengers'
]);
break
;
}
},
error
=>
this
.
showError
=
true
);
this
.
redirectAndSaveLocalStorage
(
securityResponse
);
});
}
else
this
.
showError
=
true
;
}
redirectAndSaveLocalStorage
(
securityResponse
:
SecurityResponse
):
void
{
switch
(
securityResponse
.
user
.
role
)
{
case
'supervisor'
:
this
.
securityService
.
getSupervisorByUserId
(
securityResponse
.
user
.
id
)
.
subscribe
(
supervisors
=>
{
this
.
supervisorSaveLocalStorage
(
supervisors
[
0
],
securityResponse
);
this
.
router
.
navigate
([
'/supervisors'
]);
});
break
;
case
'agent'
:
this
.
securityService
.
getAgentByUserId
(
securityResponse
.
user
.
id
)
.
subscribe
(
agents
=>
{
this
.
agentSaveLocalStorage
(
agents
[
0
],
securityResponse
);
this
.
router
.
navigate
([
'/agents'
]);
});
break
;
case
'passenger'
:
this
.
securityService
.
getPassengerByUserId
(
securityResponse
.
user
.
id
)
.
subscribe
(
passengers
=>
{
this
.
passengerSaveLocalStorage
(
passengers
[
0
],
securityResponse
);
this
.
router
.
navigate
([
'/passengers'
]);
});
break
;
}
}
supervisorSaveLocalStorage
(
supervisor
:
SupervisorAuthorize
,
securityResponse
:
SecurityResponse
):
void
{
const
userLogged
:
UserLogged
=
{
id
:
supervisor
.
id
,
name
:
supervisor
.
name
,
lastname
:
supervisor
.
lastname
,
email
:
supervisor
.
user
.
email
,
role
:
supervisor
.
user
.
role
,
token
:
securityResponse
.
accessToken
}
localStorage
.
setItem
(
'userLogged'
,
JSON
.
stringify
(
userLogged
));
}
agentSaveLocalStorage
(
agent
:
AgentAuthorize
,
securityResponse
:
SecurityResponse
):
void
{
const
userLogged
:
UserLogged
=
{
id
:
agent
.
id
,
name
:
agent
.
name
,
lastname
:
agent
.
lastname
,
email
:
agent
.
user
.
email
,
role
:
agent
.
user
.
role
,
token
:
securityResponse
.
accessToken
}
localStorage
.
setItem
(
'userLogged'
,
JSON
.
stringify
(
userLogged
));
}
passengerSaveLocalStorage
(
passenger
:
PassengerAuthorize
,
securityResponse
:
SecurityResponse
):
void
{
const
userLogged
:
UserLogged
=
{
id
:
passenger
.
id
,
name
:
passenger
.
name
,
lastname
:
passenger
.
lastname
,
email
:
passenger
.
user
.
email
,
role
:
passenger
.
user
.
role
,
token
:
securityResponse
.
accessToken
}
localStorage
.
setItem
(
'userLogged'
,
JSON
.
stringify
(
userLogged
));
}
}
src/app/security/services/security.service.ts
View file @
80a3e93f
...
...
@@ -3,15 +3,43 @@ import { Injectable } from '@angular/core';
import
{
HttpClient
}
from
'@angular/common/http'
;
import
{
SecurityCredentials
}
from
'../models/security-credentials.interface'
;
import
{
SecurityResponse
}
from
'../models/security-response.interface'
;
import
{
Observable
}
from
'rxjs'
;
import
{
Observable
,
of
,
tap
}
from
'rxjs'
;
import
{
SupervisorAuthorize
}
from
'../models/supervisor-authorize.interface'
;
import
{
Passenger
}
from
'src/app/agent/interfaces/passenger.interface'
;
import
{
PassengerAuthorize
}
from
'../models/passenger-authorize.interface'
;
import
{
AgentAuthorize
}
from
'../models/agent-authorize.interface'
;
import
{
UserLogged
}
from
'../models/user-logged.interface'
;
import
{
Router
}
from
'@angular/router'
;
@
Injectable
({
providedIn
:
'root'
})
export
class
SecurityService
{
constructor
(
private
http
:
HttpClient
)
{
}
constructor
(
private
http
:
HttpClient
,
private
router
:
Router
)
{
}
URL_BASE
:
string
=
'http://localhost:3000/'
;
get
currentUser
():
UserLogged
|
null
{
const
userLogged
:
UserLogged
|
null
=
JSON
.
parse
(
localStorage
.
getItem
(
'userLogged'
)
||
'null'
);
return
userLogged
;
}
login
(
securityCredentials
:
SecurityCredentials
):
Observable
<
SecurityResponse
>
{
return
this
.
http
.
post
<
SecurityResponse
>
(
this
.
URL_BASE
+
'signin'
,
securityCredentials
);
}
loguot
():
void
{
localStorage
.
removeItem
(
'userLogged'
);
this
.
router
.
navigate
([
'/sign-in'
]);
}
getSupervisorByUserId
(
userId
:
number
):
Observable
<
SupervisorAuthorize
[]
>
{
return
this
.
http
.
get
<
SupervisorAuthorize
[]
>
(
this
.
URL_BASE
+
'supervisors?userId='
+
userId
+
'&_expand=user'
);
}
getPassengerByUserId
(
userId
:
number
):
Observable
<
PassengerAuthorize
[]
>
{
return
this
.
http
.
get
<
PassengerAuthorize
[]
>
(
this
.
URL_BASE
+
'passengers?userId='
+
userId
+
'&_expand=user'
);
}
getAgentByUserId
(
userId
:
number
):
Observable
<
AgentAuthorize
[]
>
{
return
this
.
http
.
get
<
AgentAuthorize
[]
>
(
this
.
URL_BASE
+
'agents?userId='
+
userId
+
'&_expand=user'
);
}
}
src/app/shared/components/navigation-user/navigation-user.component.html
View file @
80a3e93f
...
...
@@ -11,7 +11,7 @@
</div>
<div
class=
"d-flex align-items-center"
>
<div
class=
"user"
>
<span>
hcordova
</span>
<span>
{{ username }}
</span>
<i
class=
"bi bi-caret-down-fill"
></i>
</div>
<button
class=
"btn"
>
...
...
src/app/shared/components/navigation-user/navigation-user.component.ts
View file @
80a3e93f
import
{
Component
,
EventEmitter
,
Output
}
from
'@angular/core'
;
import
{
Router
}
from
'@angular/router'
;
import
{
SecurityService
}
from
'src/app/security/services/security.service'
;
@
Component
({
selector
:
'shared-navigation-user'
,
...
...
@@ -11,12 +12,20 @@ export class NavigationUserComponent {
@
Output
()
public
toggleSidebarEvent
:
EventEmitter
<
void
>
=
new
EventEmitter
<
void
>
();
constructor
(
private
router
:
Router
)
{
}
constructor
(
private
router
:
Router
,
private
securityService
:
SecurityService
)
{
}
toggleSidebar
():
void
{
this
.
toggleSidebarEvent
.
emit
();
}
get
username
():
any
{
const
userLogged
=
this
.
securityService
.
currentUser
;
if
(
userLogged
)
{
return
`
${
userLogged
.
name
.
toLowerCase
().
substring
(
0
,
1
)}${
userLogged
.
lastname
.
toLowerCase
()}
`
}
return
null
;
}
goToLogin
():
void
{
this
.
router
.
navigate
([
'/sign-in'
]);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment