mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/ARCHIVED-IZYIM.git
synced 2026-08-19 04:14:01 +00:00
added forgot password feature
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
/* Hotjar */
|
||||
(function(h,o,t,j,a,r){
|
||||
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
||||
h._hjSettings={hjid:807847,hjsv:6};
|
||||
a=o.getElementsByTagName('head')[0];
|
||||
r=o.createElement('script');r.async=1;
|
||||
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
||||
a.appendChild(r);
|
||||
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
||||
|
||||
|
||||
/* Drift */
|
||||
!function() {
|
||||
var t;
|
||||
if (t = window.driftt = window.drift = window.driftt || [], !t.init) return t.invoked ? void (window.console && console.error && console.error("Drift snippet included twice.")) : (t.invoked = !0,
|
||||
t.methods = [ "identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on" ],
|
||||
t.factory = function(e) {
|
||||
return function() {
|
||||
var n;
|
||||
return n = Array.prototype.slice.call(arguments), n.unshift(e), t.push(n), t;
|
||||
};
|
||||
}, t.methods.forEach(function(e) {
|
||||
t[e] = t.factory(e);
|
||||
}), t.load = function(t) {
|
||||
var e, n, o, i;
|
||||
e = 3e5, i = Math.ceil(new Date() / e) * e, o = document.createElement("script"),
|
||||
o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous", o.src = "https://js.driftt.com/include/" + i + "/" + t + ".js",
|
||||
n = document.getElementsByTagName("script")[0], n.parentNode.insertBefore(o, n);
|
||||
});
|
||||
}();
|
||||
drift.SNIPPET_VERSION = '0.3.1';
|
||||
drift.load('bua4t3vtn9g5');
|
||||
|
||||
$.urlParam = function(name){
|
||||
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
|
||||
if (results==null){
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
return decodeURI(results[1]) || 0;
|
||||
}
|
||||
}
|
||||
|
||||
var Script = function () {
|
||||
$.validator.setDefaults({
|
||||
submitHandler: function() {
|
||||
var password=$("#password").val();
|
||||
var confirm_password=$("#confirm-password").val();
|
||||
var reset_token= $.urlParam('reset-token');
|
||||
var dataString = 'password=' + password + '&confirm_password=' + confirm_password + '&reset_token=' +reset_token;
|
||||
console.log(dataString);
|
||||
if ($.trim(password).length > 0){
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/reset-password/reset",
|
||||
data: dataString,
|
||||
cache: false,
|
||||
beforeSend: function(){
|
||||
$("#status").html('<p>Connecting to server....</p>');
|
||||
},
|
||||
complete: function(e, xhr, settings){
|
||||
if(e.status === 200){
|
||||
$("#status").html("<span style='color: #00CC96;'>Success:</span> Redirecting to login.");
|
||||
setTimeout(function () {
|
||||
window.location.href = "/dashboard"; // The URL that will be redirected too.
|
||||
}, 3000);
|
||||
}else{
|
||||
//Shake animation effect.
|
||||
$('form').shake();
|
||||
$("#status").html("<span style='color:#cc0000'>Error:</span> Please contact support. ");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$().ready(function() {
|
||||
$("#register-form").validate({
|
||||
doNotHideMessage: true,
|
||||
errorElement: 'span', //default input error message container
|
||||
errorClass: 'help-block help-block-error', // default input error message class
|
||||
focusInvalid: false,
|
||||
rules: {
|
||||
password: {
|
||||
required: true
|
||||
},
|
||||
|
||||
},
|
||||
messages: {
|
||||
|
||||
password: {
|
||||
required: 'password field is required!',
|
||||
},
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// checks form for validity
|
||||
|
||||
// propose username by combining first- and lastname
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}();
|
||||
+1
-1
@@ -30,7 +30,7 @@ include_once 'func.class/general.func.php';
|
||||
include_once 'func.class/core.func.php';
|
||||
|
||||
// Redirect to Login if Match the rule
|
||||
if ($_SERVER["REQUEST_URI"] != "/register" && $_SERVER["REQUEST_URI"] != "/register/send-verification" && $_SERVER["REQUEST_URI"] != "/register/check-verification" && $_SERVER["REQUEST_URI"] != "/register/submit" && $_SERVER["REQUEST_URI"] != "/register/check" && $_SERVER["REQUEST_URI"] != "/register/check" && $_SERVER["REQUEST_URI"] != "/forgot-password/reset" && $_SERVER["REQUEST_URI"] != "/forgot-password" && $_SERVER["REQUEST_URI"] != '/login' && $_SERVER["REQUEST_URI"] != '/login/auth' && !is_login()) {
|
||||
if (!preg_match("/reset-password?(\w+)/", $_SERVER["REQUEST_URI"] ) && $_SERVER["REQUEST_URI"] != "/register" && $_SERVER["REQUEST_URI"] != "/register/send-verification" && $_SERVER["REQUEST_URI"] != "/register/check-verification" && $_SERVER["REQUEST_URI"] != "/register/submit" && $_SERVER["REQUEST_URI"] != "/register/check" && $_SERVER["REQUEST_URI"] != "/register/check" && $_SERVER["REQUEST_URI"] != "/forgot-password/reset" && $_SERVER["REQUEST_URI"] != "/forgot-password" && $_SERVER["REQUEST_URI"] != '/login' && $_SERVER["REQUEST_URI"] != '/login/auth' && !is_login()) {
|
||||
header('Location: /login');
|
||||
} else {
|
||||
// Call the Silex after logged in
|
||||
|
||||
@@ -85,18 +85,34 @@ $app->post('/login/auth', function (Request $request) {
|
||||
});
|
||||
$app->post('/forgot-password/reset', function (Request $request) {
|
||||
global $db;
|
||||
global $global_env;
|
||||
global $global_env;
|
||||
global $twilio;
|
||||
|
||||
$username = $request->get('username');
|
||||
|
||||
$db->bind("username", $username);
|
||||
$users = $db->query("SELECT * FROM users WHERE username= :username && status = 1");
|
||||
$users = $db->query("SELECT * FROM users WHERE username= :username && status = 1");
|
||||
|
||||
if (count($users) > 0) {
|
||||
$newPwd = xToken(6);
|
||||
$encrypt = $newPwd;
|
||||
// SETELAH DAPAT PASSWORD UPDATE DULU
|
||||
$db->bind('password', $encrypt);
|
||||
# generate unique reset token
|
||||
$reset_token = md5(uniqid($users[0]["user_id"], true));
|
||||
|
||||
# update user with reset token
|
||||
$db->bind('reset_token', $reset_token);
|
||||
$db->bind('username', $username);
|
||||
$update = $db->query("UPDATE users SET password = :password WHERE username = :username");
|
||||
if ($update) {
|
||||
$update = $db->query("UPDATE users SET reset_token = :reset_token WHERE username = :username");
|
||||
if ($update) {
|
||||
# password recovery link
|
||||
$recovery_link = "https://app.izyim.com/reset-password?reset-token=".$reset_token;
|
||||
# send link to SMS
|
||||
$twilio->messages->create(
|
||||
$username,
|
||||
array(
|
||||
'from' => '+601130115722',
|
||||
'body' => 'Your IZIM password recovery link ' .$recovery_link. ' '
|
||||
)
|
||||
);
|
||||
// end todo
|
||||
return new Response('Success', 200);
|
||||
} else {
|
||||
return new Response('Failed', 201);
|
||||
@@ -107,6 +123,38 @@ $app->post('/forgot-password/reset', function (Request $request) {
|
||||
}
|
||||
});
|
||||
|
||||
$app->post('/reset-password/reset', function (Request $request) {
|
||||
global $db;
|
||||
global $global_env;
|
||||
$password = $request->get('password');
|
||||
$confirm_password = $request->get('confirm_password');
|
||||
$reset_token = $request->get('reset_token');
|
||||
|
||||
# check if token exist
|
||||
$db->bind("reset_token", $reset_token);
|
||||
$users = $db->query("SELECT * FROM users WHERE status = 1 && reset_token= :reset_token");
|
||||
|
||||
if (count($users) > 0) {
|
||||
# check confirm password
|
||||
if ($password != $confirm_password){
|
||||
return new Response('Failed, password and confirm is not the same', 201);
|
||||
}
|
||||
# update user password
|
||||
$e_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$db->bind('password', $e_password);
|
||||
$db->bind('reset_token', $reset_token);
|
||||
$update = $db->query("UPDATE users SET password = :password WHERE reset_token = :reset_token");
|
||||
|
||||
if ($update) {
|
||||
return new Response('Success', 200);
|
||||
} else {
|
||||
return new Response('Failed', 201);
|
||||
}
|
||||
} else {
|
||||
return new Response('Invalid token.', 201);
|
||||
}
|
||||
});
|
||||
|
||||
$app->post('/register/check', function(Request $request) {
|
||||
global $db;
|
||||
$username = $request->get('username');
|
||||
@@ -138,8 +186,8 @@ $app->post('/register/check-verification', function(Request $request) {
|
||||
|
||||
$app->post('/register/send-verification', function(Request $request) {
|
||||
global $db;
|
||||
|
||||
global $twilio;
|
||||
global $twilio;
|
||||
|
||||
$username = $request->get('username');
|
||||
$verification_code = mt_rand(100000,999999);
|
||||
|
||||
@@ -219,7 +267,19 @@ $app->get('/login', function() {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
$app->get('/forgot-password', function() {
|
||||
global $app;
|
||||
$title = "IZYIM - Reset Password";
|
||||
if (is_login()) {
|
||||
return $app->redirect('/dashboard');
|
||||
} else {
|
||||
require_once __DIR__ . '/../tpl/forgot.php';
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
$app->get('/reset-password', function() {
|
||||
global $app;
|
||||
$title = "IZYIM - Reset Password";
|
||||
if (is_login()) {
|
||||
@@ -229,6 +289,7 @@ $app->get('/forgot-password', function() {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
$app->get('/register', function() {
|
||||
global $app;
|
||||
$title = "IZYIM - Registration";
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Time : 13:55:05
|
||||
SQLSTATE[HY093]: Invalid parameter number
|
||||
Raw SQL : SELECT * FROM users WHERE username= :username && status = 1 && reset_token= :reset_token
|
||||
@@ -0,0 +1,85 @@
|
||||
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
|
||||
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
|
||||
<!--[if !IE]><!-->
|
||||
<html>
|
||||
<!--<![endif]-->
|
||||
<!-- BEGIN HEAD -->
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>IZYIM | Register</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta content="width=device-width, initial-scale=1" name="viewport" />
|
||||
<meta content="" name="description" />
|
||||
<meta content="" name="author" />
|
||||
<!-- BEGIN GLOBAL MANDATORY STYLES -->
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />
|
||||
<link href="/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="/assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="/assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />
|
||||
<!-- END GLOBAL MANDATORY STYLES -->
|
||||
<!-- BEGIN PAGE LEVEL PLUGINS -->
|
||||
<link href="/assets/global/plugins/select2/css/select2.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="/assets/global/plugins/select2/css/select2-bootstrap.min.css" rel="stylesheet" type="text/css" />
|
||||
<!-- END PAGE LEVEL PLUGINS -->
|
||||
<!-- BEGIN THEME GLOBAL STYLES -->
|
||||
<link href="/assets/global/css/components.min.css" rel="stylesheet" id="style_components" type="text/css" />
|
||||
<link href="/assets/global/css/plugins.min.css" rel="stylesheet" type="text/css" />
|
||||
<!-- END THEME GLOBAL STYLES -->
|
||||
<!-- BEGIN PAGE LEVEL STYLES -->
|
||||
<link href="/assets/modul-css/login/login.min.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<!-- END HEAD -->
|
||||
|
||||
<body class=" login">
|
||||
<div class="content">
|
||||
<!-- BEGIN LOGIN FORM -->
|
||||
<form class="register-form" id="register-form" >
|
||||
<h3 class="font-green">Password Recovery</h3>
|
||||
<p class="hint"> Please provide your username to recover your password, we will send you an sms for the new password. </p>
|
||||
<div id="status" style="margin-top: 15px;margin-bottom: 15px;"></div>
|
||||
<div class="form-group">
|
||||
<input class="form-control placeholder-no-fix" type="text" placeholder="Mobile No." name="username" id="username" /> </div>
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="/login" class="btn green btn-outline">Back</a>
|
||||
<button type="submit" id="register" class="btn btn-success uppercase pull-right">Submit</button>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
<!-- END LOGIN FORM -->
|
||||
|
||||
|
||||
|
||||
<!--[if lt IE 9]>
|
||||
<script src="/assets/global/plugins/respond.min.js"></script>
|
||||
<script src="/assets/global/plugins/excanvas.min.js"></script>
|
||||
<![endif]-->
|
||||
<!-- BEGIN CORE PLUGINS -->
|
||||
<script src="/assets/global/plugins/jquery.min.js" type="text/javascript"></script>
|
||||
<script src="/assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
|
||||
<script src="/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
|
||||
<script src="/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
|
||||
<script src="/assets/global/plugins/jquery.blockui.min.js" type="text/javascript"></script>
|
||||
<script src="/assets/global/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>
|
||||
<script src="/assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js" type="text/javascript"></script>
|
||||
<!-- END CORE PLUGINS -->
|
||||
<!-- BEGIN PAGE LEVEL PLUGINS -->
|
||||
<script src="/assets/global/plugins/jquery-validation/js/jquery.validate.min.js" type="text/javascript"></script>
|
||||
<script src="/assets/global/plugins/jquery-validation/js/additional-methods.min.js" type="text/javascript"></script>
|
||||
<script src="/assets/global/plugins/backstretch/jquery.backstretch.min.js" type="text/javascript"></script>
|
||||
<!-- END PAGE LEVEL PLUGINS -->
|
||||
<!-- BEGIN THEME GLOBAL SCRIPTS -->
|
||||
<script src="/assets/global/scripts/app.min.js" type="text/javascript"></script>
|
||||
<!-- END THEME GLOBAL SCRIPTS -->
|
||||
<!-- BEGIN PAGE LEVEL SCRIPTS -->
|
||||
<script type="text/javascript" src="/assets/modul-js/jquery.ui.shake.js"></script><!-- TOKENIZE -->
|
||||
<script type="text/javascript" src="/assets/modul-js/forgot-password.js"></script>
|
||||
|
||||
<!-- END PAGE LEVEL SCRIPTS -->
|
||||
<!-- BEGIN THEME LAYOUT SCRIPTS -->
|
||||
<!-- END THEME LAYOUT SCRIPTS -->
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -36,16 +36,20 @@
|
||||
<div class="content">
|
||||
<!-- BEGIN LOGIN FORM -->
|
||||
<form class="register-form" id="register-form" >
|
||||
<h3 class="font-green">Password Recovery</h3>
|
||||
<p class="hint"> Please provide your username to recover your password, we will send you an sms for the new password. </p>
|
||||
<h3 class="font-green">Reset Recovery</h3>
|
||||
<p class="hint"> Please enter your new password </p>
|
||||
<div id="status" style="margin-top: 15px;margin-bottom: 15px;"></div>
|
||||
<div class="form-group">
|
||||
<input class="form-control placeholder-no-fix" type="text" placeholder="Mobile No." name="username" id="username" /> </div>
|
||||
|
||||
<input class="form-control placeholder-no-fix" type="password" placeholder="password" name="password" id="password" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input class="form-control placeholder-no-fix" type="password" placeholder="confirm password" name="confirm-password" id="confirm-password" />
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="/login" class="btn green btn-outline">Back</a>
|
||||
<button type="submit" id="register" class="btn btn-success uppercase pull-right">Submit</button>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
<!-- END LOGIN FORM -->
|
||||
@@ -75,7 +79,7 @@
|
||||
<!-- END THEME GLOBAL SCRIPTS -->
|
||||
<!-- BEGIN PAGE LEVEL SCRIPTS -->
|
||||
<script type="text/javascript" src="/assets/modul-js/jquery.ui.shake.js"></script><!-- TOKENIZE -->
|
||||
<script type="text/javascript" src="/assets/modul-js/forgot-password.js"></script>
|
||||
<script type="text/javascript" src="/assets/modul-js/reset-password.js"></script>
|
||||
|
||||
<!-- END PAGE LEVEL SCRIPTS -->
|
||||
<!-- BEGIN THEME LAYOUT SCRIPTS -->
|
||||
|
||||
Reference in New Issue
Block a user