Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
anis
anis-client
Commits
db5e1aa2
Commit
db5e1aa2
authored
Nov 13, 2020
by
Tifenn Guillas
Browse files
Add comments for authentication module => DONE
parent
b620de07
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/app/auth/auth.module.ts
View file @
db5e1aa2
...
...
@@ -27,4 +27,8 @@ import { AuthEffects } from './store/auth.effects';
initializeKeycloakAnis
]
})
/**
* @class
* @classdesc Authentication module.
*/
export
class
AuthModule
{
}
src/app/auth/store/auth.action.ts
View file @
db5e1aa2
...
...
@@ -11,36 +11,62 @@ import { Action } from '@ngrx/store';
import
{
UserProfile
}
from
'
./user-profile.model
'
;
export
const
LOGIN
=
'
[Auth] Login
'
;
export
const
LOGOUT
=
'
[Auth] Logout
'
;
export
const
AUTH_SUCCESS
=
'
[Auth] Auth Success
'
;
export
const
LOAD_USER_PROFILE_SUCCESS
=
'
[Auth] Load User Profile Success
'
;
export
const
OPEN_EDIT_PROFILE
=
'
[Auth] Edit Profile
'
;
/**
* @class
* @classdesc LoginAction action.
* @readonly
*/
export
class
LoginAction
implements
Action
{
readonly
type
=
LOGIN
;
constructor
(
public
payload
:
{}
=
null
)
{
}
}
/**
* @class
* @classdesc LogoutAction action.
* @readonly
*/
export
class
LogoutAction
implements
Action
{
readonly
type
=
LOGOUT
;
constructor
(
public
payload
:
{}
=
null
)
{
}
}
/**
* @class
* @classdesc AuthSuccessAction action.
* @readonly
*/
export
class
AuthSuccessAction
implements
Action
{
readonly
type
=
AUTH_SUCCESS
;
constructor
(
public
payload
:
{}
=
null
)
{
}
}
/**
* @class
* @classdesc LoadUserProfileSuccessAction action.
* @readonly
*/
export
class
LoadUserProfileSuccessAction
implements
Action
{
readonly
type
=
LOAD_USER_PROFILE_SUCCESS
;
constructor
(
public
payload
:
UserProfile
)
{
}
}
/**
* @class
* @classdesc OpenEditProfileAction action.
* @readonly
*/
export
class
OpenEditProfileAction
implements
Action
{
readonly
type
=
OPEN_EDIT_PROFILE
;
...
...
src/app/auth/store/auth.effects.ts
View file @
db5e1aa2
...
...
@@ -18,24 +18,37 @@ import * as authActions from './auth.action';
import
{
environment
}
from
'
../../../environments/environment
'
;
@
Injectable
()
/**
* @class
* @classdesc Authentication effects.
*/
export
class
AuthEffects
{
constructor
(
private
actions$
:
Actions
,
private
keycloak
:
KeycloakService
)
{
}
/**
* Logs in.
*/
@
Effect
({
dispatch
:
false
})
loginAction$
=
this
.
actions$
.
pipe
(
ofType
(
authActions
.
LOGIN
),
tap
(
_
=>
this
.
keycloak
.
login
())
);
/**
* Logs out.
*/
@
Effect
({
dispatch
:
false
})
logoutAction$
=
this
.
actions$
.
pipe
(
ofType
(
authActions
.
LOGOUT
),
tap
(
_
=>
this
.
keycloak
.
logout
())
);
/**
* Loads user profile when log in success.
*/
@
Effect
()
authSuccessAction$
=
this
.
actions$
.
pipe
(
ofType
(
authActions
.
AUTH_SUCCESS
),
...
...
@@ -46,6 +59,9 @@ export class AuthEffects {
)
);
/**
* Opens edit profile page.
*/
@
Effect
({
dispatch
:
false
})
OpenEditProfileAction$
=
this
.
actions$
.
pipe
(
ofType
(
authActions
.
OPEN_EDIT_PROFILE
),
...
...
src/app/auth/store/auth.reducer.ts
View file @
db5e1aa2
...
...
@@ -10,6 +10,11 @@
import
*
as
actions
from
'
./auth.action
'
;
import
{
UserProfile
}
from
'
./user-profile.model
'
;
/**
* Interface for authentication state.
*
* @interface State
*/
export
interface
State
{
isAuthenticated
:
boolean
;
userProfile
:
UserProfile
;
...
...
@@ -20,6 +25,14 @@ export const initialState: State = {
userProfile
:
null
};
/**
* Reduces state.
*
* @param {State} state - The state.
* @param {actions} action - The action.
*
* @return State
*/
export
function
reducer
(
state
:
State
=
initialState
,
action
:
actions
.
Actions
):
State
{
switch
(
action
.
type
)
{
case
actions
.
AUTH_SUCCESS
:
...
...
src/app/auth/store/user-profile.model.ts
View file @
db5e1aa2
...
...
@@ -7,6 +7,11 @@
* file that was distributed with this source code.
*/
/**
* Interface for user profile.
*
* @interface UserProfile
*/
export
interface
UserProfile
{
id
?:
string
;
username
?:
string
;
...
...
Write
Preview
Supports
Markdown
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