Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
e-epal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
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
Χάρης Παπαδόπουλος
e-epal
Commits
409fc1ce
Commit
409fc1ce
authored
Mar 14, 2017
by
Open Source Developer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
currentuser
parent
8f3ed10c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
67 additions
and
39 deletions
+67
-39
drupal/modules/epal/epal.routing.yml
drupal/modules/epal/epal.routing.yml
+2
-2
drupal/modules/epal/src/Controller/CurrentUser.php
drupal/modules/epal/src/Controller/CurrentUser.php
+43
-23
source/components/home.ts
source/components/home.ts
+2
-8
source/components/navbar/navbar.component.html
source/components/navbar/navbar.component.html
+1
-1
source/services/helper-data-service.ts
source/services/helper-data-service.ts
+17
-2
source/store/logininfo/logininfo.reducer.ts
source/store/logininfo/logininfo.reducer.ts
+1
-1
source/store/logininfo/logininfo.transformers.ts
source/store/logininfo/logininfo.transformers.ts
+1
-1
source/store/logininfo/logininfo.types.ts
source/store/logininfo/logininfo.types.ts
+0
-1
No files found.
drupal/modules/epal/epal.routing.yml
View file @
409fc1ce
...
@@ -23,13 +23,13 @@ epal_auth_test:
...
@@ -23,13 +23,13 @@ epal_auth_test:
_permission
:
'
access
content'
_permission
:
'
access
content'
_user_is_logged_in
:
'
TRUE'
_user_is_logged_in
:
'
TRUE'
current_user
:
current_user
:
path
:
'
/epal/curuser
/{token_name}
'
path
:
'
/epal/curuser'
options
:
options
:
_auth
:
[
'
basic_auth'
]
_auth
:
[
'
basic_auth'
]
defaults
:
defaults
:
_controller
:
'
\Drupal\epal\Controller\CurrentUser::content'
_controller
:
'
\Drupal\epal\Controller\CurrentUser::content'
requirements
:
requirements
:
_
access
:
'
TRUE'
_
user_is_logged_in
:
'
TRUE'
epal.application_submit
:
epal.application_submit
:
path
:
'
/epal/appsubmit'
path
:
'
/epal/appsubmit'
options
:
options
:
...
...
drupal/modules/epal/src/Controller/CurrentUser.php
View file @
409fc1ce
<?php
<?php
/**
* @file
* Contains \Drupal\query_example\Controller\QueryExampleController.
*/
namespace
Drupal\epal\Controller
;
namespace
Drupal\epal\Controller
;
...
@@ -15,26 +7,54 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
...
@@ -15,26 +7,54 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\Core\Entity\EntityFieldManagerInterface
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
class
CurrentUser
extends
ControllerBase
{
class
CurrentUser
extends
ControllerBase
{
protected
$entityTypeManager
;
public
function
content
(
$token_name
)
{
public
function
__construct
(
EntityTypeManagerInterface
$entityTypeManager
)
$query
=
\
Drupal
::
database
()
->
select
(
'epal_users'
,
'nfd'
);
{
$query
->
fields
(
'nfd'
,
[
'name'
]);
$this
->
entityTypeManager1
=
$entityTypeManager
;
$query
->
condition
(
'nfd.authtoken'
,
$token_name
);
$field
=
$query
->
execute
()
->
fetchAssoc
();
}
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$response
=
new
JsonResponse
(
$field
);
$container
->
get
(
'entity_type.manager'
),
return
$response
;
$container
->
get
(
'entity.query'
),
$container
->
get
(
'entity_field.manager'
)
}
);
}
public
function
content
(
Request
$request
)
{
$authToken
=
$request
->
headers
->
get
(
'PHP_AUTH_USER'
);
$epalUsers
=
$this
->
entityTypeManager1
->
getStorage
(
'epal_users'
)
->
loadByProperties
(
array
(
'authtoken'
=>
$authToken
));
$epalUser
=
reset
(
$epalUsers
);
if
(
$epalUser
)
{
$currentUserName
=
$epalUser
->
name
->
value
;
$response
=
new
JsonResponse
([
'name'
=>
$currentUserName
]);
}
else
{
$response
=
new
Response
();
$response
->
setContent
(
'forbidden'
);
$response
->
setStatusCode
(
Response
::
HTTP_FORBIDDEN
);
$response
->
headers
->
set
(
'Content-Type'
,
'application/json'
);
}
return
$response
;
}
}
}
source/components/home.ts
View file @
409fc1ce
...
@@ -90,7 +90,8 @@ export default class Home implements OnInit {
...
@@ -90,7 +90,8 @@ export default class Home implements OnInit {
state
.
loginInfo
.
reduce
(({},
loginInfoToken
)
=>
{
state
.
loginInfo
.
reduce
(({},
loginInfoToken
)
=>
{
this
.
authToken
=
loginInfoToken
.
auth_token
;
this
.
authToken
=
loginInfoToken
.
auth_token
;
this
.
authRole
=
loginInfoToken
.
auth_role
;
this
.
authRole
=
loginInfoToken
.
auth_role
;
if
(
this
.
authToken
&&
this
.
authToken
.
length
>
0
)
this
.
router
.
navigate
([
'
/epal-class-select
'
]);
return
loginInfoToken
;
return
loginInfoToken
;
},
{});
},
{});
}
}
...
@@ -100,9 +101,6 @@ export default class Home implements OnInit {
...
@@ -100,9 +101,6 @@ export default class Home implements OnInit {
// subscribe to router event
// subscribe to router event
this
.
activatedRoute
.
queryParams
.
subscribe
((
params
:
Params
)
=>
{
this
.
activatedRoute
.
queryParams
.
subscribe
((
params
:
Params
)
=>
{
this
.
authToken
=
params
[
'
auth_token
'
];
this
.
authRole
=
params
[
'
auth_role
'
];
if
(
params
)
{
if
(
params
)
{
this
.
authToken
=
params
[
'
auth_token
'
];
this
.
authToken
=
params
[
'
auth_token
'
];
this
.
authRole
=
params
[
'
auth_role
'
];
this
.
authRole
=
params
[
'
auth_role
'
];
...
@@ -110,10 +108,6 @@ export default class Home implements OnInit {
...
@@ -110,10 +108,6 @@ export default class Home implements OnInit {
if
(
this
.
authToken
&&
this
.
authRole
)
if
(
this
.
authToken
&&
this
.
authRole
)
this
.
_ata
.
getloginInfo
({
auth_token
:
this
.
authToken
,
auth_role
:
this
.
authRole
});
this
.
_ata
.
getloginInfo
({
auth_token
:
this
.
authToken
,
auth_role
:
this
.
authRole
});
console
.
log
(
this
.
authToken
,
"
tttttttt
"
);
if
(
this
.
authToken
&&
this
.
authToken
.
length
>
0
)
this
.
router
.
navigate
([
'
/epal-class-select
'
]);
// this._ata.saveLoginInfo({ auth_token: this.authToken, auth_role: this.authRole, cu_name:this.name });
});
});
}
}
...
...
source/components/navbar/navbar.component.html
View file @
409fc1ce
<div
class=
"nav-wrapper"
>
<div
class=
"nav-wrapper"
class=
"content"
>
<div
class=
"container"
>
<div
class=
"container"
>
<nav
class=
"navbar navbar-toggleable-sm"
>
<nav
class=
"navbar navbar-toggleable-sm"
>
<button
class=
"navbar-toggler navbar-toggler-right"
type=
"button"
data-toggle=
"collapse"
data-target=
"#navbarNav"
aria-controls=
"navbarNav"
aria-expanded=
"false"
aria-label=
"Toggle navigation"
>
<button
class=
"navbar-toggler navbar-toggler-right"
type=
"button"
data-toggle=
"collapse"
data-target=
"#navbarNav"
aria-controls=
"navbarNav"
aria-expanded=
"false"
aria-label=
"Toggle navigation"
>
...
...
source/services/helper-data-service.ts
View file @
409fc1ce
...
@@ -233,8 +233,23 @@ export class HelperDataService {
...
@@ -233,8 +233,23 @@ export class HelperDataService {
getCurrentUser
(
oauthtoken
,
oauthrole
)
{
getCurrentUser
(
oauthtoken
,
oauthrole
)
{
this
.
authToken
=
oauthtoken
;
let
headers
=
new
Headers
({
//"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
// "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
"
Content-Type
"
:
"
application/json
"
,
// "Content-Type": "text/plain", // try to skip preflight
//"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
//"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
"
X-CSRF-Token
"
:
"
LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc
"
,
// "X-oauth-enabled": "true",
// "X-Auth-Token": this.authToken
});
this
.
createAuthorizationHeader
(
headers
);
let
options
=
new
RequestOptions
({
headers
:
headers
});
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
http
.
get
(
`
${
AppSettings
.
API_ENDPOINT
}
/epal/curuser
/
${
oauthtoken
}
`
)
this
.
http
.
get
(
`
${
AppSettings
.
API_ENDPOINT
}
/epal/curuser
`
,
options
)
.
map
(
response
=>
response
.
json
())
.
map
(
response
=>
response
.
json
())
.
subscribe
(
data
=>
{
.
subscribe
(
data
=>
{
resolve
(
this
.
transformUserSchema
(
data
,
oauthtoken
,
oauthrole
));
resolve
(
this
.
transformUserSchema
(
data
,
oauthtoken
,
oauthrole
));
...
@@ -256,7 +271,7 @@ transformUserSchema(userlogin:any,oauthtoken:string, oauthrole:string){
...
@@ -256,7 +271,7 @@ transformUserSchema(userlogin:any,oauthtoken:string, oauthrole:string){
}
}
signOut
()
{
signOut
()
{
this
.
loginInfo$
.
forEach
(
loginInfoToken
=>
{
this
.
loginInfo$
.
forEach
(
loginInfoToken
=>
{
console
.
log
(
loginInfoToken
.
get
(
0
));
console
.
log
(
loginInfoToken
.
get
(
0
));
this
.
authToken
=
loginInfoToken
.
get
(
0
).
auth_token
;
this
.
authToken
=
loginInfoToken
.
get
(
0
).
auth_token
;
...
...
source/store/logininfo/logininfo.reducer.ts
View file @
409fc1ce
...
@@ -13,7 +13,7 @@ export function loginInfoReducer(state: ILoginInfo = INITIAL_STATE, action): ILo
...
@@ -13,7 +13,7 @@ export function loginInfoReducer(state: ILoginInfo = INITIAL_STATE, action): ILo
let
loginInfoTokens
=
Array
<
ILoginInfoToken
>
();
let
loginInfoTokens
=
Array
<
ILoginInfoToken
>
();
let
i
=
0
;
let
i
=
0
;
action
.
payload
.
loginInfos
.
forEach
(
loginInfo
=>
{
action
.
payload
.
loginInfos
.
forEach
(
loginInfo
=>
{
loginInfoTokens
.
push
(
<
ILoginInfoToken
>
{
auth_token
:
loginInfo
.
auth_token
,
auth_role
:
loginInfo
.
auth_role
,
cu_name
:
loginInfo
.
cu_name
,
xcsrftoken
:
loginInfo
.
xcsrftoken
});
loginInfoTokens
.
push
(
<
ILoginInfoToken
>
{
auth_token
:
loginInfo
.
auth_token
,
auth_role
:
loginInfo
.
auth_role
,
cu_name
:
loginInfo
.
cu_name
});
i
++
;
i
++
;
});
});
return
Seq
(
loginInfoTokens
).
map
(
n
=>
n
).
toList
();
return
Seq
(
loginInfoTokens
).
map
(
n
=>
n
).
toList
();
...
...
source/store/logininfo/logininfo.transformers.ts
View file @
409fc1ce
...
@@ -3,7 +3,7 @@ import { ILoginInfo, ILoginInfoToken } from './logininfo.types';
...
@@ -3,7 +3,7 @@ import { ILoginInfo, ILoginInfoToken } from './logininfo.types';
export
function
deimmutifyLoginInfo
(
state
:
ILoginInfo
):
ILoginInfoToken
[]
{
export
function
deimmutifyLoginInfo
(
state
:
ILoginInfo
):
ILoginInfoToken
[]
{
let
fetchedLoginInfoTokens
=
new
Array
();
let
fetchedLoginInfoTokens
=
new
Array
();
state
.
forEach
(
loginInfoToken
=>
{
state
.
forEach
(
loginInfoToken
=>
{
fetchedLoginInfoTokens
.
push
(
<
ILoginInfoToken
>
{
auth_token
:
loginInfoToken
.
auth_token
,
auth_role
:
loginInfoToken
.
auth_role
,
cu_name
:
loginInfoToken
.
cu_name
,
xcsrftoken
:
loginInfoToken
.
xcsrftoken
});
fetchedLoginInfoTokens
.
push
(
<
ILoginInfoToken
>
{
auth_token
:
loginInfoToken
.
auth_token
,
auth_role
:
loginInfoToken
.
auth_role
,
cu_name
:
loginInfoToken
.
cu_name
});
});
});
return
fetchedLoginInfoTokens
;
return
fetchedLoginInfoTokens
;
};
};
source/store/logininfo/logininfo.types.ts
View file @
409fc1ce
...
@@ -4,7 +4,6 @@ export interface ILoginInfoToken {
...
@@ -4,7 +4,6 @@ export interface ILoginInfoToken {
auth_token
:
string
;
auth_token
:
string
;
auth_role
:
string
;
auth_role
:
string
;
cu_name
:
string
;
cu_name
:
string
;
xcsrftoken
:
string
;
}
}
export
type
ILoginInfo
=
List
<
ILoginInfoToken
>
;
export
type
ILoginInfo
=
List
<
ILoginInfoToken
>
;
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