Commit 7785f907 by Prasong Putichanchai

update user

parent 2faaee2b
...@@ -53,7 +53,12 @@ class ProfilesController extends AppController ...@@ -53,7 +53,12 @@ class ProfilesController extends AppController
if(!empty($Province)) $Province = $Province->toArray(); if(!empty($Province)) $Province = $Province->toArray();
$res = $responseUserPersonal['birthdate']; $res = $responseUserPersonal['birthdate'];
$dateNow = $res->i18nFormat('dd/MM/yyyy'); if($res){
$dateNow = @$res->i18nFormat('dd/MM/yyyy');
}else{
$dateNow = "";
}
if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->is(['patch', 'post', 'put'])) {
$data = $this->request->data; $data = $this->request->data;
......
...@@ -18,7 +18,7 @@ class UsersController extends AppController { ...@@ -18,7 +18,7 @@ class UsersController extends AppController {
*/ */
public function initialize() { public function initialize() {
parent::initialize(); parent::initialize();
$this->Auth->allow(['signin', 'signout', 'signup', 'verify','forgotPassword','createAccount','pinCode','pinCodepassword']); $this->Auth->allow(['signin', 'signout', 'signup', 'verify','forgotPassword','createAccount','pinCode','pinCodepassword','changeForgotpassword']);
} }
public function index() { public function index() {
...@@ -117,12 +117,13 @@ class UsersController extends AppController { ...@@ -117,12 +117,13 @@ class UsersController extends AppController {
'keyField' => 'id', 'keyField' => 'id',
'valueField' => 'province_name_th' 'valueField' => 'province_name_th'
] ]
); );
if(!empty($provinces)) $provinces = $provinces->toArray(); if(!empty($provinces)) $provinces = $provinces->toArray();
$this->set(compact('provinces','countries')); $this->set(compact('provinces','countries'));
$this->viewBuilder()->layout('blank'); $this->viewBuilder()->layout('blank');
} }
#--------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------
#Signup #Signup
...@@ -382,7 +383,7 @@ class UsersController extends AppController { ...@@ -382,7 +383,7 @@ class UsersController extends AppController {
$data['pin_pass'] = $data['pin_code_1'].$data['pin_code_2'].$data['pin_code_3'].$data['pin_code_4']; $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']){ if($data['pin_pass']==$users['pin_pass']){
$this->Flash->success(__('Pin Completed.')); $this->Flash->success(__('Pin Completed.'));
return $this->redirect(['controller' => 'Users', 'action' => 'changePassword/'.$token]); return $this->redirect(['controller' => 'Users', 'action' => 'changeForgotpassword/'.$token]);
} }
$this->Flash->error(__('Pin Invalid')); $this->Flash->error(__('Pin Invalid'));
return $this->redirect(['controller' => 'Users', 'action' => 'pinCodepassword/'.$token]); return $this->redirect(['controller' => 'Users', 'action' => 'pinCodepassword/'.$token]);
...@@ -392,32 +393,37 @@ class UsersController extends AppController { ...@@ -392,32 +393,37 @@ class UsersController extends AppController {
public function changePassword($token=null) public function changePassword($token=null)
{ {
$id = $this->Auth->user('id');
$this->viewBuilder()->layout('blank'); $this->viewBuilder()->layout('blank');
$users = $this->Users->find('all',[ $users = $this->Users->get($id);
'conditions' => [
'Users.token' => $token
]
])->first();
if ($this->request->is('post')) { if ($this->request->is('post')) {
$hasher = new DefaultPasswordHasher(); $hasher = new DefaultPasswordHasher();
$password = $this->request->data['password']; $password = $this->request->data['password'];
$confirm_password = $this->request->data['confirm_password']; $confirm_password = $this->request->data['confirm_password'];
$oldpassword = $this->request->data['oldpassword'];
$this->request->data['password'] = $hasher->hash($this->request->data['password']); $this->request->data['password'] = $hasher->hash($this->request->data['password']);
//------- เทียบ password ที่เข้ารหัส ---------------password_verify($password,hashed_password)--------------------------- //------- เทียบ password ที่เข้ารหัส ---------------password_verify($password,hashed_password)---------------------------
if (password_verify($oldpassword, $users['password'])) { if (password_verify($oldpassword, $users['password'])) {
$users = $this->Users->patchEntity($users, $this->request->getData()); $users = $this->Users->patchEntity($users, $this->request->getData());
$this->Users->save($users); $this->Users->save($users);
$this->Flash->success(__('change password success')); $this->Flash->success(__('change password success'));
return $this->redirect(['action' => 'signin']);
$this->Flash->success(__('You are now logged out.'));
return $this->redirect(['action' => 'signout']);
} else { } else {
$this->Flash->error(__('Invalid password.')); $this->Flash->error(__('Invalid password.'));
return $this->redirect(['action' => 'change-password/'.$token]); return $this->redirect(['action' => 'change-password']);
} }
} }
$this->set(array('token' => $token, '_serialize' => array('token'))); $this->set(array('token' => $token, '_serialize' => array('token')));
} }
public function change_forgotpassword($token=null) public function changeForgotpassword($token=null)
{ {
$this->viewBuilder()->layout('blank'); $this->viewBuilder()->layout('blank');
$users = $this->Users->find('all',[ $users = $this->Users->find('all',[
...@@ -428,7 +434,7 @@ class UsersController extends AppController { ...@@ -428,7 +434,7 @@ class UsersController extends AppController {
if ($this->request->is('post')) { if ($this->request->is('post')) {
$hasher = new DefaultPasswordHasher(); $hasher = new DefaultPasswordHasher();
$password = $this->request->data['password']; $password = $this->request->data['password'];
$confirm_password = $this->request->data['confirm_password']; //$confirm_password = $this->request->data['confirm_password'];
$this->request->data['password'] = $hasher->hash($this->request->data['password']); $this->request->data['password'] = $hasher->hash($this->request->data['password']);
//------- เทียบ password ที่เข้ารหัส ---------------password_verify($password,hashed_password)--------------------------- //------- เทียบ password ที่เข้ารหัส ---------------password_verify($password,hashed_password)---------------------------
$users = $this->Users->patchEntity($users, $this->request->getData()); $users = $this->Users->patchEntity($users, $this->request->getData());
...@@ -442,11 +448,21 @@ class UsersController extends AppController { ...@@ -442,11 +448,21 @@ class UsersController extends AppController {
#--------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------
public function signout() /**
{ *
$this->checkToken(); * Function user logout / signout
* @author sarawutt.b
} * @since 2018/05/22 16:44:20
* @license PAKGON
* @return void
*/
public function signout() {
$http = new Client();
$result = $http->delete(Configure::read('OAUTH2_PROVIDER.TOKEN_DETETE') . '/' . $this->Auth->user('id'))->body();
$this->Flash->success(__('You are now logged out.'));
return $this->redirect($this->Auth->logout());
}
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<!-- <div class="alert alert-warning" role="alert" style="margin: 10px 0px 10px 0px;font-size: 17px;text-align: center;"> <!-- <div class="alert alert-warning" role="alert" style="margin: 10px 0px 10px 0px;font-size: 17px;text-align: center;">
<strong><?php echo __('กรุณา! ตรวจสอบอีเมลล์ของท่าน');?></strong> <strong><?php echo __('กรุณา! ตรวจสอบอีเมลล์ของท่าน');?></strong>
</div>--> </div>-->
<?php echo $this->Form->create(null, ['url' => ['controller' => 'Users','action' => 'changePassword/'.$token],'class' => 'form-horizontal','id' => '','name' => 'changeForgotpassword','role' => 'form', 'onsubmit' => 'return validateForm()']);?> <?php echo $this->Form->create(null, ['url' => ['controller' => 'Users','action' => 'changeForgotpassword/'.$token],'class' => 'form-horizontal','id' => '','name' => 'changeForgotpassword','role' => 'form', 'onsubmit' => 'return validateForm()']);?>
<?php echo $this->Flash->render(); ?> <?php echo $this->Flash->render(); ?>
</div> </div>
<div> <div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment