Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
smart_core_connect
/
core-connect
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
83b770af
authored
May 18, 2018
by
Prasong Putichanchai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update user
parent
3e1fe137
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
289 additions
and
88 deletions
+289
-88
www/config/app.php
+40
-0
www/config/bootstrap.php
+2
-0
www/config/routes.php
+6
-2
www/src/Controller/AppController.php
+169
-8
www/src/Controller/ProfilesController.php
+1
-0
www/src/Controller/UsersController.php
+62
-72
www/src/Template/Users/signin.ctp
+9
-6
No files found.
www/config/app.php
View file @
83b770af
...
...
@@ -444,6 +444,46 @@ return [
*/
'Session'
=>
[
'defaults'
=>
'php'
,
'ini'
=>
[
'session.cookie_path'
=>
'/'
,
'session.cookie_domain'
=>
'.pakgon.com'
]
],
'OAuth2Client'
=>
[
'routes'
=>
[
'base_uri'
=>
'http://oauth-uat.connect.pakgon.com'
,
'access_token_path'
=>
'/oauth'
,
'refresh_token_path'
=>
'/oauth/access_token'
,
],
'keys'
=>
[
'client_id'
=>
'NWFmYTdjYzA3OTI4M2Jj'
,
'client_secret'
=>
'2cf5e8f82bfaa9971e8af9ed06c23d94ef1326ba'
]
],
'Muffin/OAuth2'
,
[
'providers'
=>
[
'generic'
=>
[
'className'
=>
'League\OAuth2\Client\Provider\GenericProvider'
,
// all options defined here are passed to the provider's constructor
'options'
=>
[
'clientId'
=>
'NWFmYTdjYzA3OTI4M2Jj'
,
'clientSecret'
=>
'2cf5e8f82bfaa9971e8af9ed06c23d94ef1326ba'
,
],
'mapFields'
=>
[
'username'
=>
'login'
,
// maps the app's username to github's login
],
// ... add here the usual AuthComponent configuration if needed like fields, etc.
],
],
],
'OAUTH2_PROVIDER'
=>
[
'URL'
=>
'http://oauth-uat.connect.pakgon.com'
,
'CLIENT_ID'
=>
'NWFmYTdjYzA3OTI4M2Jj'
,
'CLIENT_SECRET'
=>
'2cf5e8f82bfaa9971e8af9ed06c23d94ef1326ba'
,
'REDIRECT_URI'
=>
'http://commu-uat.connect.pakgon.com/home/callback'
,
'ACCESS_TOKEN_URL'
=>
'http://oauth-uat.connect.pakgon.com/oauth/access_token.json'
,
'REFRESH_TOKEN_URL'
=>
'xxx'
],
'Config'
=>
[
...
...
www/config/bootstrap.php
View file @
83b770af
...
...
@@ -217,3 +217,4 @@ if (Configure::read('debug')) {
//Plugin::load('AdminLTE', ['bootstrap' => true, 'routes' => true]);
//Plugin::load('Porto',['bootstrap' => true,'routes' => true ]);
}
Plugin
::
load
(
'Muffin/OAuth2'
);
\ No newline at end of file
www/config/routes.php
View file @
83b770af
...
...
@@ -49,12 +49,16 @@ Router::scope('/', function (RouteBuilder $routes) {
* its action called 'display', and we pass a param to select the view file
* to use (in this case, src/Template/Pages/home.ctp)...
*/
$routes
->
connect
(
'/'
,
[
'controller'
=>
'Users'
,
'action'
=>
'signin'
]);
// $routes->connect('/', ['controller' => 'Users', 'action' => 'signin']);
$routes
->
connect
(
'/'
,
[
'controller'
=>
'homes'
,
'action'
=>
'index'
]);
/**
* ...and connect the rest of 'Pages' controller's URLs.
*/
////$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
$routes
->
connect
(
'/pages/*'
,
[
'controller'
=>
'Pages'
,
'action'
=>
'display'
]);
//Adding by sarawutt.b for oauth2 authenticatio
//$routes->connect('/oauth/:provider', ['controller' => 'users', 'action' => 'login'], ['provider' => 'generic']);
$routes
->
setExtensions
([
'json'
,
'xml'
,
'html'
]);
/**
* Connect catchall routes for all controllers.
...
...
www/src/Controller/AppController.php
View file @
83b770af
<?php
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
...
...
@@ -12,10 +13,13 @@
* @since 0.2.9
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace
App\Controller
;
use
Cake\Controller\Controller
;
use
Cake\Event\Event
;
use
Cake\I18n\I18n
;
use
Cake\Core\Configure
;
/**
* Application Controller
...
...
@@ -25,8 +29,15 @@ use Cake\Event\Event;
*
* @link https://book.cakephp.org/3.0/en/controllers.html#the-app-controller
*/
class
AppController
extends
Controller
{
class
AppController
extends
Controller
{
protected
$selectEmptyMsg
=
'---- please select ----'
;
/**
*
* @var redirect url when authorize to success
*/
protected
$_redirectApplicationURL
=
'http://commu-uat.connect.pakgon.com'
;
/**
* Initialization hook method.
...
...
@@ -37,8 +48,7 @@ class AppController extends Controller
*
* @return void
*/
public
function
initialize
()
{
public
function
initialize
()
{
parent
::
initialize
();
//$this->viewBuilder()->theme('Porto');
$this
->
loadComponent
(
'RequestHandler'
);
...
...
@@ -48,18 +58,56 @@ class AppController extends Controller
* Enable the following components for recommended CakePHP security settings.
* see https://book.cakephp.org/3.0/en/controllers/components/security.html
*/
$this
->
loadComponent
(
'Auth'
,
[
'loginRedirect'
=>
[
'controller'
=>
'Homes'
,
'action'
=>
'index'
],
'logoutRedirect'
=>
[
'controller'
=>
'Users'
,
'action'
=>
'signin'
],
'authenticate'
=>
[
'Form'
=>
[
'fields'
=>
[
'username'
=>
'username'
,
'password'
=>
'password'
],
'userModel'
=>
'Users'
]
],
'loginAction'
=>
[
'controller'
=>
'Users'
,
'action'
=>
'signin'
],
'authorize'
=>
[
'Controller'
],
'unauthorizedRedirect'
=>
$this
->
referer
()
// If unauthorized, return them to page they were just on
]);
//$this->loadComponent('Security');
//$this->loadComponent('Csrf');
}
/**
*
* Function trigger before filter process
* @author sarawutt.b
* @param Event $event
*/
public
function
beforeFilter
(
Event
$event
)
{
parent
::
beforeFilter
(
$event
);
/**
*
* Set appication language this can be thai|english
* @author Sarawutt.b
* @since 2018-02-28
* @return void
*/
if
(
$this
->
request
->
session
()
->
check
(
'SessionLanguage'
)
==
false
)
{
$this
->
request
->
session
()
->
write
(
'SessionLanguage'
,
'tha'
);
}
$this
->
Auth
->
allow
([
'signin'
,
'signout'
,
'signup'
,
'verify'
]);
}
/**
* Before render callback.
*
* @param \Cake\Event\Event $event The beforeRender event.
* @return \Cake\Http\Response|null|void
*/
public
function
beforeRender
(
Event
$event
)
{
public
function
beforeRender
(
Event
$event
)
{
//$this->viewBuilder()->theme('Gentelella');
//$this->viewBuilder()->theme('AdminLTE');
//$this->viewBuilder()->theme('Porto');
...
...
@@ -79,11 +127,124 @@ class AppController extends Controller
//$this->set('theme', Configure::read('Theme'));
}
function
checkToken
(){
/**
*
* Function check authorize
* @author sarawutt.b
* @param type $user
* @return boolean
*/
public
function
isAuthorized
(
$user
)
{
return
true
;
}
if
(
empty
(
$this
->
request
->
getHeaderLine
(
'Authorization'
))){
/**
*
* Function check fore token
* @return type
*/
function
checkToken
()
{
if
(
empty
(
$this
->
request
->
getHeaderLine
(
'Authorization'
)))
{
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'signin'
]);
}
}
/**
* Set language used this in mutiple language application concept
* @author Sarawutt.b
* @since 2016/03/21 10:23:33
* @return void
*/
public
function
_setLanguage
()
{
$this
->
L10n
=
new
L10n
();
$language
=
$this
->
request
->
session
()
->
read
(
'SessionLanguage'
);
Configure
::
write
(
'Config.language'
,
$language
);
$this
->
L10n
->
get
(
$language
);
}
/**
*
* Function get for current session user language
* @author sarawutt.b
* @return string
*/
public
function
getCurrentLanguage
()
{
return
$this
->
request
->
session
()
->
read
(
'SessionLanguage'
);
}
/**
*
* Function used fro generate _VERSION_
* @author sarawutt.b
* @return biginteger of the version number
*/
public
function
VERSION
()
{
$parts
=
explode
(
' '
,
microtime
());
$micro
=
$parts
[
0
]
*
1000000
;
return
(
substr
(
date
(
'YmdHis'
),
2
)
.
sprintf
(
"%06d"
,
$micro
));
}
/**
*
* Function used for generate UUID key patern
* @author sarawutt.b
* @return string uuid in version
*/
public
function
UUID
()
{
return
sprintf
(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x'
,
mt_rand
(
0
,
0xffff
),
mt_rand
(
0
,
0xffff
),
mt_rand
(
0
,
0xffff
),
mt_rand
(
0
,
0x0fff
)
|
0x4000
,
mt_rand
(
0
,
0x3fff
)
|
0x8000
,
mt_rand
(
0
,
0xffff
),
mt_rand
(
0
,
0xffff
),
mt_rand
(
0
,
0xffff
));
}
/**
*
* Function get for current session user authentication full name
* @author sarawutt.b
* @since 2018/02/06
* @return string of authentication user full name
*/
protected
function
getAuthFullname
()
{
return
$this
->
readAuth
(
'Auth.User.first_name'
)
.
' '
.
$this
->
readAuth
(
'Auth.User.last_name'
);
}
/**
*
* Function get for current session user authentication user id
* @author sarawutt.b
* @since 2018/02/06
* @return string of authentication user id
*/
protected
function
getAuthUserId
()
{
return
$this
->
readAuth
(
'Auth.User.id'
);
}
/**
*
* Function get for current session user authentication role id
* @author sarawutt.b
* @since 2018/02/06
* @return string of authentication user id
*/
protected
function
getAuthUserRoleId
()
{
return
$this
->
readAuth
(
'Auth.User.role_id'
);
}
/**
*
* Function get for current session with user authentication
* @author sarawutt.b
* @since 2018/02/06
* @return string of authentication session info
*/
protected
function
readAuth
(
$name
=
null
)
{
return
$this
->
request
->
session
()
->
read
(
$name
);
}
/**
* Function get for empty option in DDL
* @author sarawutt.b
* @return array() of empty select DDL
*/
public
function
getEmptySelect
()
{
return
[
''
=>
__
(
$this
->
selectEmptyMsg
)];
}
}
www/src/Controller/ProfilesController.php
View file @
83b770af
...
...
@@ -589,4 +589,5 @@ if (!empty($SubjectEnrolls)) {
$this
->
viewBuilder
()
->
layout
(
'blank'
);
}
}
www/src/Controller/UsersController.php
View file @
83b770af
...
...
@@ -10,48 +10,55 @@ use Cake\Mailer\Email;
use
Cake\Utility\Security
;
use
Cake\Auth\AbstractPasswordHasher
;
class
UsersController
extends
AppController
{
class
UsersController
extends
AppController
{
public
function
index
()
{
/**
*
* Function initialize make for automatically trigger when contructure
*/
public
function
initialize
()
{
parent
::
initialize
();
$this
->
Auth
->
allow
([
'signin'
,
'signout'
,
'signup'
,
'verify'
,
'forgotPassword'
]);
}
public
function
index
()
{
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'signin'
]);
}
public
function
signin
()
{
public
function
signin
()
{
$this
->
viewBuilder
()
->
layout
(
'blank'
);
}
#Signin
public
function
verify
()
{
$this
->
viewBuilder
()
->
layout
(
'blank'
);
$data
=
$this
->
request
->
data
();
#$data['data']['ip'] = $this->request->clientIp();
if
(
!
empty
(
$data
)){
if
(
!
empty
(
$data
[
'data'
][
'username'
])
&&
!
empty
(
$data
[
'data'
][
'password'
])){
$data
[
'data'
][
'ip'
]
=
$this
->
request
->
clientIp
();
#prr($data);
public
function
verify
()
{
$this
->
viewBuilder
()
->
layout
(
'blank'
);
if
(
$this
->
request
->
is
(
'post'
))
{
$data
=
$this
->
request
->
getData
();
if
(
!
empty
(
$data
))
{
$data
[
'data'
][
'ip'
]
=
$this
->
request
->
clientIp
();
$api_core_signin
=
Configure
::
read
(
'Config.apiCore.signin'
);
$http
=
new
Client
();
$response
=
$http
->
post
(
$api_core_signin
,
$data
[
'data'
])
->
body
();
$response
=
json_decode
(
$response
,
'_full'
);
#prd($response);
$response
=
$http
->
post
(
$api_core_signin
,
$data
[
'data'
])
->
body
();
$response
=
json_decode
(
$response
,
'_full'
);
if
(
!
empty
(
$response
))
{
if
(
strtolower
(
trim
(
$response
[
'status'
]))
==
'success'
)
{
$this
->
Auth
->
setUser
(
$response
[
'result'
]);
//$url = Router::url(['controller' => 'Homes', 'action' => 'index'], true);
// Before chan logic to OAUTH
// echo "<script>setTimeout(function(){Login.onLogin('" . $response['result']['token'] . "','" . $url . "','" . $response['result']['topic'] . "')},1000);</script>";
$statusCode
=
'200'
;
echo
"<script type='text/javascript'>setTimeout(function(){Login.onLogin('"
.
$statusCode
.
"','"
.
$this
->
_redirectApplicationURL
.
"','"
.
$response
[
'result'
][
'topic'
]
.
"')},1000);</script>"
;
if
(
!
empty
(
$response
)){
if
(
trim
(
$response
[
'status'
])
==
'Success'
){
$url
=
Router
::
url
([
'controller'
=>
'Homes'
,
'action'
=>
'index'
],
true
);
echo
"<script>setTimeout(function()
{
Login.onLogin('".$response['result']['token']."','".$url."','".$response['result']['topic']."')
}
,1000);</script>"
;
#echo "<script>setTimeout(function(){alert('".$response['result']['token']."')},1000);</script>";
#echo "<script>Login.onLogin('".$response['result']['token']."','".$url."','".$response['result']['topic']."');</script>";
#echo "<button onclick=Login.onLogin('".$response['result']['token']."','".$url."','".$response['result']['topic']."')>CLICK</button>";
#------------------------------------------------------------------
$param
=
[];
$param
[
'topic'
]
=
'/topics/'
.
$response
[
'result'
][
'topic'
];
$param
[
'topic'
]
=
'/topics/'
.
$response
[
'result'
][
'topic'
];
$param
[
'title'
]
=
''
;
$param
[
'message'
]
=
''
;
$param
[
'badge'
]
=
1
;
...
...
@@ -69,18 +76,18 @@ class UsersController extends AppController
#prr($response);
#------------------------------------------------------------------
//$this->redirect($this->_redirectApplicationURL);
header
(
'Location: '
.
$this
->
_redirectApplicationURL
);
die
;
}
else
{
}
else
{
$this
->
Flash
->
error
(
__
(
'Verify Fail'
));
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'signin'
]);
}
}
else
{
}
else
{
$this
->
Flash
->
error
(
__
(
'Verify Fail'
));
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'signin'
]);
}
}
else
{
}
else
{
$this
->
Flash
->
error
(
__
(
'Data Empty'
));
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'signin'
]);
}
...
...
@@ -182,10 +189,10 @@ class UsersController extends AppController
// pr($users);die;
//------------------------------ ส่งอีเมล์ -----------------------------------------------------
//
$data_notification = [];
//
$data_notification['email'] = $this->request->data['email'];
//
$data_notification['pin_code'] = $users['pin_code'];
//
$this->notification($data_notification);
$data_notification
=
[];
$data_notification
[
'email'
]
=
$this
->
request
->
data
[
'email'
];
$data_notification
[
'pin_code'
]
=
$users
[
'pin_code'
];
$this
->
notification
(
$data_notification
);
//----------------------------------------------------------------------------------------------
$this
->
Users
->
save
(
$users
);
$user_personals
[
'master_country_id'
]
=
$master_country_id
;
...
...
@@ -246,18 +253,16 @@ class UsersController extends AppController
#---------------------------------------------------------------------------------------------------
function
validateAccount
(
$data
=
null
)
{
function
validateAccount
(
$data
=
null
)
{
$error
=
[];
if
(
!
empty
(
$error
)){
$this
->
set
(
'error'
,
$error
);
if
(
!
empty
(
$error
))
{
$this
->
set
(
'error'
,
$error
);
return
false
;
}
else
{
}
else
{
return
true
;
}
}
// public function notification()
...
...
@@ -318,22 +323,23 @@ class UsersController extends AppController
// $pass[] = $alphabet[$n];
// }
// $password = implode($pass);
//--------------------ตัวส่ง Email --------------------------------------
//pr($user_personals);die;
// $data_notification = [];
// $data_notification['email'] = $this->request->data['email'];
// $data_notification['password'] = $password;
// $this->notification($data_notification);
//------------------------------------------------------------------------------------------
// $users['password'] = $hasher->hash($password);
$user_personals
=
$this
->
UserPersonals
->
find
(
'all'
,[
'conditions'
=>
[
'UserPersonals.email'
=>
$email
]
])
->
first
();
if
(
!
empty
(
$user_personals
)){
//--------------------ตัวส่ง Email ---------------------------------------------------------
// pr($user_personals);die;
// $data_notification = [];
// $data_notification['email'] = $this->request->data['email'];
// $data_notification['pin_code'] = $users['pin_pass'];
// $this->notification($data_notification);
//----------------------------------------------------------------------------------------
$users
=
$this
->
Users
->
find
(
'all'
,[
'conditions'
=>
[
'Users.id'
=>
$user_personals
[
'user_id'
]
...
...
@@ -342,10 +348,15 @@ class UsersController extends AppController
$digits
=
4
;
$users
[
'pin_pass'
]
=
str_pad
(
rand
(
0
,
pow
(
10
,
$digits
)
-
1
),
$digits
,
'0'
,
STR_PAD_LEFT
);
$token
=
$users
[
'token'
];
// pr($users);die;
// $users = $this->Users->patchEntity($users, $this->request->getData());
//--------------------ตัวส่ง Email ---------------------------------------------------------
//pr($user_personals);die;
$data_notification
=
[];
$data_notification
[
'email'
]
=
$this
->
request
->
data
[
'email'
];
$data_notification
[
'pin_code'
]
=
$users
[
'pin_pass'
];
$this
->
notification
(
$data_notification
);
//----------------------------------------------------------------------------------------
$this
->
Users
->
save
(
$users
);
// pr($users);die;
$this
->
Flash
->
success
(
__
(
'send password to email success'
));
return
$this
->
redirect
([
'action'
=>
'pinCodepassword/'
.
$token
]);
...
...
@@ -415,28 +426,7 @@ class UsersController extends AppController
}
public
function
getProvince
()
{
$this
->
autoRender
=
false
;
$this
->
loadModel
(
'MasterProvinces'
);
$states
=
array
();
$id
=
$this
->
request
->
data
(
'id'
);
$states
=
$this
->
MasterProvinces
->
find
(
'list'
,
array
(
'keyField'
=>
'id'
,
'valueField'
=>
'province_name_th'
,
'conditions'
=>
array
(
'master_country_id'
=>
$id
)
))
->
toArray
();
$arr
=
array
();
if
(
!
empty
(
$states
)){
echo
'<option value=""> ---Select--- </option>'
;
foreach
(
$states
as
$key
=>
$val
){
echo
'<option value="'
.
$key
.
'">'
.
$val
.
'</option>'
;
}
}
else
{
return
false
;
}
}
}
www/src/Template/Users/signin.ctp
View file @
83b770af
...
...
@@ -3,7 +3,8 @@
<?php echo $this->Html->image('../img/core/img/logo-connect-login@3x.png', ['alt' => 'Logo']); ?>
</div>
<div class="col-md-12">
<?php echo $this->Form->create(null, ['url' => ['controller' => 'Users', 'action' => 'verify'],
<?php
echo $this->Form->create(null, ['url' => ['controller' => 'Users', 'action' => 'verify'],
'id' => '', 'name' => 'Users', 'role' => 'form', 'onsubmit' => 'return validateForm()']);
?>
<?php echo $this->Flash->render() ?>
...
...
@@ -53,12 +54,11 @@
</label>
</div>
</div>
<?php echo $this->Form->end(); ?>
<?php echo $this->Form->end(); ?>
</div>
</div>
<!---------------------------------------------------------------------->
<script>
<script type="text/javascript">
function validateForm() {
var x = document.forms["Users"]["data[username]"].value;
if (x == null || x == "") {
...
...
@@ -72,7 +72,10 @@
}
}
</script>
<style>
<style type="text/css">
#alertBox {
position:relative;
width:300px;
...
...
@@ -179,7 +182,7 @@
}
</style>
<script>
<script
type="text/javascript"
>
var ALERT_TITLE = "";
var ALERT_BUTTON_TEXT = "Ok";
...
...
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