Guest User

Untitled

a guest
Oct 16th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.47 KB | None | 0 0
  1. <body>
  2. <div class="loginbg">
  3. <div class="container">
  4. <div class="row content-area">
  5. <div class="col-md-6 company-profile">
  6. <div id="" class="adminLoginText">
  7. <h1>Admin Login</h1>
  8. </div>
  9. <div id="" class="comapny-text">
  10. <h3>Uni Web Tech</h3>
  11. <p>Website Designing & Development</p>
  12. </div>
  13. </div>
  14. <div class="col-md-6 login-form">
  15. <div id="" class="login-form-area">
  16. <form method="post">
  17. <div class="form-group">
  18. <label for="admin-username">User Name</label>
  19. <input id="admin-username" class="form-control" type="text" name="adminUsername" required>
  20. </div>
  21. <div class="form-group">
  22. <label for="admin-password">Password</label>
  23. <input id="admin-password" class="form-control" type="password" name="adminPassword" required>
  24. </div>
  25. <button type="button" class="btn btn-primary" name="adminLogin" id="adminLogin">Login</button>
  26. </form>
  27. <a href="#">Forgot Password?</a>
  28. <p style="margin-top:30px;text-align:center;color:#ea6957;" id="login-error"></p>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </body>
  35. <script type="text/javascript" src="js/adminloginJs.js"></script>
  36.  
  37. $("document").ready(function(){
  38. $("#adminLogin").click(function(){
  39. var adminUsername = $("#admin-username").val().trim();
  40. var adminPassword = $("#admin-password").val().trim();
  41.  
  42. if(adminUsername != "" && adminPassword != "")
  43. {
  44. $.ajax({
  45. type: 'POST',
  46. url: "ajax/ajaxAdminLogin.php?adminUsername="+adminUsername+"&adminPassword="+adminPassword,
  47. cache:false,
  48. success: function(message){
  49. $("#login-error").text("");
  50. $("#login-error").text(message);
  51. if($("#login-error").text().trim() == "Done"){
  52. window.location.href = "http://localhost/unidashboard/dashboard.php";
  53. }
  54. }
  55. });
  56.  
  57. /*$.post("ajaxAdminLogin.php",{adminUsername: adminUsername, adminPassword: adminPassword})
  58. .done(function(data){
  59. if(data.trim() == "Done"){
  60. window.location = "dashboard.php";
  61. }
  62. else{
  63. $("#login-error").text(data);
  64. }
  65. });*/
  66. }
  67. else
  68. {
  69. $("#login-error").text("");
  70. $("#login-error").text("Please enter Username and Password");
  71. }
  72. });
  73. });
  74.  
  75. <?php
  76. session_start();
  77. /*Uni Web Tech Online Exam DB Connection*/
  78. include("includes/dbConnection.php");
  79. /*Tracking User IP Address*/
  80. function get_ip_address(){
  81. foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key)
  82. {
  83. if (array_key_exists($key, $_SERVER) === true){
  84. foreach (explode(',', $_SERVER[$key]) as $ip){
  85. $ip = trim($ip); // just to be safe
  86. if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false){
  87. return $ip;
  88. }
  89. }
  90. }
  91. }
  92. }
  93. $AdminIPAddress = get_ip_address();
  94.  
  95. $username=$_POST['adminUsername'];
  96. $password=$_POST['adminPassword'];
  97. /* Fetching User Data */
  98. $LoginSql = "select AdminId, Email, Password, Role, Status from adminusers where AdminId = '$username' or Email = '$username'";
  99. $result = $uni_DB_Con->query($LoginSql);
  100.  
  101. if ($result->num_rows > 0) {
  102. // fetching user details
  103. while($row = $result->fetch_assoc()) {
  104. //verifying Enabled or Disabled
  105. if($row['Status'] == "Enable")
  106. {
  107. // verifying username
  108. if($row['AdminId'] == $username || $row['Email'] == $username)
  109. {
  110. if($row['Password'] == $password)
  111. {
  112. $AdminId = $row['AdminId'];
  113.  
  114. /*updating user login status 0 to 1 in users table*/
  115. $loginStatusSql = "UPDATE adminusers SET LoginStatus=1 WHERE AdminId = '$AdminId'";
  116. $uni_DB_Con->query($loginStatusSql);
  117.  
  118. /* Creating session */
  119. $_SESSION["AdminId"] = $AdminId;
  120. $_SESSION["Role"] = $row['Role'];
  121.  
  122. /*Details for Activity*/
  123. $Login = Date("d - F - Y H:i:s");
  124. $loginActivitySql = "INSERT INTO admin_activity(AdminId, AdminIPAddress, Login, Logout) VALUES ('$AdminId','$AdminIPAddress','$Login','0')";
  125.  
  126. $uni_DB_Con->query($loginActivitySql);
  127.  
  128.  
  129. /*After storing login date and time navigating to dashboard page*/
  130. echo "Done"; /*redirect done from adminlogin.js*/
  131. }
  132. else
  133. {
  134. echo "Invalid Password.";
  135. }
  136. }
  137. else
  138. {
  139. echo "Invalid Username.";
  140. }
  141. }
  142. else
  143. {
  144. echo "Sorry, You are disabled. Please contact admin.";
  145. }
  146. }
  147. }
  148. ?>
Add Comment
Please, Sign In to add comment