Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sfcode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ayush
sfcode
Commits
19d6efad
Commit
19d6efad
authored
Dec 10, 2020
by
Adarsh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comments
parent
9157fc0b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
0 deletions
+54
-0
src/app/api.service.ts
src/app/api.service.ts
+29
-0
src/app/app-routing.module.ts
src/app/app-routing.module.ts
+5
-0
src/app/app.component.ts
src/app/app.component.ts
+4
-0
src/app/app.module.ts
src/app/app.module.ts
+4
-0
src/app/auth.guard.ts
src/app/auth.guard.ts
+12
-0
No files found.
src/app/api.service.ts
View file @
19d6efad
/*! \file
This service file is used to register a user and login purposes, also it sets tokens for each user and they can be retrieved also
through this service. Contains functions to set,get and delete user tokens and also to check login status of a user.
*/
import
{
EventEmitter
,
Injectable
,
Output
}
from
'
@angular/core
'
;
import
{
map
}
from
'
rxjs/operators
'
;
import
{
HttpClient
}
from
'
@angular/common/http
'
;
...
...
@@ -16,6 +21,10 @@ export class ApiService {
constructor
(
private
httpClient
:
HttpClient
)
{
}
/*
This function is used to log in the user by posting username and password as it's parameters to the backend php scripts.
*/
public
userLogin
(
username
:
string
,
password
:
string
):
Observable
<
any
>
{
return
this
.
httpClient
.
post
<
any
>
(
this
.
baseUrl
+
'
/login.php
'
,
{
username
,
password
})
.
pipe
(
map
(
user
=>
{
...
...
@@ -28,6 +37,10 @@ export class ApiService {
}));
}
/*
This function is used to register the user by posting name, email, username and password as it's parameters to the backend php scripts.
*/
public
userReg
(
name
,
email
,
pwd
,
username
):
Observable
<
any
>
{
return
this
.
httpClient
.
post
<
any
>
(
this
.
baseUrl
+
'
/register.php
'
,
{
name
,
email
,
pwd
,
username
})
.
pipe
(
map
(
user
=>
{
...
...
@@ -35,18 +48,34 @@ export class ApiService {
}));
}
/*
This function is used to set token for the user to the local storage.
*/
setToken
(
token
:
string
):
void
{
localStorage
.
setItem
(
'
sfcode_user_token_2n1289bpxd
'
,
token
);
}
/*
This function is used to get token for the user from the local storage.
*/
getToken
():
string
{
return
localStorage
.
getItem
(
'
sfcode_user_token_2n1289bpxd
'
);
}
/*
This function is used to delete token from the local storage.
*/
deleteToken
():
void
{
localStorage
.
removeItem
(
'
sfcode_user_token_2n1289bpxd
'
);
}
/*
This function is used to check the login state of the user by the availability of token in local storage.
*/
isLoggedIn
():
boolean
{
const
userToken
=
this
.
getToken
();
return
userToken
!=
null
;
...
...
src/app/app-routing.module.ts
View file @
19d6efad
/*! \file
This file serves as the routing node of the entire project.
Containing Routes parameters for all possible routes available and wildcard routes redirect to home.
*/
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
RouterModule
,
Routes
}
from
'
@angular/router
'
;
import
{
HomeComponent
}
from
'
./home/home.component
'
;
...
...
src/app/app.component.ts
View file @
19d6efad
/*! \file
Default App Component File.
*/
import
{
Component
}
from
'
@angular/core
'
;
@
Component
({
...
...
src/app/app.module.ts
View file @
19d6efad
/*! \file
Default app module file of Angular containing imports, declarations and providers.
*/
import
{
BrowserModule
}
from
'
@angular/platform-browser
'
;
import
{
CUSTOM_ELEMENTS_SCHEMA
,
NgModule
}
from
'
@angular/core
'
;
...
...
src/app/auth.guard.ts
View file @
19d6efad
/*! \file
This file serves as an authenticator for each user which allows only users to access internal components like home,
files, arena, ide, etc. It is used in routing module for employing such restrictions.
*/
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
ActivatedRouteSnapshot
,
CanActivate
,
Router
,
RouterStateSnapshot
}
from
'
@angular/router
'
;
import
{
ApiService
}
from
'
./api.service
'
;
...
...
@@ -10,6 +15,9 @@ export class AuthGuard implements CanActivate {
constructor
(
private
dataService
:
ApiService
,
private
router
:
Router
)
{
}
/*
This function checks the state of router and calls the boolean function isLogin() to check whether a user is logged in or not.
*/
canActivate
(
route
:
ActivatedRouteSnapshot
,
state
:
RouterStateSnapshot
...
...
@@ -18,6 +26,10 @@ export class AuthGuard implements CanActivate {
return
this
.
isLogin
(
routeUrl
);
}
/*
This function calls Api Service to check the login status of the user and redirects the user to appropriate routes according to status.
*/
isLogin
(
routeUrl
:
string
):
boolean
{
if
(
this
.
dataService
.
isLoggedIn
())
{
return
true
;
...
...
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