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
d39b375e
authored
May 30, 2018
by
Prasong Putichanchai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
f7e7521f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
99 deletions
+98
-99
www/src/Controller/UsersController.php
+89
-91
www/src/Template/Users/signin.ctp
+4
-3
www/src/Template/Users/verify.ctp
+5
-5
No files found.
www/src/Controller/UsersController.php
View file @
d39b375e
<?php
namespace
App\Controller
;
use
App\Controller\AppController
;
use
Cake\Auth\DefaultPasswordHasher
;
use
Cake\Core\Configure
;
...
...
@@ -18,13 +20,21 @@ class UsersController extends AppController {
*/
public
function
initialize
()
{
parent
::
initialize
();
$this
->
Auth
->
allow
([
'signin'
,
'signout'
,
'signup'
,
'verify'
,
'forgotPassword'
,
'createAccount'
,
'pinCode'
,
'pinCodepassword'
,
'changeForgotpassword'
]);
$this
->
Auth
->
allow
([
'signin'
,
'signout'
,
'signup'
,
'verify'
,
'forgotPassword'
,
'createAccount'
,
'pinCode'
,
'pinCodepassword'
,
'changeForgotpassword'
]);
}
public
function
index
()
{
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'signin'
]);
}
/**
*
* Function signin / login make for user authentication
* @author sarawutt.b
* @since 20108/05/24 10:49:20
* @license Pakgon
* @return void
*/
public
function
signin
()
{
$this
->
viewBuilder
()
->
layout
(
'blank'
);
}
...
...
@@ -50,14 +60,12 @@ class UsersController extends AppController {
//$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>";
$redirectApplicationURL
=
Configure
::
read
(
'RedirectApplicationURL'
);
$RedirectApplicationURL
=
Configure
::
read
(
'RedirectApplicationURL'
);
$topic
=
$response
[
'result'
][
'topic'
];
$this
->
set
(
compact
(
'statusCode'
,
'redirectApplicationURL'
,
'topic'
));
$token
=
$response
[
'result'
][
'token'
];
$this
->
set
(
compact
(
'statusCode'
,
'RedirectApplicationURL'
,
'topic'
,
'token'
));
#echo "<script>setTimeout(function(){alert('".$response['result']['token']."')},1000);</script>";
#echo "<script>Login.onLogin('".$response['result']['token']."','".$url."','".$response['result']['topic']."');</script>";
...
...
@@ -82,6 +90,7 @@ class UsersController extends AppController {
#------------------------------------------------------------------
//$this->redirect($this->_redirectApplicationURL);
//header('Location: ' . $this->_redirectApplicationURL);
//return $this->redirect($redirectApplicationURL);
}
else
{
$this
->
Flash
->
error
(
__
(
'Verify Fail'
));
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'signin'
]);
...
...
@@ -97,38 +106,44 @@ class UsersController extends AppController {
}
}
public
function
signup
()
{
public
function
signup
()
{
$this
->
loadModel
(
'MasterCountries'
);
$this
->
loadModel
(
'MasterProvinces'
);
$countries
=
$this
->
MasterCountries
->
find
(
'list'
,
[
$countries
=
$this
->
MasterCountries
->
find
(
'list'
,
[
'conditions'
=>
[
'is_used'
=>
true
],
'keyField'
=>
'id'
,
'valueField'
=>
[
'country_name_th'
]
]
);
if
(
!
empty
(
$countries
))
$countries
=
$countries
->
toArray
();
$provinces
=
$this
->
MasterProvinces
->
find
(
'list'
,
[
)
->
order
([
'country_name_th'
=>
'ASC'
,
]);
if
(
!
empty
(
$countries
))
$countries
=
$countries
->
toArray
();
$provinces
=
$this
->
MasterProvinces
->
find
(
'list'
,
[
'conditions'
=>
[
'is_used'
=>
true
],
'keyField'
=>
'id'
,
'valueField'
=>
'province_name_th'
]
);
if
(
!
empty
(
$provinces
))
$provinces
=
$provinces
->
toArray
();
$this
->
set
(
compact
(
'provinces'
,
'countries'
));
)
->
order
([
'province_name_th'
=>
'DESC'
,
]);
if
(
!
empty
(
$provinces
))
$provinces
=
$provinces
->
toArray
();
$this
->
set
(
compact
(
'provinces'
,
'countries'
));
$this
->
viewBuilder
()
->
layout
(
'blank'
);
}
#---------------------------------------------------------------------------------------------------
#Signup
public
function
createAccount
()
{
public
function
createAccount
()
{
$this
->
loadModel
(
'UserPersonals'
);
$users
=
$this
->
Users
->
newEntity
();
...
...
@@ -150,11 +165,11 @@ class UsersController extends AppController {
$confirm_password
=
$this
->
request
->
data
[
'confirm_password'
];
$btn
=
$this
->
request
->
data
[
'btn'
];
if
(
!
empty
(
$this
->
request
->
data
[
'birthdate'
]))
{
if
(
!
empty
(
$this
->
request
->
data
[
'birthdate'
]))
{
$birthdate
=
explode
(
"/"
,
$this
->
request
->
data
[
'birthdate'
]);
$birthdate
=
$birthdate
[
2
]
.
'-'
.
$birthdate
[
1
]
.
'-'
.
$birthdate
[
0
];
$birthdate
=
$birthdate
[
2
]
.
'-'
.
$birthdate
[
1
]
.
'-'
.
$birthdate
[
0
];
$this
->
request
->
data
[
'birthdate'
]
=
$birthdate
;
}
else
{
}
else
{
$birthdate
=
'2000-10-10'
;
}
...
...
@@ -165,31 +180,30 @@ class UsersController extends AppController {
$users
[
'dynamic_key'
]
=
'dynamic_key'
;
// $users['point'] = 0;
$users
[
'dynamic_key_expiry'
]
=
date
(
'Y-m-d'
,
strtotime
(
'+3 day'
));
$users
[
'token'
]
=
Security
::
hash
(
$this
->
request
->
data
[
'username'
]
.
date
(
'Y-m-d h:i:s'
),
'md5'
,
true
);
$users
[
'token_expiry'
]
=
date
(
'Y-m-d'
,
strtotime
(
'+3 day'
));
$users
[
'dynamic_key_expiry'
]
=
date
(
'Y-m-d'
,
strtotime
(
'+3 day'
));
$users
[
'token'
]
=
Security
::
hash
(
$this
->
request
->
data
[
'username'
]
.
date
(
'Y-m-d h:i:s'
),
'md5'
,
true
);
$users
[
'token_expiry'
]
=
date
(
'Y-m-d'
,
strtotime
(
'+3 day'
));
// $users['modified_by'] = $modified_by;
$digits
=
4
;
$users
[
'pin_code'
]
=
str_pad
(
rand
(
0
,
pow
(
10
,
$digits
)
-
1
),
$digits
,
'0'
,
STR_PAD_LEFT
);
$users
[
'pin_code'
]
=
str_pad
(
rand
(
0
,
pow
(
10
,
$digits
)
-
1
),
$digits
,
'0'
,
STR_PAD_LEFT
);
if
(
!
empty
(
$this
->
request
->
data
[
'accept'
]))
{
if
(
!
empty
(
$this
->
request
->
data
[
'accept'
]))
{
$username_check
=
$this
->
Users
->
find
(
'all'
,
[
$username_check
=
$this
->
Users
->
find
(
'all'
,
[
'conditions'
=>
[
'Users.username'
=>
$this
->
request
->
data
[
'username'
]
]
])
->
toArray
();
$email_check
=
$this
->
UserPersonals
->
find
(
'all'
,
[
$email_check
=
$this
->
UserPersonals
->
find
(
'all'
,
[
'conditions'
=>
[
'UserPersonals.email'
=>
$this
->
request
->
data
[
'email'
]
]
])
->
toArray
();
if
((
empty
(
$username_check
))
&&
(
empty
(
$email_check
)))
{
if
((
empty
(
$username_check
))
&&
(
empty
(
$email_check
)))
{
$users
=
$this
->
Users
->
patchEntity
(
$users
,
$this
->
request
->
getData
());
// pr($users);die;
//------------------------------ ส่งอีเมล์ -----------------------------------------------------
$data_notification
=
[];
$data_notification
[
'email'
]
=
$this
->
request
->
data
[
'email'
];
...
...
@@ -208,12 +222,12 @@ class UsersController extends AppController {
$this
->
UserPersonals
->
save
(
$user_personals
);
// $this->Flash->success(__('The register success.'));
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'pinCode/'
.
$users
[
'token'
]]);
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'pinCode/'
.
$users
[
'token'
]]);
// return $this->redirect(['action' => 'signin']);
}
$this
->
Flash
->
error
(
__
(
'Username or Email Address already used by others.'
));
return
$this
->
redirect
([
'action'
=>
'signup'
]);
}
else
if
(
empty
(
$this
->
request
->
data
[
'accept'
]))
{
}
else
if
(
empty
(
$this
->
request
->
data
[
'accept'
]))
{
$this
->
Flash
->
error
(
__
(
'please accept'
));
return
$this
->
redirect
([
'action'
=>
'signup'
]);
}
...
...
@@ -221,10 +235,8 @@ class UsersController extends AppController {
}
}
public
function
notification
(
$data
=
null
)
{
if
(
!
empty
(
$data
)){
public
function
notification
(
$data
=
null
)
{
if
(
!
empty
(
$data
))
{
$verify_code
=
$data
[
'pin_code'
];
$from_email
=
[
'support@pakgon.com'
=>
'Support'
];
$to_emails
=
[
$data
[
'email'
]];
...
...
@@ -241,16 +253,13 @@ class UsersController extends AppController {
$email
->
viewVars
(
compact
(
'verify_code'
));
#$email->send($message);
$email
->
send
();
}
catch
(
Exception
$e
)
{
echo
'Exception : '
,
$e
->
getMessage
(),
"
\n
"
;
}
#$this->httpStatusCode = 200;
#$this->apiResponse['message'] = 'Signup Connect Completed!!';
}
}
#---------------------------------------------------------------------------------------------------
...
...
@@ -271,109 +280,102 @@ class UsersController extends AppController {
// {
// $this->viewBuilder()->layout('blank');
// }
#Verify Pin Code
public
function
pinCode
(
$token
=
null
)
{
public
function
pinCode
(
$token
=
null
)
{
$this
->
viewBuilder
()
->
layout
(
'blank'
);
$data
=
$this
->
request
->
data
();
if
(
!
empty
(
$data
))
{
if
(
!
empty
(
$data
))
{
$api_core_verify_pin_code
=
Configure
::
read
(
'Config.apiCore.verifyPinCode'
);
$http
=
new
Client
();
#$response = json_decode($http->post($api_core_verify_pin_code,$data)->body(),'_full');
$response
=
$http
->
post
(
$api_core_verify_pin_code
,
$data
)
->
body
();
$response
=
json_decode
(
$response
,
'_full'
);
$response
=
$http
->
post
(
$api_core_verify_pin_code
,
$data
)
->
body
();
$response
=
json_decode
(
$response
,
'_full'
);
if
(
!
empty
(
$response
))
{
if
(
trim
(
$response
[
'status'
])
==
'Success'
){
if
(
!
empty
(
$response
))
{
if
(
trim
(
$response
[
'status'
])
==
'Success'
)
{
$this
->
Flash
->
success
(
__
(
'Verify Completed.'
));
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'signin'
]);
}
else
{
}
else
{
$this
->
Flash
->
error
(
__
(
'Pin Code Invalid'
));
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'pinCode/'
.
$token
]);
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'pinCode/'
.
$token
]);
}
}
}
$this
->
set
(
array
(
'token'
=>
$token
,
'_serialize'
=>
array
(
'token'
)));
}
#---------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
public
function
forgotPassword
()
{
/**
*
* Function user forgot password
* @return void
*/
public
function
forgotPassword
()
{
$this
->
viewBuilder
()
->
layout
(
'blank'
);
$this
->
loadModel
(
'UserPersonals'
);
if
(
$this
->
request
->
is
(
'post'
))
{
$hasher
=
new
DefaultPasswordHasher
();
$email
=
$this
->
request
->
data
[
'email'
];
$user_personals
=
$this
->
UserPersonals
->
find
(
'all'
,
[
$user_personals
=
$this
->
UserPersonals
->
find
(
'all'
,
[
'conditions'
=>
[
'UserPersonals.email'
=>
$email
]
])
->
first
();
if
(
!
empty
(
$user_personals
))
{
if
(
!
empty
(
$user_personals
))
{
$users
=
$this
->
Users
->
find
(
'all'
,
[
$users
=
$this
->
Users
->
find
(
'all'
,
[
'conditions'
=>
[
'Users.id'
=>
$user_personals
[
'user_id'
]
]
])
->
first
();
$digits
=
4
;
$users
[
'pin_pass'
]
=
str_pad
(
rand
(
0
,
pow
(
10
,
$digits
)
-
1
),
$digits
,
'0'
,
STR_PAD_LEFT
);
$users
[
'pin_pass'
]
=
str_pad
(
rand
(
0
,
pow
(
10
,
$digits
)
-
1
),
$digits
,
'0'
,
STR_PAD_LEFT
);
$token
=
$users
[
'token'
];
//--------------------ตัวส่ง Email ---------------------------------------------------------
//pr($user_personals);die;
$data_notification
=
[];
$data_notification
[
'email'
]
=
$this
->
request
->
data
[
'email'
];
$data_notification
[
'pin_code'
]
=
$users
[
'pin_pass'
]
.
'<br>'
.
" Username: "
.
$users
[
'username
'
];
$data_notification
[
'pin_code'
]
=
$users
[
'pin_pass
'
];
$this
->
notification
(
$data_notification
);
//----------------------------------------------------------------------------------------
$this
->
Users
->
save
(
$users
);
$this
->
Flash
->
success
(
__
(
'send password to email success'
));
return
$this
->
redirect
([
'action'
=>
'pinCodepassword/'
.
$token
]);
}
else
{
return
$this
->
redirect
([
'action'
=>
'pinCodepassword/'
.
$token
]);
}
else
{
$this
->
Flash
->
error
(
__
(
'Invalid Email.'
));
return
$this
->
redirect
([
'action'
=>
'forgot-password'
]);
}
}
}
public
function
pinCodepassword
(
$token
=
null
)
{
public
function
pinCodepassword
(
$token
=
null
)
{
$this
->
viewBuilder
()
->
layout
(
'blank'
);
$users
=
$this
->
Users
->
find
(
'all'
,
[
'conditions'
=>
[
'Users.token'
=>
$token
$users
=
$this
->
Users
->
find
(
'all'
,
[
'conditions'
=>
[
'Users.token'
=>
$token
]
])
->
first
();
if
(
$this
->
request
->
is
(
'post'
))
{
if
(
$this
->
request
->
is
(
'post'
))
{
$data
=
$this
->
request
->
data
();
$data
[
'pin_pass'
]
=
$data
[
'pin_code_1'
]
.
$data
[
'pin_code_2'
]
.
$data
[
'pin_code_3'
]
.
$data
[
'pin_code_4'
];
if
(
$data
[
'pin_pass'
]
==
$users
[
'pin_pass'
])
{
$data
[
'pin_pass'
]
=
$data
[
'pin_code_1'
]
.
$data
[
'pin_code_2'
]
.
$data
[
'pin_code_3'
]
.
$data
[
'pin_code_4'
];
if
(
$data
[
'pin_pass'
]
==
$users
[
'pin_pass'
])
{
$this
->
Flash
->
success
(
__
(
'Pin Completed.'
));
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'changeForgotpassword/'
.
$token
]);
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'changeForgotpassword/'
.
$token
]);
}
$this
->
Flash
->
error
(
__
(
'Pin Invalid'
));
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'pinCodepassword/'
.
$token
]);
return
$this
->
redirect
([
'controller'
=>
'Users'
,
'action'
=>
'pinCodepassword/'
.
$token
]);
}
$this
->
set
(
array
(
'token'
=>
$token
,
'_serialize'
=>
array
(
'token'
)));
}
public
function
changePassword
()
{
public
function
changePassword
(
$token
=
null
)
{
$id
=
$this
->
Auth
->
user
(
'id'
);
$this
->
viewBuilder
()
->
layout
(
'blank'
);
...
...
@@ -387,23 +389,25 @@ class UsersController extends AppController {
$this
->
request
->
data
[
'password'
]
=
$hasher
->
hash
(
$this
->
request
->
data
[
'password'
]);
//------- เทียบ password ที่เข้ารหัส ---------------password_verify($password,hashed_password)---------------------------
if
(
password_verify
(
$oldpassword
,
$users
[
'password'
]))
{
$users
=
$this
->
Users
->
patchEntity
(
$users
,
$this
->
request
->
getData
());
$this
->
Users
->
save
(
$users
);
$this
->
Flash
->
success
(
__
(
'change password success'
));
$this
->
Flash
->
success
(
__
(
'You are now logged out.'
));
return
$this
->
redirect
([
'action'
=>
'signout'
]);
}
else
{
$this
->
Flash
->
error
(
__
(
'Invalid password.'
));
return
$this
->
redirect
([
'action'
=>
'change-password'
]);
}
}
$this
->
set
(
array
(
'token'
=>
$token
,
'_serialize'
=>
array
(
'token'
)));
}
public
function
changeForgotpassword
(
$token
=
null
)
{
public
function
changeForgotpassword
(
$token
=
null
)
{
$this
->
viewBuilder
()
->
layout
(
'blank'
);
$users
=
$this
->
Users
->
find
(
'all'
,
[
$users
=
$this
->
Users
->
find
(
'all'
,
[
'conditions'
=>
[
'Users.token'
=>
$token
]
...
...
@@ -415,9 +419,8 @@ class UsersController extends AppController {
$this
->
request
->
data
[
'password'
]
=
$hasher
->
hash
(
$this
->
request
->
data
[
'password'
]);
//------- เทียบ password ที่เข้ารหัส ---------------password_verify($password,hashed_password)---------------------------
$users
=
$this
->
Users
->
patchEntity
(
$users
,
$this
->
request
->
getData
());
if
(
$this
->
Users
->
save
(
$users
))
{
if
(
$this
->
Users
->
save
(
$users
))
{
$this
->
Flash
->
success
(
__
(
'change password success'
));
$this
->
Flash
->
success
(
__
(
'You are now logout'
));
return
$this
->
redirect
([
'action'
=>
'signin'
]);
}
$this
->
Flash
->
error
(
__
(
'Invalid password.'
));
...
...
@@ -426,7 +429,6 @@ class UsersController extends AppController {
$this
->
set
(
array
(
'token'
=>
$token
,
'_serialize'
=>
array
(
'token'
)));
}
#---------------------------------------------------------------------------------------------------
/**
...
...
@@ -444,8 +446,4 @@ class UsersController extends AppController {
return
$this
->
redirect
(
$this
->
Auth
->
logout
());
}
}
www/src/Template/Users/signin.ctp
View file @
d39b375e
<?php $this->layout = 'login'; ?>
<div>
<div class="center" style="padding-bottom: 40px;">
<?php echo $this->Html->image('../img/core/img/logo-connect-login@3x.png', ['alt' => 'Logo']); ?>
...
...
@@ -5,7 +6,7 @@
<div class="col-md-12">
<?php
echo $this->Form->create(null, ['url' => ['controller' => 'Users', 'action' => 'verify'],
'id' =>
''
, 'name' => 'Users', 'role' => 'form', 'onsubmit' => 'return validateForm()']);
'id' =>
false
, 'name' => 'Users', 'role' => 'form', 'onsubmit' => 'return validateForm()']);
?>
<?php echo $this->Flash->render() ?>
<div class="row">
...
...
@@ -15,7 +16,7 @@
<div class="input-group-addon">
<span class="glyphicon glyphicon-user"></span>
</div>
<input type="text" name="data[username]" value="" placeholder="USERNAME" class="form-control input-lg input-border-radius color-button-border"
id="FALSE"
style="padding-left: 42px;">
<input type="text" name="data[username]" value="" placeholder="USERNAME" class="form-control input-lg input-border-radius color-button-border" style="padding-left: 42px;">
</div>
</div>
</div>
...
...
@@ -27,7 +28,7 @@
<div class="input-group-addon">
<span class="glyphicon glyphicon-lock"></span>
</div>
<input data-toggle="password" data-placement="before" type="password" name="data[password]" value="" placeholder="********" class="form-control input-lg input-border-radius color-button-border"
id="FALSE"
style="padding-left: 42px;">
<input data-toggle="password" data-placement="before" type="password" name="data[password]" value="" placeholder="********" class="form-control input-lg input-border-radius color-button-border" style="padding-left: 42px;">
</div>
</div>
</div>
...
...
www/src/Template/Users/verify.ctp
View file @
d39b375e
<script type='text/javascript'>
setTimeout(function(){
setTimeout(function () {
if (typeof Login == 'undefined') {
location = '<?php echo $paramOptions['url']['url']
; ?>';
location = '<?php echo $RedirectApplicationURL
; ?>';
} else {
Login.onLogin('<?php echo json_encode($paramOptions['url']); ?>','<?php echo json_encode($paramOptions['token']); ?>','<?php $paramOptions['topic']
; ?>');
Login.onLogin('<?php echo $token; ?>', '<?php echo $RedirectApplicationURL; ?>', '<?php echo $topic
; ?>');
}
}, 1000);
}, 1000);
</script>;
\ No newline at end of file
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