Commit f31c1fb2 by Teeradone-PIM

teeradone validate register

parent 2faaee2b
......@@ -18,7 +18,7 @@ class UsersController extends AppController {
*/
public function 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() {
......@@ -314,26 +314,7 @@ class UsersController extends AppController {
$this->loadModel('UserPersonals');
if ($this->request->is('post')) {
$hasher = new DefaultPasswordHasher();
$email = $this->request->data['email'];
//-------------------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);
//--------------------ตัวส่ง Email --------------------------------------
//pr($user_personals);die;
// $data_notification = [];
// $data_notification['email'] = $this->request->data['email'];
// $data_notification['password'] = $password;
// $this->notification($data_notification);
//------------------------------------------------------------------------------------------
$email = $this->request->data['email'];
$user_personals = $this->UserPersonals->find('all',[
'conditions' => [
'UserPersonals.email' => $email
......@@ -382,7 +363,7 @@ class UsersController extends AppController {
$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]);
return $this->redirect(['controller' => 'Users', 'action' => 'changeForgotpassword/'.$token]);
}
$this->Flash->error(__('Pin Invalid'));
return $this->redirect(['controller' => 'Users', 'action' => 'pinCodepassword/'.$token]);
......@@ -395,10 +376,12 @@ class UsersController extends AppController {
$this->viewBuilder()->layout('blank');
$users = $this->Users->find('all',[
'conditions' => [
'Users.token' => $token
'Users.id' => $this->Auth->user('id')
]
])->first();
if ($this->request->is('post')) {
$oldpassword = $this->request->data['oldpassword'];
// pr($this->request->data['oldpassword']);die;
$hasher = new DefaultPasswordHasher();
$password = $this->request->data['password'];
$confirm_password = $this->request->data['confirm_password'];
......@@ -408,7 +391,7 @@ class UsersController extends AppController {
$users = $this->Users->patchEntity($users, $this->request->getData());
$this->Users->save($users);
$this->Flash->success(__('change password success'));
return $this->redirect(['action' => 'signin']);
return $this->redirect(['action' => 'signout']);
} else {
$this->Flash->error(__('Invalid password.'));
return $this->redirect(['action' => 'change-password/'.$token]);
......@@ -417,7 +400,7 @@ class UsersController extends AppController {
$this->set(array('token' => $token, '_serialize' => array('token')));
}
public function change_forgotpassword($token=null)
public function changeForgotpassword($token=null)
{
$this->viewBuilder()->layout('blank');
$users = $this->Users->find('all',[
......@@ -432,9 +415,12 @@ 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());
$this->Users->save($users);
if($this->Users->save($users)){
$this->Flash->success(__('change password success'));
return $this->redirect(['action' => 'signin']);
}
$this->Flash->error(__('Invalid password.'));
return $this->redirect(['action' => 'change_forgotpassword']);
}
$this->set(array('token' => $token, '_serialize' => array('token')));
}
......
......@@ -6,7 +6,7 @@
<!-- <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/'.$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(); ?>
</div>
<div>
......
......@@ -29,7 +29,7 @@
<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="username" id="username" value="" onkeypress="check_notnum();" placeholder="USERNAME" class="form-control-reg border-bottom-from">
<input type="text" name="username" id="username" value="" onkeypress="checkeng();" placeholder="USERNAME" class="form-control-reg border-bottom-from">
</div>
</div>
......@@ -109,7 +109,7 @@
<div class="form-group has-feedback">
<div class="col-md-12">
<label class="label-text-sub"><?php echo __('รหัสผ่าน');?><em>* </em></label>
<input data-toggle="password" data-placement="before" type="password" name="password" id="password" value="" placeholder="********" class="form-control input-lg color-button-border border-bottom-from" style="padding:0px 0px !important;">
<input data-toggle="password" data-placement="before" onkeypress="checkeng();" type="password" name="password" id="password" value="" placeholder="********" class="form-control input-lg color-button-border border-bottom-from" style="padding:0px 0px !important;">
<!--<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>-->
</div>
......@@ -119,7 +119,7 @@
<div class="form-group has-feedback">
<div class="col-md-12">
<label class="label-text-sub"><?php echo __('ยืนยันรหัสผ่าน');?><em>* </em></label>
<input data-toggle="password" data-placement="before" type="password" name="confirm_password" id="confirm_password" value="" placeholder="********" class="form-control input-lg color-button-border border-bottom-from" style="padding:0px 0px !important;">
<input data-toggle="password" data-placement="before" onkeypress="checkeng();" type="password" name="confirm_password" id="confirm_password" value="" placeholder="********" class="form-control input-lg color-button-border border-bottom-from" 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();'>-->
<!--<span class="glyphicon glyphicon-eye-close form-control-feedback" id='message'></span>-->
<span id='message'></span>
......@@ -176,8 +176,34 @@
});
</script>
<script>
// function check_key() {
// e_k=event.keyCode
// alert( 'asdasd')
// if ((k>=65 && k<=90) || (k>=97 && k<=122)){
// return true;
// }else{
// alert("thai");
// return false;
// }
// }
$(document).ready(function() {
// $("#username").on('keyup',function(){
// var $this = $(this);
// if($this.val().length>=4){
// alert(check_key());
// }else{
// //alert("กรุณากรอกชื่อผู้ใช้งานของท่าน");
// // return false;
// }
// });
$("#fremail").on('change',function(){
var email = document.getElementById("fremail").value;
$.post("/Checkemails/checkemail", {email: email}, function(data) {
......@@ -205,6 +231,16 @@
alert("ข้อมูลผิดพลาด กรุณาใส่ข้อมูลที่เป็นตัวอักษรภาษาไทย [ก-ฮ] หรือภาษาอังกฤษให้ถูกต้อง");
}
}
function checkeng()
{
e_k=event.keyCode
if ((e_k >= 48 && e_k<=57) || (e_k>=97 && e_k<=122) || ((e_k>=65 && e_k<=90))) {
e_k = true;
}else{
e_k = false;
alert("กรุณากรอกชือผู้ใช้เป็นเป็นตัวอักษรภาษาอังกฤษตัวเล็กหรือตัวใหญ่และมีหรือไม่มีตัวเลขผสมอยู่");
}
}
function validateForm() {
var firstname = document.getElementById("firstname").value;
......@@ -222,9 +258,9 @@
alert("กรุณากรอกชื่อผู้ใช้งานของท่าน");
return false;
}
if(document.getElementById("username").value.length < 5)
if(document.getElementById("username").value.length < 4 || document.getElementById("username").value.length > 10)
{
alert('กรุณาระบุชื่อผู้ใช้งานอย่างน้อย 5 ตัวอักษร');
alert('กรุณาระบุชื่อผู้ใช้งานความยาว 4-10 ตัวอักษร');
return false;
}
var master_country_id = document.getElementById("master_country_id").value;
......
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