Commit dfd654f4 by Prasong Putichanchai

Merge branch 'integration' into prasong

# Conflicts:
#	www/src/Controller/UsersController.php
parents d39b375e fe787816
......@@ -105,6 +105,8 @@ class ProfilesController extends AppController
$userPersonals = $this->UserPersonals->patchEntity($userPersonals, $data['UserPersonals']);
$userPersonals['firstname_th'] = $this->request->data['UserPersonals']['firstname_th'];
$userPersonals['lastname_th'] = $this->request->data['UserPersonals']['lastname_th'];
$userPersonals['firstname_en'] = $this->request->data['UserPersonals']['firstname_th'];
$userPersonals['lastname_en'] = $this->request->data['UserPersonals']['lastname_th'];
$userPersonals['email'] = $this->request->data['email'];
$userPersonals['birthdate'] = $birthdate;
$userPersonals['user_id'] = $data['Users']['user_id'];
......
......@@ -306,11 +306,11 @@ class UserCardsController extends AppController
return $this->redirect(['controller' => 'Profiles', 'action' => 'index']);
}
}else{
$this->Flash->success(__('ลงทะเบียนไว้อยู่แล้ว'));
$this->Flash->error(__('ลงทะเบียนไว้อยู่แล้ว'));
return $this->redirect(['controller' => 'UserCards', 'action' => 'viewCard']);
}
}else{
$this->Flash->success(__('ไม่พบข้อมูล'));
$this->Flash->error(__('ไม่พบข้อมูล'));
return $this->redirect(['controller' => 'UserCards', 'action' => 'viewCard']);
}
}
......
......@@ -20,7 +20,11 @@ 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']);
$this->Auth->allow(['signin', 'signout', 'signup', 'verify','forgotPassword','createAccount','pinCode','pinCodepassword','registersendpin','forgotsendpin','changeForgotpassword']);
}
public function index() {
......@@ -354,13 +358,87 @@ class UsersController extends AppController {
}
}
public function pinCodepassword($token = null) {
// public function pinCodepassword($token = null) {
// $this->viewBuilder()->layout('blank');
// $users = $this->Users->find('all', [
// 'conditions' => [
// 'Users.token' => $token
// ]
// ])->first();
public function pinCodepassword($token=null)
{
$this->viewBuilder()->layout('blank');
$users = $this->Users->find('all', [
$users = $this->Users->find('all',[
'conditions'=>[
'Users.token'=>$token
]
])->first();
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']){
$this->Flash->success(__('Pin Completed.'));
return $this->redirect(['controller' => 'Users', 'action' => 'changeForgotpassword/'.$token]);
}
$this->Flash->error(__('Pin Invalid'));
return $this->redirect(['controller' => 'Users', 'action' => 'pinCodepassword/'.$token]);
}
$this->set(array('token' => $token, '_serialize' => array('token')));
}
public function changePassword()
{
$id = $this->Auth->user('id');
$this->viewBuilder()->layout('blank');
$users = $this->Users->get($id);
if ($this->request->is('post')) {
$hasher = new DefaultPasswordHasher();
$password = $this->request->data['password'];
$confirm_password = $this->request->data['confirm_password'];
$oldpassword = $this->request->data['oldpassword'];
$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(__('You are now logged out.'));
return $this->redirect(['action' => 'signout']);
} else {
$this->Flash->error(__('Invalid password.'));
return $this->redirect(['action' => 'change-password']);
}
}
}
public function changeForgotpassword($token=null)
{
$this->viewBuilder()->layout('blank');
$users = $this->Users->find('all',[
'conditions' => [
'Users.token' => $token
]
])->first();
if ($this->request->is('post')) {
$hasher = new DefaultPasswordHasher();
$password = $this->request->data['password'];
$confirm_password = $this->request->data['confirm_password'];
$this->request->data['password'] = $hasher->hash($this->request->data['password']);
//------- เทียบ password ที่เข้ารหัส ---------------password_verify($password,hashed_password)---------------------------
$users = $this->Users->patchEntity($users, $this->request->getData());
$this->Users->save($users);
$this->Flash->success(__('You are now logged out.'));
return $this->redirect(['action' => 'signin']);
}
$this->set(array('token' => $token, '_serialize' => array('token')));
}
if ($this->request->is('post')) {
$data = $this->request->data();
......@@ -446,4 +524,66 @@ class UsersController extends AppController {
return $this->redirect($this->Auth->logout());
}
public function forgotsendpin($token=null) {
$this->loadModel('UserPersonals');
$users = $this->Users->find('all',[
'conditions'=>[
'Users.token'=>$token
]
])->first();
$digits = 4;
$users['pin_pass'] = str_pad(rand(0, pow(10, $digits)-1), $digits, '0', STR_PAD_LEFT);
$user_personals = $this->UserPersonals->find('all',[
'conditions'=>[
'UserPersonals.user_id'=>$users['id']
]
])->first();
//--------------------ตัวส่ง Email ---------------------------------------------------------
//pr($user_personals);die;
$data_notification = [];
$data_notification['email'] = $user_personals['email'];
$data_notification['pin_code'] = $users['pin_pass'].'<br>'." Username: ".$users['username'];
$this->notification($data_notification);
//----------------------------------------------------------------------------------------
if($this->Users->save($users)){
$this->Flash->success(__('send pin success.'));
return $this->redirect(['action' => 'pin_codepassword/'.$token]);
}
$this->Flash->success(__('send pin false.'));
return $this->redirect(['action' => 'pin_codepassword/'.$token]);
}
public function registersendpin($token=null) {
$this->loadModel('UserPersonals');
$users = $this->Users->find('all',[
'conditions'=>[
'Users.token'=>$token
]
])->first();
$digits = 4;
$users['pin_pass'] = str_pad(rand(0, pow(10, $digits)-1), $digits, '0', STR_PAD_LEFT);
$user_personals = $this->UserPersonals->find('all',[
'conditions'=>[
'UserPersonals.user_id'=>$users['id']
]
])->first();
//--------------------ตัวส่ง Email ---------------------------------------------------------
//pr($user_personals);die;
$data_notification = [];
$data_notification['email'] = $user_personals['email'];
$data_notification['pin_code'] = $users['pin_pass'].'<br>'." Username: ".$users['username'];
$this->notification($data_notification);
//----------------------------------------------------------------------------------------
if($this->Users->save($users)){
$this->Flash->success(__('send pin success.'));
return $this->redirect(['action' => 'pin_code/'.$token]);
}
$this->Flash->success(__('send pin false.'));
return $this->redirect(['action' => 'pin_code/'.$token]);
}
}
......@@ -48,12 +48,18 @@
<div style="clear: both"></div>
</div><!--/row-->
<br><br>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<?php echo $this->Form->create('UserProfiles', ['id' => 'frmSignIn', 'type' => 'file','name' => 'frmSignIn','role' => 'form', 'onsubmit' => 'return validateForm()']); ?>
<?php echo $this->Flash->render() ?>
<div class="form-group has-feedback">
<div class="col-xs-12 col-sm-12 col-md-12">
<h3> <?php echo __('ข้อมูลสมาชิก');?></h3>
</div>
</div>
<div class="form-group has-feedback">
<div class="col-xs-12 col-sm-12 col-md-12">
<?php echo $this->Form->hidden('Users.user_id', ['class' => 'form-control-reg border-bottom-from label-text-sub', 'value' => $responseUserProfile['id'], 'id' => 'userId', 'type' => 'text', 'label' => __('ชื่อผู้ใช้งาน'), 'placeholder' => 'USERNAME']); ?>
<?php echo $this->Form->input('Users.username', ['class' => 'form-control-reg border-bottom-from label-text-sub', 'value' => $username, 'id' => 'username', 'type' => 'text', 'label' => __('ชื่อผู้ใช้งาน'), 'placeholder' => 'USERNAME', 'readonly']); ?>
<?php // echo $this->Form->input('user_id', ['class' => 'form-control-reg border-bottom-from label-text-sub', 'value' => $userProfile->username, 'id' => 'userId', 'type' => 'text', 'label' => __('ชื่อผู้ใช้งาน'), 'placeholder' => 'USERNAME']); ?>
......@@ -117,14 +123,14 @@
</div>
<div class="form-group has-feedback">
<div class="col-xs-12 col-sm-12 col-md-12">
<?php echo __('เบอร์โทรศัพท์');?><em>* </em>
<?php echo $this->Form->input('UserPersonals.moblie_no', ['class' => 'form-control-reg border-bottom-from label-text-sub', 'value' => $responseUserPersonal['moblie_no'], 'id' => 'moblieNo', 'type' => 'text', 'label' => false, 'placeholder' => '000-000-0000']); ?>
<?php echo __('เบอร์โทรศัพท์(มือถือ)');?><em>* </em>
<?php echo $this->Form->input('UserPersonals.moblie_no', ['class' => 'form-control-reg border-bottom-from label-text-sub', 'value' => $responseUserPersonal['moblie_no'], 'id' => 'moblieNo', 'type' => 'text', 'label' => false, 'maxlength' => '10', 'placeholder' => 'หมายเลขโทรศัพท์(มือถือ)']); ?>
<?php // echo $this->Form->input('moblie_no', ['class' => 'form-control-reg border-bottom-from label-text-sub', 'value' => $userProfiles->moblie_no, 'id' => 'moblieNo', 'type' => 'text', 'label' => __('เบอร์โทรศัพท์'), 'placeholder' => '000-000-0000']); ?>
</div>
</div>
<div class="form-group has-feedback">
<div class="col-xs-12 col-sm-12 col-md-12">
<?php echo __('อีเมลล์');?><em>* </em>
<?php echo __('อีเมล');?><em>* </em>
<!-- <?php echo $this->Form->input('UserPersonals.email', ['class' => 'form-control-reg border-bottom-from label-text-sub', 'value' => $responseUserPersonal['email'], 'id' => 'email', 'label' => false, 'placeholder' => 'mail@xxx.com']); ?> -->
<?php // echo $this->Form->input('email', ['class' => 'form-control-reg border-bottom-from label-text-sub', 'value' => $userProfiles->email, 'id' => 'email', 'type' => 'email', 'label' => __('Email'), 'placeholder' => 'mail@xxx.com']); ?>
<input type="text" name="email" id="email" value="<?php echo $responseUserPersonal['email'] ?>" placeholder="mail@xxx.com" class="form-control-reg border-bottom-from">
......@@ -222,12 +228,21 @@
// console.log(data);
data = jQuery.parseJSON(data);
if(data['chk'] == 'false'){
alert("อีเมลล์นี้มีในระบบแล้ว");
alert("อีเมลนี้มีในระบบแล้ว");
return false;
}
});
});
$("#moblieNo").on('change',function(){
var elem = document.getElementById('moblieNo').value;
// console.log(elem);
if(!elem.match(/^([A-Za-zก-๙])+$/i)){
alert("กรอกเฉพาะตัวเลข");
return false;
}
})
});
function validateForm() {
var firstname_th = document.getElementById("firstname_th").value;
if (firstname_th == null || firstname_th == "") {
......@@ -251,7 +266,7 @@
alert("กรุณากรอก เบอร์โทรศัพท์ของท่าน");
return false;
}
if(document.getElementById("moblieNo").value.length != 12)
if(document.getElementById("moblieNo").value.length != 10)
{
alert('กรุณากรอกเบอร์โทรศัพท์ ให้ครบ 10 หลัก');
return false;
......@@ -461,8 +476,6 @@
<?php $this->append('scriptBottom'); ?>
<script type="text/javascript">
$(function () {
$('#moblieNo').inputmask('999-999-9999');
$('#officePhone').inputmask('99-999-9999');
//==================================================
// CHANGE Date Times
//==================================================
......
......@@ -141,11 +141,13 @@ use Cake\I18n\Time;
<img src="/img/core/img/bloc-plus@3x.png" class="img-responsive" style="width: 100%">
</div>
<div class="col-xs-1 col-sm-1 col-md-1 box-arrow"></div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<?php echo $this->Form->create('UserCards', ['id' => 'frmSignIn', 'type' => 'file', 'onsubmit' => 'return check();']); ?>
<div class="form-group has-feedback">
<div class="col-xs-12 col-sm-12 col-md-12">
<?php echo $this->Flash->render(); ?>
<?php echo $this->Form->hidden('UserCards.user_id', ['class' => 'form-control-reg border-bottom-from label-text-sub required', 'id' => 'userId', 'type' => 'text', 'placeholder' => 'USERNAME']); ?>
<?php echo $this->Form->hidden('UserCards.organize_id', ['class' => 'form-control-reg border-bottom-from label-text-sub required', 'id' => 'organize_id', 'type' => 'text', 'label' => __('ไอดีใช้งาน'), 'placeholder' => 'USERNAME', 'required']); ?>
<?php echo $this->Form->input('UserCards.organize_code', ['class' => 'form-control-reg border-bottom-from label-text-sub required', 'id' => 'organize_code', 'type' => 'text', 'label' => __('Company Code'), 'placeholder' => 'Company Code', 'required']); ?>
......
......@@ -6,9 +6,8 @@
<!-- <div class="alert alert-warning" role="alert" style="margin: 10px 0px 10px 0px;font-size: 17px;text-align: center;">
<strong><?php echo __('กรุณา! ตรวจสอบอีเมลล์ของท่าน');?></strong>
</div>-->
<?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->Form->create(null, ['url' => ['controller' => 'Users','action' => 'changeForgotpassword/'.$token],'class' => 'form-horizontal','id' => '','name' => 'changePressword','role' => 'form', 'onsubmit' => 'return validateForm()']);?>
<?php echo $this->Flash->render(); ?>
</div>
<div>
<div class="form-group has-feedback">
<div class="col-md-12">
......@@ -63,27 +62,27 @@
function validateForm() {
var password = document.forms["changeForgotpassword"]["password"].value;
var password = document.forms["changePressword"]["password"].value;
if (password == null || password == "") {
alert("กรุณากรอก รหัสผ่านใหม่");
return false;
}
if(document.forms["changeForgotpassword"]["password"].value.length < 8)
if(document.forms["changePressword"]["password"].value.length < 8)
{
alert('กรุณาระบุรหัสผ่านใหม่อย่างน้อย 8 ตัวอักษร');
return false;
}
var confirm_password = document.forms["changeForgotpassword"][["confirm_password"]].value;
var confirm_password = document.forms["changePressword"][["confirm_password"]].value;
if (confirm_password == null || confirm_password == "") {
alert("กรุณากรอก ยืนยันรหัสผ่าน");
return false;
}
if(document.forms["changeForgotpassword"]["confirm_password"].value.length < 8)
if(document.forms["changePressword"]["confirm_password"].value.length < 8)
{
alert('กรุณาระบุยืนยันรหัสผ่านอย่างน้อย 8 ตัวอักษร');
return false;
}
if(document.forms["changeForgotpassword"]["password"].value != document.forms["changeForgotpassword"]["confirm_password"].value){
if(document.forms["changePressword"]["password"].value != document.forms["changePressword"]["confirm_password"].value){
alert('กรุณาระบุรหัสผ่านให้ตรงกัน');
//document.createAccount.confirm_password.focus();
return false;
......
......@@ -11,9 +11,8 @@
<div>
<div class="form-group has-feedback">
<div class="col-md-12">
<label class="label-text-sub"><?php echo __('อีเมลล์');?><em>* </em></label>
<label class="label-text-sub"><?php echo __('อีเมล');?><em>* </em></label>
<input type="text" value="" name="email" placeholder="mail@xxx.com" class="form-control-reg border-bottom-from" id="fremail">
</div>
</div>
</div>
......
......@@ -31,6 +31,18 @@
</div>
</div>
</div>
<div class="row">
<div class="form-group has-feedback">
<div class="col-md-12">
<div class=" row center">
<?php
echo $this->Html->link('ส่ง pin ใหม่อีกครั้ง', ['controller' => 'Users', 'action' => 'registersendpin/'.$token]);
?>
</div>
</div>
</div>
</div>
<?php echo $this->Form->end(); ?>
</div>
</div>
......
......@@ -8,7 +8,9 @@
<?php echo $this->Form->create(null, ['url' => ['controller' => 'Users', 'action' => 'pinCodepassword/'.$token],
'id' => 'PinCode', 'name' => 'PinCode', 'role' => 'form']);
?>
<div style="padding: 5px;">
<?php echo $this->Flash->render(); ?>
</div>
<div class="row">
<div class="form-group has-feedback">
<div class="col-md-12">
......@@ -30,6 +32,17 @@
</div>
</div>
</div>
<div class="row">
<div class="form-group has-feedback">
<div class="col-md-12">
<div class=" row center">
<?php
echo $this->Html->link('ส่ง pin ใหม่อีกครั้ง', ['controller' => 'Users', 'action' => 'forgotsendpin/'.$token]);
?>
</div>
</div>
</div>
</div>
<?php echo $this->Form->end(); ?>
</div>
</div>
......
......@@ -91,15 +91,15 @@
<div>
<div class="form-group has-feedback">
<div class="col-md-12">
<label class="label-text-sub"><?php echo __('เบอร์โทรศัพท์');?><em>* </em></label>
<input type="text" name="phone_no" id="phone_no" onkeypress="check_phone();" value="" maxlength="12" placeholder="000-000-0000" class="mask form-control-reg border-bottom-from">
<label class="label-text-sub"><?php echo __('เบอร์โทรศัพท์(มือถือ)');?><em>* </em></label>
<input type="text" name="phone_no" id="phone_no" onkeypress="check_phone();" value="" maxlength="10" placeholder="000-000-0000" class="mask form-control-reg border-bottom-from">
</div>
</div>
</div>
<div>
<div class="form-group has-feedback">
<div class="col-md-12">
<label class="label-text-sub"><?php echo __('อีเมลล์');?><em>* </em></label>
<label class="label-text-sub"><?php echo __('อีเมล');?><em>* </em></label>
<input type="text" name="email" id="fremail" value="" placeholder="mail@xxx.com" class="form-control-reg border-bottom-from">
</div>
......@@ -164,17 +164,6 @@
</div>
</div>
<!-- ------------------------------- popup ----------------------------------- -->
<script type="text/javascript">
$(function () {
$('#phone_no').inputmask('999-999-9999');
//==================================================
// CHANGE Date Times
//==================================================
$('#datepicker').datepicker({
format: 'dd/mm/yyyy'
});
});
</script>
<script>
$(document).ready(function() {
......@@ -230,7 +219,7 @@
// console.log(data);
data = jQuery.parseJSON(data);
if(data['chk'] == 'false'){
alert("อีเมลล์นี้มีในระบบแล้ว");
alert("อีเมลนี้มีในระบบแล้ว");
return false;
}
});
......@@ -316,7 +305,7 @@ function check_notnum() {
alert("กรุณากรอก เบอร์โทรศัพท์ของท่าน");
return false;
}
if(document.getElementById("phone_no").value.length != 12)
if(document.getElementById("phone_no").value.length != 10)
{
alert('กรุณากรอกเบอร์โทรศัพท์ ให้ครบ 10 หลัก');
return false;
......@@ -324,13 +313,13 @@ function check_notnum() {
var email = document.getElementById("fremail").value;
if (email == null || email == "") {
alert("กรุณากรอกอีเมลล์");
alert("กรุณากรอกอีเมล");
return false;
}
// Validate Email
var email = $("#fremail").val();
if (/(.+)@(.+){2,}\.(.+){2,}/.test(email)) { } else {
alert("รูปแบบที่อยู่อีเมลล์ผิด กรุณากรอกให้ถูกต้อง");
alert("รูปแบบที่อยู่อีเมลผิด กรุณากรอกให้ถูกต้อง");
return false;
}
......
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