Commit 5e93d833 by Teeradone-PIM

teeradone: register

parent 2905751c
<?php <?php
namespace App\Controller; namespace App\Controller;
use App\Controller\AppController; use App\Controller\AppController;
use Cake\Auth\DefaultPasswordHasher;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Http\Client; use Cake\Http\Client;
use Cake\Routing\Router; use Cake\Routing\Router;
use Cake\I18n\Time;
use Cake\Mailer\Email;
use Cake\Utility\Security;
class UsersController extends AppController class UsersController extends AppController
{ {
...@@ -25,7 +28,7 @@ class UsersController extends AppController ...@@ -25,7 +28,7 @@ class UsersController extends AppController
$this->viewBuilder()->layout('blank'); $this->viewBuilder()->layout('blank');
$data = $this->request->data(); $data = $this->request->data();
#$data['data']['ip'] = $this->request->clientIp(); #$data['data']['ip'] = $this->request->clientIp();
if(!empty($data)){ if(!empty($data)){
if(!empty($data['data']['username']) && !empty($data['data']['password'])){ if(!empty($data['data']['username']) && !empty($data['data']['password'])){
...@@ -85,49 +88,181 @@ class UsersController extends AppController ...@@ -85,49 +88,181 @@ class UsersController extends AppController
} }
public function signup() public function signup()
{ {
$this->loadModel('MasterCountries');
$this->loadModel('MasterProvinces');
$countries = $this->MasterCountries->find('list',
[
'conditions' => ['is_used' => true,'id'=>1],
'keyField' => 'id',
'valueField' => ['country_name_th']
]
);
if(!empty($countries)) $countries = $countries->toArray();
$provinces = $this->MasterProvinces->find('list',
[
'conditions' => ['is_used' => true,'master_country_id'=>1],
'keyField' => 'id',
'valueField' => 'province_name_th'
]
);
if(!empty($provinces)) $provinces = $provinces->toArray();
$this->set(compact('provinces','countries'));
$this->viewBuilder()->layout('blank'); $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 #Signup
public function createAccount() public function createAccount()
{ {
$this->viewBuilder()->layout('blank'); $this->loadModel('UserPersonals');
$data = $this->request->data(); $users = $this->Users->newEntity();
$user_personals = $this->UserPersonals->newEntity();
if(!empty($data)){
if($this->validateAccount($data)){ if ($this->request->is('post')) {
$data['data']['ip'] = $this->request->clientIp();#prr($data); // $username_check = $this->MasterProvinces->find('all')->toArray();
// pr($username_check);die;
// pr($this->request->data);die;
$today = Time::now();
$dateNow = $today->i18nFormat('yyyy-MM-dd HH:mm:ss');
$hasher = new DefaultPasswordHasher();
$firstname = $this->request->data['firstname'];
// $phone_no = $this->request->data['phone_no'];
$lastname = $this->request->data['lastname'];
$master_country_id = $this->request->data['master_country_id'];
$master_province_id = $this->request->data['master_province_id'];
$password = $this->request->data['password'];
$confirm_password = $this->request->data['confirm_password'];
$btn = $this->request->data['btn'];
if(!empty($this->request->data['birthdate'])){
$birthdate = explode("/", $this->request->data['birthdate']);
$birthdate = $birthdate[2].'-'.$birthdate[1].'-'.$birthdate[0];
$this->request->data['birthdate'] = $birthdate;
}else{
$birthdate = '2000-10-10';
}
$this->request->data['password'] = $hasher->hash($password);
$users['created_by'] = 0;
$users['is_used'] = true;
$users['created'] = $dateNow;
$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['modified_by'] = $modified_by;
$digits = 4;
$users['pin_code'] = str_pad(rand(0, pow(10, $digits)-1), $digits, '0', STR_PAD_LEFT);
if(!empty($this->request->data['accept'])){
$username_check = $this->Users->find('all',[
'conditions' => [
'Users.username' => $this->request->data['username']
]
])->toArray();
$api_core_create_account = Configure::read('Config.apiCore.createAccount'); $email_check = $this->UserPersonals->find('all',[
$http = new Client(); 'conditions' => [
$response = $http->post($api_core_create_account,$data)->body();#prd($response); 'UserPersonals.email' => $this->request->data['email']
$response = json_decode($response,'_full'); ]
//debug($response);exit(); ])->toArray();
if(!empty($response)){
if(trim($response['status']) == 'Success'){ if((empty($username_check))&&(empty($email_check))){
$this->Flash->success(__('create Account completed.')); $users = $this->Users->patchEntity($users, $this->request->getData());
return $this->redirect(['controller' => 'Users', 'action' => 'pinCode/'.$response['result']['data']['token']]); // pr($users);die;
} elseif ($response['result']['message'] == 'Email Duplicate'){
$this->Flash->error(__('Email Duplicate')); //------------------------------ ส่งอีเมล์ -----------------------------------------------------
return $this->redirect(['controller' => 'Users', 'action' => 'signup']); // $data_notification = [];
}else{ // $data_notification['email'] = $this->request->data['email'];
$this->Flash->error(__('create Account Fail')); // $data_notification['pin_code'] = $users['pin_code'];
return $this->redirect(['controller' => 'Users', 'action' => 'signup']); // $this->notification($data_notification);
//----------------------------------------------------------------------------------------------
$this->Users->save($users);
$user_personals['master_country_id'] = $master_country_id;
$user_personals['master_province_id'] = $master_province_id;
$user_personals['user_id'] = $users['id'];
$user_personals['firstname_th'] = $firstname;
$user_personals['lastname_th'] = $lastname;
$user_personals['created_by'] = 1;
$user_personals['created'] = $dateNow;
$user_personals = $this->UserPersonals->patchEntity($user_personals, $this->request->getData());
$this->UserPersonals->save($user_personals);
$this->Flash->success(__('The register success.'));
return $this->redirect(['controller' => 'Users', 'action' => 'pinCode/'.$users['token']]);
return $this->redirect(['action' => 'signin']);
} }
$this->Flash->success(__('user or email in program'));
return $this->redirect(['action' => 'signup']);
}else if(empty($this->request->data['accept'])){
$this->Flash->success(__('please accept'));
return $this->redirect(['action' => 'signup']);
} }
$this->Flash->error(__('The article could not be saved. Please, try again.'));
}else{
$this->Flash->error(__('Data Empty'));
return $this->redirect(['controller' => 'Users', 'action' => 'signin']);
}
} }
die; }
public function notification($data = null)
{
if(!empty($data)){
$verify_code = $data['pin_code'];
$from_email = ['support@pakgon.com' => 'Support'];
$to_emails = [$data['email']];
$email = new Email();
$email->transport('gmail');
try {
$email->template('notification_signup', 'connect');
$email->from($from_email);
$email->to($to_emails);
$email->subject('Signup Connect Verify');
$email->emailFormat('html');
$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!!';
}
} }
#--------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------
function validateAccount($data = null) function validateAccount($data = null)
...@@ -144,10 +279,10 @@ class UsersController extends AppController ...@@ -144,10 +279,10 @@ class UsersController extends AppController
} }
public function notification() // public function notification()
{ // {
$this->viewBuilder()->layout('blank'); // $this->viewBuilder()->layout('blank');
} // }
#Verify Pin Code #Verify Pin Code
public function pinCode($token=null) public function pinCode($token=null)
...@@ -175,8 +310,8 @@ class UsersController extends AppController ...@@ -175,8 +310,8 @@ class UsersController extends AppController
return $this->redirect(['controller' => 'Users', 'action' => 'pinCode/'.$token]); return $this->redirect(['controller' => 'Users', 'action' => 'pinCode/'.$token]);
} }
} }
} }
$this->set(array('token' => $token, '_serialize' => array('token'))); $this->set(array('token' => $token, '_serialize' => array('token')));
} }
#--------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------
...@@ -225,20 +360,29 @@ class UsersController extends AppController ...@@ -225,20 +360,29 @@ class UsersController extends AppController
{ {
$this->viewBuilder()->layout('blank'); $this->viewBuilder()->layout('blank');
$data = $this->request->data();#debug($data);exit(); $data = $this->request->data();#debug($data);exit();
// pr($data);die;
// pr($this->validateAccount($data));die;
if(!empty($data)){ if(!empty($data)){
// pr($data);die;
if($this->validateAccount($data)){ if($this->validateAccount($data)){
$data['data']['ip'] = $this->request->clientIp();#debug($data);exit(); $data['data']['ip'] = $this->request->clientIp();#debug($data);exit();
// pr($data);die;
$api_core_change_password = Configure::read('Config.apiCore.changePassword');#debug($api_core_change_password);exit(); $api_core_change_password = Configure::read('Config.apiCore.changePassword');#debug($api_core_change_password);exit();
$http = new Client(); $http = new Client();
// pr($http);die;
#$response = json_decode($http->post($api_core_change_password,$data)->body(),'_full'); #$response = json_decode($http->post($api_core_change_password,$data)->body(),'_full');
$response = $http->post($api_core_change_password,$data)->body(); $response = $http->post($api_core_change_password,$data)->body();
// pr($data);die;
#debug($response);exit(); #debug($response);exit();
$response = json_decode($response,'_full'); $response = json_decode($response,'_full');
// pr($response);die;
#debug($response);exit(); #debug($response);exit();
if(!empty($response)){ if(!empty($response)){
// pr($response);die;
#if(trim($response['status']) == 'Success' && !empty($response['result']['type'])){ #if(trim($response['status']) == 'Success' && !empty($response['result']['type'])){
if(trim($response['status']) == 'Success'){ if(trim($response['status']) == 'Success'){
#$this->response->withHeader('Authorization', 'Bearer '.$response['result']['token']); #$this->response->withHeader('Authorization', 'Bearer '.$response['result']['token']);
...@@ -267,5 +411,6 @@ class UsersController extends AppController ...@@ -267,5 +411,6 @@ class UsersController extends AppController
{ {
$this->checkToken(); $this->checkToken();
} }
} }
...@@ -71,51 +71,51 @@ class UsersTable extends Table { ...@@ -71,51 +71,51 @@ class UsersTable extends Table {
* @return \Cake\Validation\Validator * @return \Cake\Validation\Validator
*/ */
public function validationDefault(Validator $validator) { public function validationDefault(Validator $validator) {
$validator // $validator
->allowEmpty('id', 'create'); // ->allowEmpty('id', 'create');
$validator // $validator
->scalar('username') // ->scalar('username')
->allowEmpty('username'); // ->allowEmpty('username');
$validator // $validator
->scalar('password') // ->scalar('password')
->allowEmpty('password'); // ->allowEmpty('password');
$validator // $validator
->integer('point') // ->integer('point')
->allowEmpty('point'); // ->allowEmpty('point');
$validator // $validator
->boolean('is_used') // ->boolean('is_used')
->allowEmpty('is_used'); // ->allowEmpty('is_used');
$validator // $validator
->scalar('dynamic_key') // ->scalar('dynamic_key')
->allowEmpty('dynamic_key'); // ->allowEmpty('dynamic_key');
$validator // $validator
->date('dynamic_key_expiry') // ->date('dynamic_key_expiry')
->allowEmpty('dynamic_key_expiry'); // ->allowEmpty('dynamic_key_expiry');
$validator // $validator
->scalar('token') // ->scalar('token')
->allowEmpty('token'); // ->allowEmpty('token');
$validator // $validator
->date('token_expiry') // ->date('token_expiry')
->allowEmpty('token_expiry'); // ->allowEmpty('token_expiry');
$validator // $validator
->requirePresence('created_by', 'create') // ->requirePresence('created_by', 'create')
->notEmpty('created_by'); // ->notEmpty('created_by');
$validator // $validator
->allowEmpty('modified_by'); // ->allowEmpty('modified_by');
$validator // $validator
->scalar('pin_code') // ->scalar('pin_code')
->allowEmpty('pin_code'); // ->allowEmpty('pin_code');
return $validator; return $validator;
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<div class="col-md-12"> <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="data[firstname]" value="" placeholder="FIRSTNAME" class="form-control-reg border-bottom-from" id="inputSuccess"> <input type="text" name="firstname" value="" placeholder="FIRSTNAME" class="form-control-reg border-bottom-from" id="inputSuccess">
</div> </div>
</div> </div>
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<div class="col-md-12"> <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="data[lastname]" value="" placeholder="LASTNAME" class="form-control-reg border-bottom-from" id="inputSuccess"> <input type="text" name="lastname" value="" placeholder="LASTNAME" class="form-control-reg border-bottom-from" id="inputSuccess">
</div> </div>
</div> </div>
...@@ -29,16 +29,61 @@ ...@@ -29,16 +29,61 @@
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<div class="col-md-12"> <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="data[username]" value="" placeholder="USERNAME" class="form-control-reg border-bottom-from" id="inputSuccess"> <input type="text" name="username" value="" placeholder="USERNAME" class="form-control-reg border-bottom-from" id="inputSuccess">
</div> </div>
</div> </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>
<?php
echo $this->Form->input( 'master_country_id', array(
'name'=>'master_country_id',
'id'=>'master_country_id',
'label' => false,
'type' => 'select',
'options' => $countries,
'empty' => '---Select---',
'default' => '',
'class' => 'form-control border-bottom-from label-text-sub required',
'style' => 'width:100%'
));
?>
</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>
<?php
echo $this->Form->input( 'master_province_id', [
'name'=>'master_province_id',
// 'id'=>'master_province_id',
'label' => false,
'type' => 'select',
'options' => $provinces,
'empty' => '---Select---',
'default' => '',
'class' => 'form-control border-bottom-from label-text-sub required',
'style' => 'width:100%'
]);
?>
</div>
</div>
</div>
<div> <div>
<div class="form-group has-feedback bootstrap-iso"> <div class="form-group has-feedback bootstrap-iso">
<div class="col-md-12"> <div class="col-md-12">
<label class="label-text-sub"><?php echo __('วันเกิด');?></label> <label class="label-text-sub"><?php echo __('วันเกิด');?></label>
<input type="text" name="data[birthdate]" id="date" placeholder="กรุณาระบุวันเดือนปีเกิด" value="" placeholder="DD-MM-YYYY" data-date-format="mm/dd/yyyy" class="form-control-reg border-bottom-from"> <input type="text" name="birthdate" id="date" placeholder="กรุณาระบุวันเดือนปีเกิด" value="" placeholder="DD-MM-YYYY" data-date-format="mm/dd/yyyy" class="form-control-reg border-bottom-from">
<span class="glyphicon glyphicon-calendar form-control-feedback"></span> <span class="glyphicon glyphicon-calendar form-control-feedback"></span>
</div> </div>
</div> </div>
...@@ -48,7 +93,7 @@ ...@@ -48,7 +93,7 @@
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<div class="col-md-12"> <div class="col-md-12">
<label class="label-text-sub"><?php echo __('เบอร์โทรศัพท์');?></label> <label class="label-text-sub"><?php echo __('เบอร์โทรศัพท์');?></label>
<input type="text" name="data[phone_no]" onkeypress="check_phone();" value="" maxlength="10" placeholder="0000000000" class="mask form-control-reg border-bottom-from" id="inputSuccess"> <input type="text" name="phone_no" onkeypress="check_phone();" value="" maxlength="10" placeholder="0000000000" class="mask form-control-reg border-bottom-from" id="inputSuccess">
</div> </div>
</div> </div>
...@@ -57,7 +102,7 @@ ...@@ -57,7 +102,7 @@
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<div class="col-md-12"> <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="data[email]" id="fremail" value="" placeholder="mail@xxx.com" class="form-control-reg border-bottom-from" id="inputSuccess"> <input type="text" name="email" id="fremail" value="" placeholder="mail@xxx.com" class="form-control-reg border-bottom-from" id="inputSuccess">
</div> </div>
</div> </div>
...@@ -66,7 +111,7 @@ ...@@ -66,7 +111,7 @@
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<div class="col-md-12"> <div class="col-md-12">
<label class="label-text-sub"><?php echo __('รหัสผ่าน');?></label> <label class="label-text-sub"><?php echo __('รหัสผ่าน');?></label>
<input data-toggle="password" data-placement="before" type="password" name="data[password]" value="" placeholder="********" class="form-control input-lg color-button-border border-bottom-from" id="FALSE" style="padding:0px 0px !important;"> <input data-toggle="password" data-placement="before" type="password" name="password" value="" placeholder="********" class="form-control input-lg color-button-border border-bottom-from" id="FALSE" style="padding:0px 0px !important;">
<!--<input type="password" name="data[password]" id="password" value="" placeholder="********" class="form-control-reg border-bottom-from" onkeyup='check();'>--> <!--<input type="password" name="data[password]" id="password" value="" placeholder="********" class="form-control-reg border-bottom-from" onkeyup='check();'>-->
<!--<span class="glyphicon glyphicon-eye-close form-control-feedback"></span>--> <!--<span class="glyphicon glyphicon-eye-close form-control-feedback"></span>-->
</div> </div>
...@@ -76,7 +121,7 @@ ...@@ -76,7 +121,7 @@
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<div class="col-md-12"> <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 data-toggle="password" data-placement="before" type="password" name="data[confirm_password]" value="" placeholder="********" class="form-control input-lg color-button-border border-bottom-from" id="FALSE" style="padding:0px 0px !important;"> <input data-toggle="password" data-placement="before" type="password" name="confirm_password" value="" placeholder="********" class="form-control input-lg color-button-border border-bottom-from" id="FALSE" style="padding:0px 0px !important;">
<!--<input type="password" id="confirm_password" name="data[confirm_password]" value="" placeholder="********" class="form-control-reg border-bottom-from" onkeyup='check();'>--> <!--<input type="password" id="confirm_password" name="data[confirm_password]" value="" placeholder="********" class="form-control-reg border-bottom-from" onkeyup='check();'>-->
<!--<span class="glyphicon glyphicon-eye-close form-control-feedback" id='message'></span>--> <!--<span class="glyphicon glyphicon-eye-close form-control-feedback" id='message'></span>-->
<span id='message'></span> <span id='message'></span>
...@@ -106,7 +151,7 @@ ...@@ -106,7 +151,7 @@
</div> </div>
<!------------------Exit Model----------------------> <!------------------Exit Model---------------------->
<div class="switch switch-lg switch-warning" style="padding: 10px 0px 30px 0px;"> <div class="switch switch-lg switch-warning" style="padding: 10px 0px 30px 0px;">
<input type="checkbox" name="data[accept]" data-plugin-ios-switch data-toggle="modal" data-target="#largeModal"/> <input type="checkbox" id="accept" name="accept" data-plugin-ios-switch data-toggle="modal" data-target="#largeModal"/>
<span style="font-size: 17px;"><?php echo __('กรุณายอมรับ <b>เงื่อนไขการใช้งาน</b>');?></span> <span style="font-size: 17px;"><?php echo __('กรุณายอมรับ <b>เงื่อนไขการใช้งาน</b>');?></span>
</div> </div>
...@@ -120,63 +165,65 @@ ...@@ -120,63 +165,65 @@
<?php echo $this->Form->end(); ?> <?php echo $this->Form->end(); ?>
</div> </div>
</div> </div>
<!--------------------------------- popup -------------------------------------> <!-- ------------------------------- popup ----------------------------------- -->
<script> <script>
function validateForm() { function validateForm() {
var firstname = document.forms["createAccount"]["data[firstname]"].value; var firstname = document.forms["createAccount"]["firstname"].value;
if (firstname == null || firstname == "") { if (firstname == null || firstname == "") {
alert("กรุณากรอกชื่อ"); alert("กรุณากรอกชื่อ");
return false; return false;
} }
var lastname = document.forms["createAccount"]["data[lastname]"].value; var lastname = document.forms["createAccount"]["lastname"].value;
if (lastname == null || lastname == "") { if (lastname == null || lastname == "") {
alert("กรุณากรอกนามสกุล"); alert("กรุณากรอกนามสกุล");
return false; return false;
} }
var username = document.forms["createAccount"]["data[username]"].value; var username = document.forms["createAccount"]["username"].value;
if (username == null || username == "") { if (username == null || username == "") {
alert("กรุณากรอกชื่อผู้ใช้งานของท่าน"); alert("กรุณากรอกชื่อผู้ใช้งานของท่าน");
return false; return false;
} }
if(document.forms["createAccount"]["data[username]"].value.length < 5) if(document.forms["createAccount"]["username"].value.length < 5)
{ {
alert('กรุณาระบุชื่อผู้ใช้งานอย่างน้อย 5 ตัวอักษร'); alert('กรุณาระบุชื่อผู้ใช้งานอย่างน้อย 5 ตัวอักษร');
return false; return false;
} }
/*
var birthdate = document.forms["createAccount"]["data[birthdate]"].value;
var birthdate = document.forms["createAccount"]["birthdate"].value;
if (birthdate == null || birthdate == "") { if (birthdate == null || birthdate == "") {
alert("กรุณากรอก วันเดือนปีเกิดของท่าน"); alert("กรุณากรอก วันเดือนปีเกิดของท่าน");
return false; return false;
} }
var person_card_no = document.forms["createAccount"]["data[person_card_no]"].value; // var person_card_no = document.forms["createAccount"]["person_card_no"].value;
if (person_card_no == null || person_card_no == "") { // if (person_card_no == null || person_card_no == "") {
alert("กรุณากรอกเลขบัตรประชาชน"); // alert("กรุณากรอกเลขบัตรประชาชน");
return false; // return false;
} // }
if(document.forms["createAccount"]["data[person_card_no]"].value.length < 13 || document.forms["createAccount"]["data[person_card_no]"].value.length > 13) // if(document.forms["createAccount"]["data[person_card_no]"].value.length < 13 || document.forms["createAccount"]["data[person_card_no]"].value.length > 13)
{ // {
alert('กรุณากรอกเลขบัตรประชาชนให้ครบ 13 หลัก'); // alert('กรุณากรอกเลขบัตรประชาชนให้ครบ 13 หลัก');
return false; // return false;
} // }
var phone_no = document.forms["createAccount"]["data[phone_no]"].value; var phone_no = document.forms["createAccount"]["phone_no"].value;
if (phone_no == null || phone_no == "") { if (phone_no == null || phone_no == "") {
alert("กรุณากรอกเบอร์โทรศัพท์ของท่าน"); alert("กรุณากรอก เบอร์โทรศัพท์ของท่าน");
return false; return false;
} }
if(document.forms["createAccount"]["data[phone_no]"].value.length < 10 || document.forms["createAccount"]["data[phone_no]"].value.length > 10) if(document.forms["createAccount"]["phone_no"].value.length < 10 || document.forms["createAccount"]["phone_no"].value.length > 10)
{ {
alert('กรุณากรอกเบอร์โทรศัพท์ ให้ครบ 10 หลัก'); alert('กรุณากรอกเบอร์โทรศัพท์ ให้ครบ 10 หลัก');
return false;
}
*/
/*var lastname = document.forms["createAccount"]["data[lastname]"].value;
if (lastname == null || lastname == "") {
alert("กรุณากรอกรหัสผ่าน");
return false; return false;
}*/ }
var email = document.forms["createAccount"]["data[email]"].value;
// var lastname = document.forms["createAccount"]["data[lastname]"].value;
// if (lastname == null || lastname == "") {
// alert("กรุณากรอกรหัสผ่าน");
// return false;
// }
var email = document.forms["createAccount"]["email"].value;
if (email == null || email == "") { if (email == null || email == "") {
alert("กรุณากรอกอีเมลล์"); alert("กรุณากรอกอีเมลล์");
return false; return false;
...@@ -187,28 +234,40 @@ ...@@ -187,28 +234,40 @@
alert("รูปแบบที่อยู่อีเมลล์ผิด กรุณากรอกให้ถูกต้อง"); alert("รูปแบบที่อยู่อีเมลล์ผิด กรุณากรอกให้ถูกต้อง");
return false; return false;
} }
var password = document.forms["createAccount"]["data[password]"].value; var password = document.forms["createAccount"]["password"].value;
if (password == null || password == "") { if (password == null || password == "") {
alert("กรุณากรอกรหัสผ่าน"); alert("กรุณากรอกรหัสผ่าน");
return false; return false;
} }
if(document.forms["createAccount"]["data[password]"].value.length < 8) if(document.forms["createAccount"]["password"].value.length < 8)
{ {
alert('กรุณาระบุรหัสผ่านอย่างน้อย 8 ตัวอักษร'); alert('กรุณาระบุรหัสผ่านอย่างน้อย 8 ตัวอักษร');
return false; return false;
} }
var confirm_password = document.forms["createAccount"]["data[confirm_password]"].value; var confirm_password = document.forms["createAccount"]["confirm_password"].value;
if (confirm_password == null || confirm_password == "") { if (confirm_password == null || confirm_password == "") {
alert("กรุณายืนยันรหัสผ่าน"); alert("กรุณายืนยันรหัสผ่าน");
return false; return false;
} }
if(document.forms["createAccount"]["data[password]"].value != document.forms["createAccount"]["data[confirm_password]"].value){ if(document.forms["createAccount"]["password"].value != document.forms["createAccount"]["confirm_password"].value){
alert('กรุณาระบุรหัสผ่านให้ตรงกัน'); alert('กรุณาระบุรหัสผ่านให้ตรงกัน');
//document.createAccount.confirm_password.focus(); //document.createAccount.confirm_password.focus();
return false; return false;
} }
$("body").delegate(".is_active", "click", function () {
$('.is_active').not(this).prop('checked', false);
return true;
// var id = $(this).closest('td').find('#idAddresses').val();
// var id_card13 = $(this).closest('td').find('#idCard13Addresses').val();
// console.log(id);
// $.post("/Addresses/currentAddress", {id: id, id_card13 : id_card13}, function(data) {
// location.reload();
// });
});
} }
</script> </script>
<style> <style>
#alertBox { #alertBox {
...@@ -371,17 +430,47 @@ ...@@ -371,17 +430,47 @@
alert('Alert this pages'); alert('Alert this pages');
} }
</script> </script>
<!--------------------------------- confirm password -------------------------------->
<script type="text/javascript">
$(document).ready(function() {
$(document).ready(function() {
$("#loding1").hide();
$("#loding2").hide();
$("#master_country_id").on('change',function() {
var id = $(this).val();
$("#loding1").show();
$("#master_province_id").find('option').remove();
// alert('dddd');
if (id) {
var dataString = 'id='+ id;
$.ajax({
type: "POST",
url: 'users/getStates' ,
data: dataString,
cache: false,
success: function(html) {
$("#loding1").hide();
$.each(html, function(key, value) {
$('<option>').val('').text('---Select---');
$('<option>').val(key).text(value).appendTo($("#master_province_id"));
});
}
});
}
});
});
});
</script>
<!--------------------------------- confirm password ------------------------------ -->
<script> <script>
function check_number() {
e_k=event.keyCode
//if (((e_k < 48) || (e_k > 57)) && e_k != 46 ) {
if (e_k = 13 && (e_k < 48) || (e_k > 57)) {
event.returnValue = false;
alert("ขออภัยหมายเลขบัตรประจำตัวประชาชน ต้องเป็นตัวเลขเท่านั้น");
}
}
function check_phone() { function check_phone() {
e_k=event.keyCode e_k=event.keyCode
//if (((e_k < 48) || (e_k > 57)) && e_k != 46 ) { //if (((e_k < 48) || (e_k > 57)) && e_k != 46 ) {
......
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