Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
allo-app
Overview
Overview
Details
Activity
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
Nabil Sadki
allo-app
Commits
ab4d459e
Commit
ab4d459e
authored
Sep 17, 2019
by
Nabil Sadki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auth
parent
062026c5
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
132 additions
and
4 deletions
+132
-4
app-routing.module.ts
src/app/app-routing.module.ts
+1
-1
app.component.ts
src/app/app.component.ts
+10
-1
constants.ts
src/app/constants.ts
+2
-0
login.page.ts
src/app/pages/compte/login/login.page.ts
+4
-1
allo-service.ts
src/app/services/allo-service.ts
+1
-1
auth.service.spec.ts
src/app/services/auth.service.spec.ts
+12
-0
auth.service.ts
src/app/services/auth.service.ts
+102
-0
No files found.
src/app/app-routing.module.ts
View file @
ab4d459e
...
@@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
...
@@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
import
{
PreloadAllModules
,
RouterModule
,
Routes
}
from
'@angular/router'
;
import
{
PreloadAllModules
,
RouterModule
,
Routes
}
from
'@angular/router'
;
const
routes
:
Routes
=
[
const
routes
:
Routes
=
[
{
path
:
''
,
redirectTo
:
'
mainslider
'
,
pathMatch
:
'full'
},
{
path
:
''
,
redirectTo
:
'
start
'
,
pathMatch
:
'full'
},
{
path
:
'start'
,
loadChildren
:
'./pages/start/start.module#StartPageModule'
},
{
path
:
'start'
,
loadChildren
:
'./pages/start/start.module#StartPageModule'
},
{
path
:
'login'
,
loadChildren
:
'./pages/compte/login/login.module#LoginPageModule'
},
{
path
:
'login'
,
loadChildren
:
'./pages/compte/login/login.module#LoginPageModule'
},
{
path
:
'mainslider'
,
loadChildren
:
'./pages/mainslider/mainslider.module#MainsliderPageModule'
},
{
path
:
'mainslider'
,
loadChildren
:
'./pages/mainslider/mainslider.module#MainsliderPageModule'
},
...
...
src/app/app.component.ts
View file @
ab4d459e
...
@@ -8,6 +8,7 @@ import { StatusBar } from '@ionic-native/status-bar/ngx';
...
@@ -8,6 +8,7 @@ import { StatusBar } from '@ionic-native/status-bar/ngx';
import
{
LocalNotifications
}
from
'@ionic-native/local-notifications/ngx'
;
import
{
LocalNotifications
}
from
'@ionic-native/local-notifications/ngx'
;
import
{
TripService
}
from
'./services/trip-service'
;
import
{
TripService
}
from
'./services/trip-service'
;
import
{
AuthService
}
from
'./services/auth.service'
;
// import { LocationService } from './services/location-service';
// import { LocationService } from './services/location-service';
@
Component
({
@
Component
({
...
@@ -24,7 +25,8 @@ export class AppComponent {
...
@@ -24,7 +25,8 @@ export class AppComponent {
private
splashScreen
:
SplashScreen
,
private
splashScreen
:
SplashScreen
,
private
statusBar
:
StatusBar
,
private
statusBar
:
StatusBar
,
private
router
:
Router
,
private
router
:
Router
,
private
_STOR
:
Storage
private
_STOR
:
Storage
,
private
_AUTH
:
AuthService
// private _LOCAT: LocationService
// private _LOCAT: LocationService
)
{
)
{
this
.
initializeApp
();
this
.
initializeApp
();
...
@@ -42,6 +44,13 @@ export class AppComponent {
...
@@ -42,6 +44,13 @@ export class AppComponent {
// Set locator
// Set locator
// this.setLocator();
// this.setLocator();
this
.
_STOR
.
get
(
'wpUser'
).
then
((
wpUser
)
=>
{
if
(
wpUser
)
{
this
.
_AUTH
.
validateAuthToken
(
wpUser
.
token
);
}
else
{
this
.
router
.
navigateByUrl
(
'/login'
,
{
replaceUrl
:
true
});
}
});
// this._STOR.get('PARAM_mainslider').then((prmMainslider) => {
// this._STOR.get('PARAM_mainslider').then((prmMainslider) => {
// if (prmMainslider) {
// if (prmMainslider) {
// this._STOR.get('isLoggedIn').then((isLoggedIn) => {
// this._STOR.get('isLoggedIn').then((isLoggedIn) => {
...
...
src/app/constants.ts
0 → 100644
View file @
ab4d459e
export
const
WORDPRESS_URL
=
'http://www.allo-testeurs.com/'
;
export
const
WORDPRESS_REST_API_URL
=
WORDPRESS_URL
+
'wp-json/wp/v2/'
;
src/app/pages/compte/login/login.page.ts
View file @
ab4d459e
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
Validators
,
FormBuilder
,
FormGroup
,
FormControl
}
from
'@angular/forms'
;
import
{
Validators
,
FormBuilder
,
FormGroup
,
FormControl
}
from
'@angular/forms'
;
import
{
AlloService
}
from
'../../../services/allo-service'
;
import
{
AlloService
}
from
'../../../services/allo-service'
;
import
{
AuthService
}
from
'../../../services/auth.service'
;
import
{
Storage
}
from
'@ionic/storage'
;
import
{
Storage
}
from
'@ionic/storage'
;
import
{
Router
}
from
'@angular/router'
;
import
{
Router
}
from
'@angular/router'
;
import
{
GooglePlus
}
from
'@ionic-native/google-plus/ngx'
;
import
{
GooglePlus
}
from
'@ionic-native/google-plus/ngx'
;
...
@@ -32,7 +33,8 @@ export class LoginPage implements OnInit {
...
@@ -32,7 +33,8 @@ export class LoginPage implements OnInit {
public
storage
:
Storage
,
public
storage
:
Storage
,
public
router
:
Router
,
public
router
:
Router
,
private
googlePlus
:
GooglePlus
,
private
googlePlus
:
GooglePlus
,
public
_ALLO
:
AlloService
public
_ALLO
:
AlloService
,
public
_AUTH
:
AuthService
)
{
}
)
{
}
ngOnInit
()
{
ngOnInit
()
{
...
@@ -47,6 +49,7 @@ export class LoginPage implements OnInit {
...
@@ -47,6 +49,7 @@ export class LoginPage implements OnInit {
onSubmit
(
values
)
{
onSubmit
(
values
)
{
console
.
log
(
values
);
console
.
log
(
values
);
this
.
_AUTH
.
doLogin
(
values
.
email
,
values
.
password
);
}
}
async
doGoogleLogin
()
{
async
doGoogleLogin
()
{
...
...
src/app/services/allo-service.ts
View file @
ab4d459e
...
@@ -113,7 +113,7 @@ export class AlloService {
...
@@ -113,7 +113,7 @@ export class AlloService {
this
.
showPage
=
false
;
this
.
showPage
=
false
;
const
loading
=
await
this
.
loadingCtrl
.
create
({
const
loading
=
await
this
.
loadingCtrl
.
create
({
// spinner: null,
// spinner: null,
duration
:
200
0
,
duration
:
0
,
message
:
'Chargement...'
,
message
:
'Chargement...'
,
translucent
:
true
,
translucent
:
true
,
cssClass
:
'custom-class custom-loading'
cssClass
:
'custom-class custom-loading'
...
...
src/app/services/auth.service.spec.ts
0 → 100644
View file @
ab4d459e
import
{
TestBed
}
from
'@angular/core/testing'
;
import
{
AuthService
}
from
'./auth.service'
;
describe
(
'AuthService'
,
()
=>
{
beforeEach
(()
=>
TestBed
.
configureTestingModule
({}));
it
(
'should be created'
,
()
=>
{
const
service
:
AuthService
=
TestBed
.
get
(
AuthService
);
expect
(
service
).
toBeTruthy
();
});
});
src/app/services/auth.service.ts
0 → 100644
View file @
ab4d459e
import
{
Injectable
}
from
'@angular/core'
;
import
{
Platform
}
from
'@ionic/angular'
;
import
{
Storage
}
from
'@ionic/storage'
;
import
{
HttpClient
,
HttpHeaders
,
HttpErrorResponse
}
from
'@angular/common/http'
;
import
{
HTTP
}
from
'@ionic-native/http/ngx'
;
import
{
Router
}
from
'@angular/router'
;
import
{
AlloService
}
from
'./allo-service'
;
import
*
as
Config
from
'../constants'
;
@
Injectable
({
providedIn
:
'root'
})
export
class
AuthService
{
constructor
(
private
platform
:
Platform
,
public
storage
:
Storage
,
private
http
:
HttpClient
,
private
httpAdv
:
HTTP
,
private
router
:
Router
,
private
_ALLO
:
AlloService
)
{
}
getUser
()
{
return
this
.
storage
.
get
(
'wpUser'
);
}
setUser
(
user
)
{
return
this
.
storage
.
set
(
'wpUser'
,
user
);
}
logOut
()
{
return
this
.
storage
.
clear
();
}
doLogin
(
username
,
password
)
{
this
.
_ALLO
.
presentLoading
();
let
authData
=
{
username
:
username
,
password
:
password
};
if
(
this
.
platform
.
is
(
'cordova'
))
{
return
this
.
httpAdv
.
post
(
Config
.
WORDPRESS_URL
+
'wp-json/jwt-auth/v1/token'
,
authData
,
{}).
then
(
result
=>
{
this
.
setUser
(
result
);
this
.
_ALLO
.
dismissLoading
();
});
}
else
{
return
this
.
http
.
post
(
Config
.
WORDPRESS_URL
+
'wp-json/jwt-auth/v1/token'
,
authData
).
subscribe
(
result
=>
{
this
.
setUser
(
result
);
this
.
_ALLO
.
dismissLoading
();
});
}
}
doRegister
(
user_data
,
token
)
{
return
this
.
http
.
post
(
Config
.
WORDPRESS_REST_API_URL
+
'users?token='
+
token
,
user_data
);
}
validateAuthToken
(
token
)
{
this
.
_ALLO
.
presentLoading
();
if
(
this
.
platform
.
is
(
'cordova'
))
{
let
header
:
Headers
=
new
Headers
();
header
.
append
(
'Authorization'
,
'Bearer '
+
token
);
return
this
.
httpAdv
.
post
(
Config
.
WORDPRESS_URL
+
'wp-json/jwt-auth/v1/token/validate'
,
{},
{
headers
:
header
}
).
then
(
result
=>
{
this
.
processeAuthToken
(
result
);
}).
catch
(
error
=>
{
this
.
_ALLO
.
dismissLoading
();
console
.
log
(
error
);
});
}
else
{
let
header
:
HttpHeaders
=
new
HttpHeaders
();
header
.
append
(
'Authorization'
,
'Bearer '
+
token
);
return
this
.
http
.
post
(
Config
.
WORDPRESS_URL
+
'wp-json/jwt-auth/v1/token/validate'
,
{},
{
headers
:
header
}
).
subscribe
((
result
:
any
)
=>
{
this
.
processeAuthToken
(
result
);
},
error
=>
{
this
.
_ALLO
.
dismissLoading
();
console
.
log
(
error
);
});
}
}
processeAuthToken
(
result
:
any
)
{
this
.
_ALLO
.
dismissLoading
();
if
(
result
.
data
.
status
!==
200
)
{
if
(
this
.
router
.
url
===
'/login'
)
{
alert
(
'Votre session est expirée. Veuillez vous reconnecter'
);
}
}
else
{
this
.
router
.
navigateByUrl
(
'/mainslider'
,
{
replaceUrl
:
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