forked from xurror/web-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Shift services into their own folders.
* Add comments.
Fixes #288
- Loading branch information
1 parent
1526235
commit 90087bf
Showing
37 changed files
with
1,441 additions
and
1,247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Alert model. | ||
*/ | ||
export interface Alert { | ||
type: string; | ||
message: string; | ||
} |
File renamed without changes.
18 changes: 14 additions & 4 deletions
18
src/app/core/alert.service.ts → src/app/core/alert/alert.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,74 @@ | ||
/** Angular Imports */ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http'; | ||
|
||
/** rxjs Imports */ | ||
import { Observable } from 'rxjs'; | ||
|
||
/** Environment Configuration */ | ||
import { environment } from '../../../environments/environment'; | ||
|
||
/** Http request options headers. */ | ||
const httpOptions = { | ||
headers: { | ||
'Content-Type': 'application/json; charset=utf-8', | ||
'Fineract-Platform-TenantId': environment.fineractPlatformTenantId | ||
} | ||
}; | ||
|
||
/** Authorization header. */ | ||
const authorizationHeader = 'Authorization'; | ||
/** Two factor access token header. */ | ||
const twoFactorAccessTokenHeader = 'Fineract-Platform-TFA-Token'; | ||
|
||
/** | ||
* Http Request interceptor to set the request headers. | ||
*/ | ||
@Injectable() | ||
export class AuthenticationInterceptor implements HttpInterceptor { | ||
|
||
constructor() {} | ||
|
||
/** | ||
* Intercepts a Http request and sets the request headers. | ||
*/ | ||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | ||
request = request.clone({ setHeaders: httpOptions.headers }); | ||
return next.handle(request); | ||
} | ||
|
||
/** | ||
* Sets the basic/oauth authorization header depending on the configuration. | ||
* @param {string} authenticationKey Authentication key. | ||
*/ | ||
setAuthorizationToken(authenticationKey: string) { | ||
if (environment.oauth.enabled) { | ||
httpOptions.headers['Authorization'] = `Bearer ${authenticationKey}`; | ||
httpOptions.headers[authorizationHeader] = `Bearer ${authenticationKey}`; | ||
} else { | ||
httpOptions.headers['Authorization'] = `Basic ${authenticationKey}`; | ||
httpOptions.headers[authorizationHeader] = `Basic ${authenticationKey}`; | ||
} | ||
} | ||
|
||
/** | ||
* Sets the two factor access token header. | ||
* @param {string} twoFactorAccessToken Two factor access token. | ||
*/ | ||
setTwoFactorAccessToken(twoFactorAccessToken: string) { | ||
httpOptions.headers['Fineract-Platform-TFA-Token'] = twoFactorAccessToken; | ||
httpOptions.headers[twoFactorAccessTokenHeader] = twoFactorAccessToken; | ||
} | ||
|
||
/** | ||
* Removes the authorization header. | ||
*/ | ||
removeAuthorization() { | ||
delete httpOptions.headers['Authorization']; | ||
delete httpOptions.headers[authorizationHeader]; | ||
} | ||
|
||
/** | ||
* Removes the two factor access token header. | ||
*/ | ||
removeTwoFactorAuthorization() { | ||
delete httpOptions.headers['Fineract-Platform-TFA-Token']; | ||
delete httpOptions.headers[twoFactorAccessTokenHeader]; | ||
} | ||
|
||
} |
Oops, something went wrong.