Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Χάρης Παπαδόπουλος
e-epal
Commits
e3c939f6
Commit
e3c939f6
authored
Mar 14, 2017
by
Νίκος Κατσαούνος
Browse files
Merge branch 'develop' of
https://git.minedu.gov.gr/itminedu/e-epal
into director_view
parents
86a020e5
cb154a87
Changes
14
Hide whitespace changes
Inline
Side-by-side
drupal/modules/epal/epal.routing.yml
View file @
e3c939f6
...
...
@@ -23,7 +23,9 @@ epal_auth_test:
_permission
:
'
access
content'
_user_is_logged_in
:
'
TRUE'
current_user
:
path
:
'
/epal/curuser'
path
:
'
/epal/curuser/{token_name}'
options
:
_auth
:
[
'
basic_auth'
]
defaults
:
_controller
:
'
\Drupal\epal\Controller\CurrentUser::content'
requirements
:
...
...
drupal/modules/epal/src/Controller/CurrentUser.php
View file @
e3c939f6
...
...
@@ -4,6 +4,10 @@
* Contains \Drupal\query_example\Controller\QueryExampleController.
*/
namespace
Drupal\epal\Controller
;
use
Drupal\Core\Entity\Query\QueryFactory
;
...
...
@@ -13,26 +17,22 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use
Drupal\Core\Controller\ControllerBase
;
class
CurrentUser
extends
ControllerBase
{
public
function
content
()
{
// $name = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$name
=
"LALALA"
;
$authToken
=
"no authToken"
;
$accessKey
=
"no accessKey"
;
if
(
\
Drupal
::
request
()
->
headers
->
has
(
'X-AUTH-TOKEN'
))
{
$authToken
=
\
Drupal
::
request
()
->
headers
->
get
(
'X-AUTH-TOKEN'
);
}
if
(
\
Drupal
::
request
()
->
headers
->
has
(
'X-ACCESS-KEY'
))
{
$accessKey
=
\
Drupal
::
request
()
->
headers
->
get
(
'X-ACCESS-KEY'
);
}
$response
=
new
JsonResponse
([
$name
]);
$response
->
headers
->
set
(
'X-AUTH-TOKEN'
,
'HELLOTOKEN'
);
public
function
content
(
$token_name
)
{
$query
=
\
Drupal
::
database
()
->
select
(
'epal_users'
,
'nfd'
);
$query
->
fields
(
'nfd'
,
[
'name'
]);
$query
->
condition
(
'nfd.authtoken'
,
$token_name
);
$field
=
$query
->
execute
()
->
fetchAssoc
();
$response
=
new
JsonResponse
(
$field
);
return
$response
;
}
...
...
source/actions/index.ts
View file @
e3c939f6
...
...
@@ -8,8 +8,9 @@ import { AmkaFillsActions} from './amkafill.actions';
import
{
LoginInfoActions
}
from
'
./logininfo.actions
'
;
import
{
CriteriaActions
}
from
'
./criteria.actions
'
;
const
ACTION_PROVIDERS
=
[
CourseFieldsActions
,
SectorFieldsActions
,
RegionSchoolsActions
,
SectorCoursesActions
,
StudentDataFieldsActions
,
EpalClassesActions
,
AmkaFillsActions
,
LoginInfoActions
,
CriteriaActions
];
EpalClassesActions
,
AmkaFillsActions
,
LoginInfoActions
,
CriteriaActions
];
export
{
CourseFieldsActions
,
...
...
@@ -21,5 +22,6 @@ export {
AmkaFillsActions
,
LoginInfoActions
,
CriteriaActions
,
ACTION_PROVIDERS
,
};
source/actions/logininfo.actions.ts
View file @
e3c939f6
import
{
LOGININFO_SAVE
,
LOGININFO_INIT
}
from
'
../constants
'
;
import
{
LOGININFO_SAVE
,
LOGININFO_RECEIVED
}
from
'
../constants
'
;
import
{
LOGININFO_INIT
}
from
'
../constants
'
;
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
NgRedux
}
from
'
ng2-redux
'
;
import
{
IAppState
}
from
'
../store
'
;
...
...
@@ -10,14 +11,17 @@ export class LoginInfoActions {
private
_ngRedux
:
NgRedux
<
IAppState
>
,
private
_hds
:
HelperDataService
)
{}
saveLoginInfo
=
(
loginInfo
)
=>
{
getloginInfo
=
(
loginInfo
)
=>
{
return
this
.
_hds
.
getCurrentUser
(
loginInfo
.
auth_token
,
loginInfo
.
auth_role
).
then
(
loginInfos
=>
{
return
this
.
_ngRedux
.
dispatch
({
type
:
LOGININFO_SAVE
,
payload
:
{
loginInfo
loginInfo
s
}
});
};
});
}
initLoginInfo
=
()
=>
{
return
this
.
_ngRedux
.
dispatch
({
...
...
@@ -27,4 +31,5 @@ export class LoginInfoActions {
});
};
}
source/app.settings.ts
View file @
e3c939f6
export
const
API_ENDPOINT
=
'
http://localhost/drupal
-8.2.5
'
;
export
const
API_ENDPOINT
=
'
http://localhost/
angular/eepal-front/
drupal
'
;
export
class
AppSettings
{
public
static
get
API_ENDPOINT
():
string
{
return
'
http://localhost/drupal
-8.2.5
'
;
return
'
http://localhost/
angular/eepal-front/
drupal
'
;
// return 'http://localhost/angular/eepal-front/drupal';
// return 'http://localhost/drupal';
// return 'http://localhost/angular/eepal-front/drupal';
// return 'http://localhost/drupal';
// return 'http://localhost/
angular/eepal-front/
drupal';
// return 'http://eepal.dev/drupal';
// return 'http://localhost/drupal';
// return 'http://eduslim2.minedu.gov.gr/drupal';
}
}
source/components/home.ts
View file @
e3c939f6
...
...
@@ -5,6 +5,7 @@ import { ILoginInfo } from '../store/logininfo/logininfo.types';
import
{
NgRedux
,
select
}
from
'
ng2-redux
'
;
import
{
Observable
}
from
'
rxjs/Rx
'
;
import
{
IAppState
}
from
'
../store/store
'
;
import
{
HelperDataService
}
from
'
../services/helper-data-service
'
;
import
{
FormBuilder
,
FormGroup
,
...
...
@@ -17,7 +18,7 @@ import { API_ENDPOINT } from '../app.settings';
selector
:
'
home
'
,
template
:
`
<div>
<form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/oauth/login" #form>
<form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/oauth/login" #form>
<!-- <input type="hidden" name="X-oauth-enabled" value="true"> -->
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
...
...
@@ -57,10 +58,13 @@ import { API_ENDPOINT } from '../app.settings';
</div>
`
})
export
default
class
Home
implements
OnInit
{
public
formGroup
:
FormGroup
;
private
authToken
:
string
;
private
authRole
:
string
;
private
name
:
any
;
private
xcsrftoken
:
any
;
private
loginInfo$
:
Observable
<
ILoginInfo
>
;
private
apiEndPoint
=
API_ENDPOINT
;
...
...
@@ -68,10 +72,12 @@ export default class Home implements OnInit {
private
_ata
:
LoginInfoActions
,
private
_ngRedux
:
NgRedux
<
IAppState
>
,
private
activatedRoute
:
ActivatedRoute
,
private
_hds
:
HelperDataService
,
private
router
:
Router
)
{
this
.
authToken
=
''
;
this
.
authRole
=
''
;
this
.
name
=
''
;
this
.
formGroup
=
this
.
fb
.
group
({
// Username: [],
// Paswd: []
...
...
@@ -79,30 +85,36 @@ export default class Home implements OnInit {
};
ngOnInit
()
{
this
.
loginInfo$
=
this
.
_ngRedux
.
select
(
state
=>
{
this
.
loginInfo$
=
this
.
_ngRedux
.
select
(
state
=>
{
if
(
state
.
loginInfo
.
size
>
0
)
{
state
.
loginInfo
.
reduce
(({},
loginInfoToken
)
=>
{
this
.
authToken
=
loginInfoToken
.
auth_token
;
this
.
authRole
=
loginInfoToken
.
auth_role
;
if
(
this
.
authToken
&&
this
.
authToken
.
length
>
0
)
this
.
router
.
navigate
([
'
/epal-class-select
'
]);
return
loginInfoToken
;
},
{});
}
return
state
.
loginInfo
;
});
// subscribe to router event
this
.
activatedRoute
.
queryParams
.
subscribe
((
params
:
Params
)
=>
{
this
.
authToken
=
params
[
'
auth_token
'
];
this
.
authRole
=
params
[
'
auth_role
'
];
if
(
params
)
{
this
.
authToken
=
params
[
'
auth_token
'
];
this
.
authRole
=
params
[
'
auth_role
'
];
}
if
(
this
.
authToken
&&
this
.
authRole
)
this
.
_ata
.
saveLoginInfo
({
auth_token
:
this
.
authToken
,
auth_role
:
this
.
authRole
});
// console.log(this.authToken);
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 @
e3c939f6
...
...
@@ -10,14 +10,18 @@
<div
class=
"collapse navbar-collapse flex-row-reverse"
id=
"navbarNav"
>
<div
*ngFor=
"let loginInfoToken$ of loginInfo$ | async; let i=index"
></div>
<ul
class=
"navbar-nav"
>
<b>
Όνομα Χρήστη:
</b>
{{this.cuser}}
<div
*ngFor=
"let username$ of loginInfo$ | async;"
>
<b>
Όνομα Χρήστη:
</b>
{{username$.cu_name}}
<div
*ngIf=
"authToken"
>
<button
type=
"button"
class=
"btn-primary btn-sm pull-right"
(click)=
"oauthSignOut()"
>
<i
class=
"fa fa-sign-out"
></i>
</button>
</div>
</div>
<!--
<li class="nav-item" [ngClass]="{active: path=='application-preview'}">
<a class="nav-link" [routerLink]="['/application-preview']" [routerLinkActive]="['active']">Προεπισκόπηση</a>
...
...
source/components/navbar/navbar.component.ts
View file @
e3c939f6
import
{
Component
,
OnInit
}
from
'
@angular/core
'
;
import
{
Router
}
from
'
@angular/router
'
;
import
{
Injectable
}
from
"
@angular/core
"
;
import
{
HelperDataService
}
from
'
../../services/helper-data-service
'
;
import
{
Observable
}
from
'
rxjs/Rx
'
;
import
{
LoginInfoActions
}
from
'
../../actions/logininfo.actions
'
;
import
{
ILoginInfo
}
from
'
../../store/logininfo/logininfo.types
'
;
import
{
NgRedux
,
select
}
from
'
ng2-redux
'
;
import
{
IAppState
}
from
'
../../store/store
'
;
import
{
ILoginInfo
,
ILoginInfoToken
}
from
'
../../store/logininfo/logininfo.types
'
;
import
{
HelperDataService
}
from
'
../../services/helper-data-service
'
;
import
{
LoginInfoActions
}
from
'
../../actions/logininfo.actions
'
;
@
Component
({
selector
:
'
reg-navbar
'
,
...
...
@@ -19,6 +22,10 @@ import { IAppState } from '../../store/store';
private
loginInfo$
:
Observable
<
ILoginInfo
>
;
public
cuser
:
any
;
constructor
(
private
_ata
:
LoginInfoActions
,
private
_hds
:
HelperDataService
,
private
_ngRedux
:
NgRedux
<
IAppState
>
,
...
...
@@ -43,7 +50,7 @@ import { IAppState } from '../../store/store';
return
state
.
loginInfo
;
});
this
.
_hds
.
getCurrentUser
().
then
(
cuser
=>
this
.
cuser
=
cuser
);
}
oauthSignOut
()
{
...
...
@@ -56,5 +63,4 @@ import { IAppState } from '../../store/store';
}
}
source/constants.ts
View file @
e3c939f6
...
...
@@ -21,6 +21,12 @@ export const EPALCLASSES_SAVE = 'EPALCLASSES_SAVE';
export
const
AMKAFILL_SAVE
=
'
AMKAFILL_SAVE
'
;
export
const
LOGININFO_SAVE
=
'
LOGININFO_SAVE
'
;
export
const
LOGININFO_RECEIVED
=
'
LOGININFO_RECEIVED
'
;
export
const
USERINFOS_RECEIVED
=
'
USERINFOS_RECEIVED
'
;
export
const
USERINFO_SELECTED_SAVE
=
'
USERINFO_SELECTED_SAVE
'
;
export
const
LOGININFO_INIT
=
'
LOGININFO_INIT
'
;
export
const
CRITERIA_RECEIVED
=
'
CRITERIA_RECEIVED
'
;
...
...
source/services/helper-data-service.ts
View file @
e3c939f6
...
...
@@ -10,7 +10,8 @@ import { ISector, ISectors, ISectorCourse } from '../store/sectorcourses/sectorc
import
{
AppSettings
}
from
'
../app.settings
'
;
import
{
NgRedux
,
select
}
from
'
ng2-redux
'
;
import
{
IAppState
}
from
'
../store/store
'
;
import
{
ILoginInfo
}
from
'
../store/logininfo/logininfo.types
'
;
import
{
ILoginInfo
,
ILoginInfoToken
}
from
'
../store/logininfo/logininfo.types
'
;
const
HEADER
=
{
headers
:
new
Headers
({
'
Content-Type
'
:
'
application/json
'
})
};
...
...
@@ -254,20 +255,29 @@ export class HelperDataService {
});
};
getCurrentUser
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
http
.
get
(
`
${
AppSettings
.
API_ENDPOINT
}
/epal/curuser`
)
getCurrentUser
(
oauthtoken
,
oauthrole
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
http
.
get
(
`
${
AppSettings
.
API_ENDPOINT
}
/epal/curuser
/
${
oauthtoken
}
`
)
.
map
(
response
=>
response
.
json
())
.
subscribe
(
data
=>
{
resolve
(
data
);
},
resolve
(
this
.
transformUserSchema
(
data
,
oauthtoken
,
oauthrole
)
);
},
// put the data returned from the server in our variable
error
=>
{
console
.
log
(
"
Error HTTP GET Service
"
);
console
.
log
(
"
Error HTTP GET Service
"
);
// in case of failure show this message
reject
(
"
Error HTTP GET Service
"
);
},
()
=>
console
.
log
(
"
Course Fields
Received
"
));
()
=>
console
.
log
(
"
UserName
Received
"
));
});
};
}
transformUserSchema
(
userlogin
:
any
,
oauthtoken
:
string
,
oauthrole
:
string
){
let
rsa
=
Array
<
ILoginInfoToken
>
();
rsa
.
push
(
<
ILoginInfoToken
>
{
'
auth_token
'
:
oauthtoken
,
'
auth_role
'
:
oauthrole
,
'
cu_name
'
:
userlogin
.
name
});
return
rsa
;
}
signOut
()
{
this
.
loginInfo$
.
forEach
(
loginInfoToken
=>
{
...
...
@@ -278,7 +288,8 @@ export class HelperDataService {
//"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
// "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
"
Content-Type
"
:
"
application/json
"
,
"
Content-Type
"
:
"
application/json
"
,
"
Accept
"
:
"
*/*
"
,
"
Access-Control-Allow-Credentials
"
:
"
true
"
,
// "Content-Type": "text/plain", // try to skip preflight
...
...
@@ -305,4 +316,5 @@ export class HelperDataService {
});
}
}
source/store/logininfo/logininfo.reducer.ts
View file @
e3c939f6
...
...
@@ -10,9 +10,14 @@ import {
export
function
loginInfoReducer
(
state
:
ILoginInfo
=
INITIAL_STATE
,
action
):
ILoginInfo
{
switch
(
action
.
type
)
{
case
LOGININFO_SAVE
:
let
loginInfoTokens
=
Array
<
ILoginInfoToken
>
();
loginInfoTokens
.
push
(
<
ILoginInfoToken
>
{
auth_token
:
action
.
payload
.
loginInfo
.
auth_token
,
auth_role
:
action
.
payload
.
loginInfo
.
auth_role
});
let
loginInfoTokens
=
Array
<
ILoginInfoToken
>
();
let
i
=
0
;
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
});
i
++
;
});
return
Seq
(
loginInfoTokens
).
map
(
n
=>
n
).
toList
();
case
LOGININFO_INIT
:
return
INITIAL_STATE
;
default
:
...
...
source/store/logininfo/logininfo.transformers.ts
View file @
e3c939f6
...
...
@@ -3,7 +3,7 @@ import { ILoginInfo, ILoginInfoToken } from './logininfo.types';
export
function
deimmutifyLoginInfo
(
state
:
ILoginInfo
):
ILoginInfoToken
[]
{
let
fetchedLoginInfoTokens
=
new
Array
();
state
.
forEach
(
loginInfoToken
=>
{
fetchedLoginInfoTokens
.
push
(
<
ILoginInfoToken
>
{
auth_token
:
loginInfoToken
.
auth_token
,
auth_role
:
loginInfoToken
.
auth_role
});
fetchedLoginInfoTokens
.
push
(
<
ILoginInfoToken
>
{
auth_token
:
loginInfoToken
.
auth_token
,
auth_role
:
loginInfoToken
.
auth_role
,
cu_name
:
loginInfoToken
.
cu_name
,
xcsrftoken
:
loginInfoToken
.
xcsrftoken
});
});
return
fetchedLoginInfoTokens
;
};
source/store/logininfo/logininfo.types.ts
View file @
e3c939f6
...
...
@@ -3,6 +3,8 @@ import { List } from 'immutable';
export
interface
ILoginInfoToken
{
auth_token
:
string
;
auth_role
:
string
;
cu_name
:
string
;
xcsrftoken
:
string
;
}
export
type
ILoginInfo
=
List
<
ILoginInfoToken
>
;
source/store/store.ts
View file @
e3c939f6
...
...
@@ -23,6 +23,7 @@ export interface IAppState {
amkafills
?:
amkafills
.
IAmkaFills
;
loginInfo
?:
loginInfo
.
ILoginInfo
;
criter
?:
criter
.
ICriter
;
};
export
const
rootReducer
=
combineReducers
<
IAppState
>
({
...
...
@@ -35,6 +36,7 @@ export const rootReducer = combineReducers<IAppState>({
amkafills
:
amkafills
.
amkafillReducer
,
loginInfo
:
loginInfo
.
loginInfoReducer
,
criter
:
criter
.
criteriaReducer
,
});
export
function
deimmutify
(
state
:
IAppState
):
Object
{
...
...
@@ -48,6 +50,7 @@ export function deimmutify(state: IAppState): Object {
amkafills
:
amkafills
.
deimmutifyAmkaFills
(
state
.
amkafills
),
loginInfo
:
loginInfo
.
deimmutifyLoginInfo
(
state
.
loginInfo
),
criter
:
criter
.
deimmutifyCriteria
(
state
.
criter
),
};
}
...
...
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