· 5 years ago · Feb 11, 2020, 01:04 PM
1//html
2<?php
3 session_start();
4 include 'config.php';
5
6try {
7 $query = 'SELECT 1 FROM users LIMIT 1';
8 $statement = $db->prepare($query);
9 $statement->execute();
10} catch (Exception $e) {
11 // If Users table doesn't exist then redirect to install page
12 header('location:install.php');
13}
14
15// user SESSION CHECK SET OR NOT
16if (isset($_SESSION['username'])) {
17 if(isset($_SESSION['table']) && $_SESSION['table']== 'admin'){
18 header('location:admin/');
19 }
20 else if(isset($_SESSEION['first']) && $_SESSION['first'] != 'true')
21 {
22 $_SESSEION['first'] == 'true';
23 header('https://maysur.com/app/' );
24 }
25 else{
26 header('https://maysur.com/app/' );
27 //header('location:user/dashboard.php' );
28 }
29 exit();
30}
31else if(isset($_COOKIE['username']) && isset($_COOKIE['userPassword'])) {
32 $_SESSION['username'] = $_COOKIE['username'];
33 $_SESSION['name'] = $_COOKIE['name'];
34 $_SESSION['table'] = $_COOKIE['table'];
35 $_SESSEION['first'] == 'true';
36 header('https://maysur.com/app/' );
37 //header('location:user/dashboard.php');
38 exit();
39}
40?>
41<!DOCTYPE html>
42<!--[if lt IE 7]>
43<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
44<!--[if IE 7]>
45<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
46<!--[if IE 8]>
47<html class="no-js lt-ie9"> <![endif]-->
48<!--[if gt IE 8]><!-->
49<html class="no-js"> <!--<![endif]-->
50<head>
51
52 <title>User Panel | Login</title>
53 <meta charset="utf-8">
54 <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
55
56 <!---CSS FILES -->
57
58 <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />
59 <link href="assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
60 <link href="assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
61 <link href="assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
62 <!-- END GLOBAL MANDATORY STYLES -->
63 <!-- BEGIN PAGE LEVEL PLUGINS -->
64 <link href="assets/css/login.css" rel="stylesheet" type="text/css" />
65
66 <!-- END PAGE LEVEL PLUGINS -->
67 <!-- BEGIN THEME GLOBAL STYLES -->
68 <link href="assets/css/components-md.css" rel="stylesheet" id="style_components" type="text/css" />
69 <link href="assets/css/plugins-md.css" rel="stylesheet" type="text/css" />
70 <!-- END THEME GLOBAL STYLES -->
71 <!-- BEGIN PAGE LEVEL STYLES -->
72 <link href="assets/plugins/froiden-helper/helper.css" rel="stylesheet" type="text/css" />
73 <link href="assets/css/custom.css" rel="stylesheet" type="text/css" />
74 <!---END OF CSS FILES -->
75
76</head>
77<body class="login">
78<!-- BEGIN LOGO -->
79<div class="logo">
80 <a href="javascript:;">
81<!-- <img src="assets/img/logos/logo-big.png" alt="" /> -->
82 Maysur
83 </a>
84</div>
85<!-- END LOGO -->
86<!-- BEGIN LOGIN -->
87<div class="content">
88 <!-- BEGIN LOGIN FORM -->
89 <form class="login-form" method="POST" autocomplete="off">
90 <h3 class="form-title font-green">Sign In</h3>
91 <div id="error"></div>
92 <div class="form-group form-md-line-input">
93 <!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
94 <label class="control-label visible-ie8 visible-ie9">Username</label>
95 <input class="form-control" type="text" placeholder="Username" name="username" id="username" autocomplete="new-username"/>
96 <span class="help-block help-block-error"> </span>
97 <div class="form-control-focus"> </div>
98 </div>
99 <div class="form-group form-md-line-input">
100 <label class="control-label visible-ie8 visible-ie9">Password</label>
101 <input class="form-control" type="password" placeholder="Password" name="password" id="password" autocomplete="new-password"/>
102 <span class="help-block help-block-error"> </span>
103 <div class="form-control-focus"> </div>
104 </div>
105 <div class="form-actions">
106 <button type="submit" class="btn green uppercase btn-xs btn-outline" onclick="login();return false;">Login</button>
107 <span class="md-checkbox has-success m-l-20">
108 <input type="checkbox" id="remember" class="md-check" name="remember" value="1" />
109 <label for="remember">
110 <span class="inc"></span>
111 <span class="check"></span>
112 <span class="box"></span> Remember </label>
113 </span>
114 <a href="javascript:;" id="forget-password" class="forget-password">Forgot Password?</a>
115 </div>
116
117 <div class="create-account">
118 <p>
119 <a href="javascript:;" id="register-btn" class="uppercase">Create an account</a>
120 </p>
121 </div>
122 </form>
123 <!-- END LOGIN FORM -->
124 <!-- BEGIN FORGOT PASSWORD FORM -->
125 <form class="forget-form">
126 <h3 class="font-green">Forget Password ?</h3>
127 <p> Enter your username address below to reset your password. </p>
128 <div id="errorForget"></div>
129 <div class="form-group form-md-line-input forget">
130 <input class="form-control placeholder-no-fix" type="text" placeholder="username" name="usernameForget" id="usernameForget"/>
131 <div class="form-control-focus"> </div>
132 </div>
133 <div class="form-actions">
134 <button type="button" id="back-btn" class="btn dark btn-outline">Back</button>
135 <button type="submit" class="btn green uppercase btn-outline pull-right forget" onclick="forget();return false;" id="forget-btn">Submit</button>
136 </div>
137 </form>
138 <!-- END FORGOT PASSWORD FORM -->
139 <!-- BEGIN REGISTRATION FORM -->
140
141 <form class="register-form">
142
143 <h3 class="font-green">Sign Up</h3>
144 <div id="errorRegister"></div>
145 <p class="hint"> Enter your details below: </p>
146 <div class="form-group form-md-line-input register">
147 <input class="form-control" type="text" placeholder="Name" name="nameRegister" id="nameRegister"/>
148 <label class="control-label visible-ie8 visible-ie9">Name</label>
149 <span class="form-control-focus"> </span>
150 </div>
151 <div class="form-group form-md-line-input register">
152 <!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
153 <input class="form-control placeholder-no-fix" type="text" placeholder="Username" name="usernameRegister" id="usernameRegister" />
154 <label class="control-label visible-ie8 visible-ie9">Username</label>
155 <span class="form-control-focus"> </span>
156 </div>
157 <div class="form-group form-md-line-input register">
158 <input class="form-control" type="password" id="passwordRegister" placeholder="Password" name="passwordRegister" />
159 <label class="control-label visible-ie8 visible-ie9">Password</label>
160 <span class="form-control-focus"> </span>
161 </div>
162 <div class="form-group form-md-line-input register">
163 <input class="form-control" type="password" placeholder="Re-type Your Password" name="cpasswordRegister" id="cpasswordRegister"/>
164 <label class="control-label visible-ie8 visible-ie9">Re-type Your Password</label>
165 <span class="form-control-focus"> </span>
166 </div>
167 <div class="form-group form-md-line-input register">
168 <input class="form-control" type="email" placeholder="Email" name="emailRegister" id="emailRegister"/>
169 <label class="control-label visible-ie8 visible-ie9">Email</label>
170 <span class="form-control-focus"> </span>
171 </div>
172 <div class="form-group form-md-line-input register">
173 <label class="qstn1">Do you have an online store? </label>
174 <div class="input-group-btn">
175 <button type="button" class="btn btn-default dropdown-toggle singup-dropdown btn-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Choose your answer <span class="caret signup-caret"></span></button>
176 <ul class="dropdown-menu dropdown-menu-right">
177 <li><a data-index"0" data-value="yes">Yes, I have an online store.</a></li>
178 <li><a data-index"1" data-value="no">No, I don't have a store.</a></li>
179 </ul>
180 </div>
181 </div>
182
183 <div class="form-group register">
184 <label class="control-label visible-ie8 visible-ie9">Recaptcha</label>
185 <div class="g-recaptcha" data-sitekey="<?php echo $siteKey; ?>"></div>
186 </div>
187 <div class="form-actions">
188 <button type="button" id="register-back-btn" class="btn dark btn-outline">Back</button>
189 <button type="submit" id="register-submit-btn" class="btn green uppercase btn-outline pull-right register" onclick="register();return false;">Submit</button>
190 </div>
191 </form>
192 <!-- END REGISTRATION FORM -->
193</div>
194
195<script src="assets/global/plugins/respond.min.js"></script>
196<script src="assets/global/plugins/excanvas.min.js"></script>
197<script src="assets/global/plugins/ie8.fix.min.js"></script>
198<![endif]-->
199<!-- BEGIN CORE PLUGINS -->
200<script src="assets/global/plugins/jquery.min.js" type="text/javascript"></script>
201<script src="assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
202<!-- END CORE PLUGINS -->
203<!-- BEGIN PAGE LEVEL PLUGINS -->
204
205<script src="assets/global/plugins/backstretch/jquery.backstretch.min.js" type="text/javascript"></script>
206<script src='https://www.google.com/recaptcha/api.js'></script>
207<!-- END PAGE LEVEL PLUGINS -->
208<!-- BEGIN THEME GLOBAL SCRIPTS -->
209<script src="assets/global/app.min.js" type="text/javascript"></script>
210<script src="assets/plugins/froiden-helper/helper.js" type="text/javascript"></script>
211<!-- END THEME GLOBAL SCRIPTS -->
212
213<script>
214//$('.dropdown-toggle').dropdown();
215 //$(document).ready(function() {
216//$('.mdb-select').materialSelect();
217//});
218
219 jQuery('#forget-password').click(function() {
220 jQuery('.login-form').hide();
221 jQuery('.forget-form').show();
222 $('.forget').each(function () {
223 $(this).removeClass('hide').addClass('show');
224 $('.forget-form').trigger("reset");
225 $('#alert').addClass('hide');
226 });
227 });
228
229 jQuery('#back-btn').click(function() {
230 jQuery('.login-form').show();
231 jQuery('.forget-form').hide();
232 });
233 jQuery('#register-btn').click(function() {
234 jQuery('.login-form').hide();
235 jQuery('.register-form').show();
236 $('.register').each(function () {
237 $(this).removeClass('hide').addClass('show');
238 $('.register-form').trigger("reset");
239 $('#alert').addClass('hide');
240 });
241 });
242
243 jQuery('#register-back-btn').click(function() {
244 jQuery('.login-form').show();
245 jQuery('.register-form').hide();
246 });
247
248 jQuery(".dropdown-menu").on('click', 'li a', function(){
249 jQuery(".btn-dropdown:first-child").html($(this).text()+'<span class="caret signup-caret"></span>');
250 jQuery(".btn-dropdown:first-child").val($(this).text());
251 });
252
253
254
255
256 // Login Function
257 function login() {
258 $.easyAjax({
259 url: "ajax/login.php",
260 type: "POST",
261 data: $(".login-form").serialize(),
262 container: ".login-form",
263 messagePosition: "inline"
264 });
265 }
266
267 // Forget Password Function
268 function forget() {
269 $.easyAjax({
270 url: "ajax/forget.php",
271 type: "POST",
272 data: $(".forget-form").serialize(),
273 container: ".forget-form",
274 messagePosition: "inline",
275 success: function (response) {
276 if (response.status == "success") {
277 $('.forget').each(function () {
278 $(this).removeClass('show').addClass('hide');
279 });
280
281 }
282 }
283 });
284 }
285
286 // Register Function
287 function register() {
288 $.easyAjax({
289 url: "ajax/register.php",
290 type: "POST",
291 data: $(".register-form").serialize(),
292 container: ".register-form",
293 messagePosition: "inline",
294 success: function (response) {
295 if (response.status == "success") {
296 $('.register').each(function () {
297 $(this).removeClass('show').addClass('hide');
298 });
299
300 }
301 }
302 });
303 }
304
305</script>
306</body>
307</html>
308
309
310
311//register.php
312<?php
313 session_start();
314 include '../config.php';
315 $smtp = include '../smtp.php';
316 error_reporting(0);
317 require '../assets/PHPMailer/PHPMailerAutoload.php';
318
319 $captcha = post('g-recaptcha-response');
320
321 $googleUrl = 'https://www.google.com/recaptcha/api/siteverify';
322 $secret = $secretKey;
323 $ip = $_SERVER['REMOTE_ADDR'];
324 $url = $googleUrl . '?secret=' . $secret . '&response=' . $captcha . '&remoteip=' . $ip;
325 $res = getCurlData($url);
326 $res = json_decode($res, true);
327
328 // Set base url
329 // $baseUrl = preg_replace('/\/ajax\/register.php/', '', $_SERVER['PHP_SELF']);
330
331// Server side validation
332
333if (empty($captcha)) {
334
335 $output = responseError('Please Enter the Captcha');
336 die(json_encode($output));
337
338}
339
340$output = [];
341$input['passwordRegister'] = post('password');
342
343$input = [];
344$input['nameRegister'] = post('nameRegister');
345$input['usernameRegister'] = post('usernameRegister');
346$input['emailRegister'] = post('emailRegister');
347$input['passwordRegister'] = post('passwordRegister');;
348$input['cpasswordRegister'] = post('cpasswordRegister');;
349
350$output = responseFormErrors($input);
351
352
353if($output['error']) {
354
355 foreach ($output['errors'] as $key => $out) {
356
357 $output['errors'][$key] = preg_replace('/Register/', '', $out[0]);
358
359 if($key == 'cpasswordRegister') {
360 $output['errors'][$key] = preg_replace('/c/', 'confirm ', $output['errors'][$key]);
361 }
362 }
363
364 echo json_encode($output);
365 die;
366}
367
368// Check password and confirm password match or not
369else if ($input['cpasswordRegister'] != $input['passwordRegister']) {
370 $output['errors']['passwordRegister'] = 'Password and confirm password do not match';
371 $output['status'] = 'fail';
372}
373else if (!filter_var($input['emailRegister'], FILTER_VALIDATE_EMAIL)) {
374
375 $output['errors']['emailRegister'] = 'Enter correct Email ID';
376 $output['status'] = 'fail';
377 echo json_encode($output);
378 die;
379}
380// Insert the data into the database
381else {
382
383 // SELECT MATCH FROM THE DATABASE
384 $query = 'SELECT * FROM `users` where username=?';
385 $statement = $db->prepare($query);
386 $statement->execute(array($input['usernameRegister']));
387
388 if ($statement->rowCount() > 0) {
389
390 $output['errors']['usernameRegister'] = 'Username Already exists.Try another username.';
391 $output['status'] = 'fail';
392 echo json_encode($output);
393 die;
394
395 } else {
396
397 // Generate key for email verification
398 $key = sha1($encryptionKey . $input['usernameRegister'] . $input['emailRegister']);
399
400 // Encrypt password according to encryption type defined in config.php
401 if($encryptionType == 'sha1') {
402 $input['passwordRegister'] = sha1($input['passwordRegister']);
403 }
404 elseif ($encryptionType == 'md5') {
405 $input['passwordRegister'] = md5($input['passwordRegister']);
406 }
407
408 $query = 'INSERT INTO `users` SET username=? , password =? , name = ? ,email = ?,`key` = ?,status = ?,email_verified =?';
409 $parameters = array($input['usernameRegister'], $input['passwordRegister'], $input['nameRegister'], $input['emailRegister'], $key, 'enable', 'no');
410
411 $statement = $db->prepare($query);
412 $statement->execute($parameters);
413
414
415 // Email verification
416 $mail = new PHPMailer(); // create a new object
417 $mail->IsHTML(true);
418 $mail->WordWrap = 50; // Set word wrap to 50 characters
419
420 // Check E-mail verification is true or false
421 if($emailVerification) {
422 // If Smtp is set true. Then the email will be sent using smtp
423 if ($GLOBALS['SMTP'] == true) {
424 $mail->IsSMTP(); // enable SMTP
425 $mail->SMTPAuth = true; // authentication enabled
426 $mail->SMTPSecure = $smtp['encryption']; // secure transfer enabled REQUIRED for Gmail
427 $mail->Host = $smtp['host'];
428 $mail->Port = $smtp['port']; // or 587
429 $mail->Username = $smtp['username'];
430 $mail->Password = $smtp['password'];
431 $mail->From = $smtp['from']['address'];
432 $mail->FromName = $smtp['from']['name'];
433 }
434 else {
435 $mail->SetFrom($fromAddress);
436 }
437
438 $template = file_get_contents('../email_template.php');
439 $body = 'Welcome <strong>'.$input['nameRegister'].'</strong>,
440 <br>
441 Thank you for signing up!
442 <br>
443 <br>
444 Your account has been created, you can login to your account after you have activated your account by pressing the url below.
445 <br>
446 <br>
447
448 Please click on the link below or copy it into your browser address line:<br>
449 <a href='.$baseUrl.'/confirm.php?key='.$key.'>'.$baseUrl.'/confirm.php?key='.$key.'</a>
450 ';
451
452 $mail->addAddress($input['emailRegister'], $input['emailRegister']); // Add a recipient
453 $mail->Subject = 'Confirm Your Email Address';
454 $mail->Body = str_replace('#BODY#', $body, $template);
455
456 if (!$mail->send()) {
457 $output = responseSuccess($mail->ErrorInfo);
458
459 } else {
460 $output = responseSuccess('success');
461
462 }
463
464 // End email verification
465 $output = responseSuccess('Mail sent to your email.Please verify your email to get Registered');
466 }
467 else {
468
469 $output = responseSuccess('User successfully registered');
470
471 }
472 }
473}
474 echo json_encode($output);
475?>