Commit fcce0e50 by Zen-PC\Zen

Merge branch 'integration' into kraikrit

parents 9e6c0a7a 3e1fe137
......@@ -231,6 +231,7 @@ class UserCardsController extends AppController
}
public function viewCard($user_id = null){
$this->viewBuilder()->layout('blank');
// $user = $this->Auth();
$this->loadModel('UserCards');
$UserCards = $this->UserCards->find('all')
->select($this->UserCards)
......
......@@ -115,26 +115,6 @@ class UsersController extends AppController
$this->viewBuilder()->layout('blank');
}
// public function getProvince() {
// $this->autoRender = false;
// $this->loadModel('MasterProvinces');
// $states = array();
// pr($this->request->$data);die;
// if (isset($this->request['data']['id'])) {
// $states = $this->MasterProvinces->find('list', array(
// 'keyField' => 'id',
// 'valueField' => ['country_name_th'],
// 'conditions' => array(
// 'State.countries_id' => $this->request['data']['id']
// )
// ));
// }
// header('Content-Type: application/json');
// pr($states);die;
// echo json_encode($states);
// exit();
// }
#---------------------------------------------------------------------------------------------------
#Signup
......@@ -220,7 +200,7 @@ class UsersController extends AppController
// $this->Flash->success(__('The register success.'));
return $this->redirect(['controller' => 'Users', 'action' => 'pinCode/'.$users['token']]);
return $this->redirect(['action' => 'signin']);
// return $this->redirect(['action' => 'signin']);
}
$this->Flash->error(__('Username or Email Address already used by others.'));
return $this->redirect(['action' => 'signup']);
......@@ -289,7 +269,7 @@ class UsersController extends AppController
public function pinCode($token=null)
{
if(empty($token)) die;
if(empty($token))
$this->viewBuilder()->layout('blank');
......@@ -317,42 +297,10 @@ class UsersController extends AppController
#---------------------------------------------------------------------------------------------------
#Forgot Password
// public function forgotPassword()
// {
// $this->viewBuilder()->layout('blank');
// $data = $this->request->data();
// #$data['data']['ip'] = $this->request->clientIp();
// if(!empty($data)){
// if(!empty($data['data']['username'])){
// $data['data']['ip'] = $this->request->clientIp();#prr($data);
// $api_core_forgotPassword = Configure::read('Config.apiCore.forgotPassword');
// $http = new Client();
// $response = $http->post($api_core_forgotPassword,$data['data'])->body();
// $response = json_decode($response,'_full');#debug($response);
// if(!empty($response)){
// if(trim($response['status']) == 'Success'){
// $this->Flash->success(__('Completed.'));
// return $this->redirect(['controller' => 'Users', 'action' => 'signin']);
// }else{
// $this->Flash->error(__('Forgot Password Fail'));
// return $this->redirect(['controller' => 'Users', 'action' => 'forgotPassword']);
// }
// }else{
// $this->Flash->error(__('Forgot Password Fail'));
// return $this->redirect(['controller' => 'Users', 'action' => 'forgotPassword']);
// }
// }else{
// $this->Flash->error(__('Data Empty'));
// return $this->redirect(['controller' => 'Users', 'action' => 'forgotPassword']);
// }
// }
// }
#---------------------------------------------------------------------------------------------------
public function forgotPassword()
{
......@@ -361,41 +309,46 @@ class UsersController extends AppController
if ($this->request->is('post')) {
$hasher = new DefaultPasswordHasher();
$email = $this->request->data['email'];
//-------------------Random---------------------------------------------------------------
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$pass = array();
$alphaLength = strlen($alphabet) - 1;
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
$password = implode($pass);
//------------------------------------------------------------------------------------------
$users['password'] = $hasher->hash($password);
//-------------------RandomPassword---------------------------------------------------------
// $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
// $pass = array();
// $alphaLength = strlen($alphabet) - 1;
// for ($i = 0; $i < 8; $i++) {
// $n = rand(0, $alphaLength);
// $pass[] = $alphabet[$n];
// }
// $password = implode($pass);
//------------------------------------------------------------------------------------------
// $users['password'] = $hasher->hash($password);
$user_personals = $this->UserPersonals->find('all',[
'conditions' => [
'UserPersonals.email' => $email
]
])->first();
pr($password);
if(!empty($user_personals)){
//--------------------ตัวส่ง Email ---------------------------------------------------------
//--------------------ตัวส่ง Email ---------------------------------------------------------
// pr($user_personals);die;
// $data_notification = [];
// $data_notification['email'] = $this->request->data['email'];
// $data_notification['pin_code'] = $password;
// $data_notification['pin_code'] = $users['pin_pass'];
// $this->notification($data_notification);
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
$users = $this->Users->find('all',[
'conditions' => [
'Users.id' => $user_personals['user_id']
]
])->first();
pr($users);die;
$users = $this->Users->patchEntity($users, $this->request->getData());
$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());
$this->Users->save($users);
// pr($users);die;
$this->Flash->success(__('send password to email success'));
return $this->redirect(['action' => 'signin']);
return $this->redirect(['action' => 'pinCodepassword/'.$token]);
}else{
$this->Flash->error(__('Invalid Email.'));
return $this->redirect(['action' => 'forgot-password']);
......@@ -403,38 +356,57 @@ class UsersController extends AppController
}
}
public function pinCodepassword($token=null)
{
$this->viewBuilder()->layout('blank');
$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' => 'changePassword/'.$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()
public function changePassword($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'];
$oldpassword = $this->request->data['oldpassword'];
$this->request->data['password'] = $hasher->hash($this->request->data['password']);
$userid = 59445;
$users = $this->Users->find('all',[
'conditions' => [
'Users.id' => $userid
]
])->first();
//------- เทียบ password ที่เข้ารหัส ---------------password_verify($password,hashed_password)---------------------------
if (password_verify($oldpassword, $users['password'])) {
if($password==$confirm_password){
$users = $this->Users->patchEntity($users, $this->request->getData());
$this->Users->save($users);
$this->Flash->success(__('change password success'));
return $this->redirect(['action' => 'signin']);
}
} else {
$this->Flash->error(__('Invalid password.'));
return $this->redirect(['action' => 'change-password']);
return $this->redirect(['action' => 'change-password/'.$token]);
}
}
$this->set(array('token' => $token, '_serialize' => array('token')));
}
#---------------------------------------------------------------------------------------------------
public function signout()
......
......@@ -94,8 +94,7 @@
date.focus();
}
}
</script>
<script>
$(document).ready(function(){
var date_input=$('input[id="date"]'); //our date input has the name "date"
var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
......
<?php
use Cake\I18n\Time;
?>
<div class="owl-carousel owl-theme" data-plugin-options="{'items': 1}">
<?php foreach ($UserCards as $value) { #pr($value);die;?>
<div class="row">
......@@ -37,10 +40,18 @@
<div class="col-xs-1">
</div>
<div class="col-xs-5">
<?php echo $value['date_issued'] ?>
<?php
$now = new Time($value['date_issued']);
$dateIssued = $now->i18nFormat('yyyy-MM-dd');
echo $this->DateFormat->formatDateThai($dateIssued);
?>
</div>
<div class="col-xs-5">
<?php echo $value['date_expiry'] ?>
<?php
$now = new Time($value['date_expiry']);
$dateExpiry = $now->i18nFormat('yyyy-MM-dd');
echo $this->DateFormat->formatDateThai($dateIssued);
?>
</div>
</div>
<div class="row">
......@@ -98,18 +109,74 @@
<div class="form-group has-feedback">
<div class="col-xs-12 col-sm-12 col-md-12">
<label style="font-size: 17px" class="col-xs-4 col-sm-4 col-md-4">วันที่ออกบัตร</label>
<?php echo $value['date_issued'] ?>
<?php
$now = new Time($value['date_issued']);
$dateIssued = $now->i18nFormat('yyyy-MM-dd');
echo $this->DateFormat->formatDateThai($dateIssued);
?>
</div>
</div>
<div class="form-group has-feedback">
<div class="col-xs-12 col-sm-12 col-md-12">
<label style="font-size: 17px" class="col-xs-4 col-sm-4 col-md-4">วันที่หมดอายุ</label>
<?php echo $value['date_expiry'] ?>
<?php
$now = new Time($value['date_expiry']);
$dateExpiry = $now->i18nFormat('yyyy-MM-dd');
echo $this->DateFormat->formatDateThai($dateIssued);
?>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-xs-1 col-sm-1 col-md-1 box-arrow">
<i class = "fa fa-angle-left prev" > </i>
</div>
<div class="col-xs-9 col-sm-9 col-md-9">
<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>
<!--- s -->
<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 style="position: absolute;z-index: 2;">
<a href="profile_setting"><img src="/img/core/img/setting-icon@3x.png"/></a>
</div> -->
<!-- <div class="bg-profile"></div> -->
<!--<div class="col-xs-12 col-sm-12 col-md-12" style="padding-top: 20px;">-->
<div class="form-group has-feedback">
<div class="col-xs-12 col-sm-12 col-md-12">
<?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']); ?>
<label id = "nameorg_th" style="color: green"></label>
<label id = "noorg_th" style="color: red"></label>
</div>
</div>
<div class="form-group has-feedback">
<div class="col-xs-12 col-sm-12 col-md-12">
<?php echo $this->Form->input('UserCards.employee', ['class' => 'form-control-reg border-bottom-from label-text-sub required', 'id' => 'employee', 'type' => 'text', 'label' => __('รหัสพนักงาน / รหัสนักศึกษา'), 'placeholder' => 'รหัสพนักงาน / รหัสนักศึกษา', 'disabled', 'required']); ?>
</div>
</div>
<div class="form-group has-feedback bootstrap-iso">
<div class="col-xs-12 col-sm-12 col-md-12">
<label class="label-text-sub"><?php echo __('วันเกิด');?></label>
<input type="text" name="UserCards[birthdate]" id="date" placeholder="กรุณาระบุวันเดือนปีเกิด" value="" placeholder="DD-MM-YYYY" data-date-format="mm/dd/yyyy" class="form-control-reg border-bottom-from" disabled>
<span class="glyphicon glyphicon-calendar form-control-feedback"></span>
</div>
</div>
<div>
<button type="submit" class="btn btn-quaternary mr-xs mb-sm button-text-profile">ตรวจสอบ</button>
</div>
<?php echo $this->Form->end(); ?>
</div>
</div>
<!-- e -->
</div>
</div>
<style>
......@@ -157,6 +224,65 @@ function callBack(){
$('.next').show();
}
}
//$('.prev').hide();
var organize_id = $("#organize_id");
var employee = $("#employee");
var date = $("#date");
$(document).ready(function() {
$("#organize_code").on('change',function(){
var organize_code = $("#organize_code").val();
$.post("/UserCards/checkOrg", {organize_code: organize_code}, function(data) {
if(data!='false'){
data = jQuery.parseJSON(data);
console.log(data);
employee.val('sssss');
if(data['chkuser'] == true){
$("#noorg_th").text('ลงทะเบียนกับ '+data[0]['org_name_th']+' แล้ว');
$("#nameorg_th").text('');
$('#employee').attr("disabled",true);
$('#date').attr("disabled",true);
organize_id.val('');
employee.val('');
date.val('');
}else if(data['chkuser'] == false){
$("#nameorg_th").text(data[0]['org_name_th']);
$("#noorg_th").text('');
$("#employee").removeAttr("disabled");
$("#date").removeAttr("disabled");
organize_id.val(data[0]['id']);
}
}else{
$("#noorg_th").text('ไม่พบข้อมูล');
$("#nameorg_th").text('');
$('#employee').attr("disabled",true);
$('#date').attr("disabled",true);
organize_id.val('');
employee.val('');
date.val('');
}
});
});
});
function check() {
if (employee.val() == '') {
employee.focus();
return false;
}
if (date.val() == '') {
return false;
date.focus();
}
}
$(document).ready(function(){
var date_input=$('input[id="date"]'); //our date input has the name "date"
var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
var options={
format: 'dd/mm/yyyy',
container: container,
todayHighlight: true,
autoclose: true,
};
date_input.datepicker(options);
})
</script>
<?php $this->end();?>
......@@ -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' => 'changePassword'],'class' => 'form-horizontal','id' => '','name' => 'changePressword','role' => 'form', 'onsubmit' => 'return validateForm()']);?>
<?php echo $this->Form->create(null, ['url' => ['controller' => 'Users','action' => 'changePassword/'.$token],'class' => 'form-horizontal','id' => '','name' => 'changePressword','role' => 'form', 'onsubmit' => 'return validateForm()']);?>
<?php echo $this->Flash->render(); ?>
<div>
<div class="form-group has-feedback">
<div class="col-md-12">
......@@ -22,7 +21,7 @@
<div class="form-group has-feedback">
<div class="col-md-12">
<label class="label-text-sub"><?php echo __('รหัสผ่านใหม่');?></label>
<input type="text" value="" name="password" placeholder="********" class="form-control-reg border-bottom-from" id="password" onkeyup='check();'>
<input type="password" value="" name="password" placeholder="********" class="form-control-reg border-bottom-from" id="password" onkeyup='check();'>
<span class="glyphicon glyphicon-eye-open form-control-feedback"></span>
</div>
</div>
......@@ -44,7 +43,6 @@
echo $this->Form->submit('ตรวจสอบ', array('div' => false, 'class' => 'btn btn-quaternary mr-xs mb-sm button-text',
'name' => 'btn', 'id' => '', 'title' => 'Title'));
?>
</div>
<?php echo $this->Form->end(); ?>
......@@ -200,3 +198,57 @@
color:green;
}
</style>
<script>
var ALERT_TITLE = "";
var ALERT_BUTTON_TEXT = "Ok";
if (document.getElementById) {
window.alert = function (txt) {
createCustomAlert(txt);
}
}
function createCustomAlert(txt) {
d = document;
if (d.getElementById("modalContainer"))
return;
mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
mObj.id = "modalContainer";
mObj.style.height = d.documentElement.scrollHeight + "px";
alertObj = mObj.appendChild(d.createElement("div"));
alertObj.id = "alertBox";
if (d.all && !window.opera)
alertObj.style.top = document.documentElement.scrollTop + "px";
alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth) / 2 + "px";
alertObj.style.visiblity = "visible";
h1 = alertObj.appendChild(d.createElement("h1"));
h1.appendChild(d.createTextNode(ALERT_TITLE));
msg = alertObj.appendChild(d.createElement("p"));
//msg.appendChild(d.createTextNode(txt));
msg.innerHTML = txt;
btn = alertObj.appendChild(d.createElement("a"));
btn.id = "closeBtn";
btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
btn.href = "#";
btn.focus();
btn.onclick = function () {
removeCustomAlert();
return false;
}
alertObj.style.display = "block";
}
function removeCustomAlert() {
document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}
function ful() {
alert('Alert this pages');
}
</script>
......@@ -17,9 +17,6 @@
</div>
</div>
</div>
<div>
<?php
echo $this->Form->submit('ตรวจสอบ', array('div' => false, 'class' => 'btn btn-quaternary mr-xs mb-sm button-text',
......
......@@ -64,10 +64,10 @@
<?php
echo $this->Form->input( 'master_province_id', [
'name'=>'master_province_id',
// 'id'=>'master_province_id',
'id'=>'master_province_id',
'label' => false,
'type' => 'select',
'options' => $provinces,
// 'options' => $provinces,
'empty' => '---Select---',
'default' => '',
'class' => 'form-control border-bottom-from label-text-sub required',
......@@ -437,6 +437,7 @@
var id = $(this).val();
if (id) {
var dataString = 'id=' + id;
$("#master_province_id").html('');
$.ajax({
type: "POST",
url: '/users/getProvince',
......
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