Advertisement
Guest User

thakur

a guest
Jan 10th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.04 KB | None | 0 0
  1. Priya.18737@sscbs.du.ac.in
  2. password123!
  3. --------------------------------------------------------------------------------------------------------------
  4. apt update
  5. apt upgrade
  6. apt install nodejs
  7. apt install npm
  8. mkdir code
  9. cd code
  10. npm install express-generator -g --save
  11. express -v hbs
  12. npm install
  13. npm install nodemon -g --save
  14. npm install mysql --save
  15. npm start
  16. --------------------------------------------------------------------------------------------------
  17. apt install mysql-server
  18. service mysql start
  19. GRANT ALL PRIVILEGES ON *.* TO 'nitasha'@'localhost' IDENTIFIED BY 'Qwerty@1234';
  20. create database node;
  21. create table users(ID int AUTO_INCREMENT, Username varchar(20) not null, Password varchar(20) not null, PRIMARY KEY(ID));
  22. insert into users(Username, Password) values ('admin', 'admin');
  23. -------------------------------------------------------------------------------------------------------------------
  24. pscp -r -i "D:\aws\abhishek.ppk" D:\aws\code ubuntu@18.224.153.73:
  25. ----------------------------------------------------------------------------------------------------------------------------------------
  26. https://datatables.net/download/
  27. ----------------------------------------------------------------------------------------------------------------------------------------
  28. code/config/database.js
  29. var DataBase = {
  30. host : 'localhost' ,
  31. database : 'node',
  32. user : 'nitasha',
  33. password : 'Qwerty@1234'
  34. }module.exports=DataBase;
  35. ----------------------------------------------------------------------------------------------------------------------------------------
  36. code/routes/index.js
  37.  
  38. var express = require('express');
  39. var router = express.Router();
  40. var DataBase = require('../config/database.js');
  41. var mysql = require('mysql');
  42. var con = mysql.createConnection(DataBase);
  43.  
  44. /* GET home page. */
  45.  
  46.  
  47.  
  48. router.get('/', function(req, res, next) {
  49. res.render('login');
  50. });
  51.  
  52. router.post('/userValid', function(req, res, next) {
  53. console.log(req.body)
  54. data=req.body;
  55. username=data["uname"]; //xss //SQL
  56. password=data["psw"]
  57. con.connect(function(err){
  58. sql ="select * from users where username=\""+username+"\" and password=\""+password+"\"";
  59. con.query(sql,function(err,result){
  60. if (err) throw err;
  61. if (result.length > 0) {
  62. console.log(result)
  63. final1=[]
  64. // res.send(result)
  65. for (let index = 0; index < result.length; index++) {
  66. temp=[]
  67. temp.push(result[index]["FirstName"])
  68. temp.push(result[index]["LastName"])
  69. temp.push(result[index]["Occupation"])
  70. final1.push(temp)
  71.  
  72. }
  73. res.render('dashboard',{ final1})
  74. console.log(final1)
  75. }
  76.  
  77. else
  78. {
  79. res.render('login');
  80. }
  81. })
  82. })
  83. // res.send("Page Working")
  84. });
  85. module.exports = router;
  86. -----------------------------------------------------------------------------------------------------------------------------
  87. code/views/dashboard.hbs
  88.  
  89. <!DOCTYPE html>
  90. <html lang="en">
  91.  
  92. <head>
  93. <title>Page</title>
  94. <link href = "https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" type="text/css" >
  95. <link href= "https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" >
  96.  
  97.  
  98. <script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.3.1.js"></script>
  99. <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
  100. <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
  101.  
  102.  
  103. </head>
  104.  
  105. <body>
  106. <div id="test" class="container-fluid">
  107. <h1 class="text-danger" >
  108. Welcome to dashboard
  109. <small class="text-muted">{{App}}</small>
  110. </h1>
  111. <div id="Fail" >
  112. <table id="example" class="table table-striped table-bordered" style="width:100%">
  113. <thead>
  114. <tr>
  115. <th>First Name</th>
  116. <th>Last Name</th>
  117. <th>Occupation Type</th>
  118. </tr>
  119. </thead>
  120. <tbody>
  121. {{#each final1}}
  122. <tr>
  123. {{#each this}}
  124. <td>{{this}}</td>
  125. {{/each}}
  126. </tr>
  127. {{/each}}
  128. </tbody>
  129. </table>
  130. </div>
  131. </div>
  132. </body>
  133.  
  134. <script type="text/javascript">
  135. $(document).ready(function() {
  136. $('#enter').DataTable();
  137. } );
  138. </html>
  139. ---------------------------------------------------------------------------------------------------------------------------
  140. code/views/login.hbs
  141.  
  142. <!DOCTYPE html>
  143. <html>
  144. <head>
  145. <meta name="viewport" content="width=device-width, initial-scale=1">
  146. <style>
  147. body {font-family: Arial, Helvetica, sans-serif;}
  148.  
  149. /* Full-width input fields */
  150. input[type=text], input[type=password] {
  151. width: 100%;
  152. padding: 12px 20px;
  153. margin: 8px 0;
  154. display: inline-block;
  155. border: 1px solid #ccc;
  156. box-sizing: border-box;
  157. }
  158.  
  159. /* Set a style for all buttons */
  160. button {
  161. background-color: #4CAF50;
  162. color: white;
  163. padding: 14px 20px;
  164. margin: 8px 0;
  165. border: none;
  166. cursor: pointer;
  167. width: 100%;
  168. }
  169.  
  170. button:hover {
  171. opacity: 0.8;
  172. }
  173.  
  174. /* Extra styles for the cancel button */
  175. .cancelbtn {
  176. width: auto;
  177. padding: 10px 18px;
  178. background-color: #f44336;
  179. }
  180.  
  181. /* Center the image and position the close button */
  182. .imgcontainer {
  183. text-align: center;
  184. margin: 24px 0 12px 0;
  185. position: relative;
  186. }
  187.  
  188. img.avatar {
  189. width: 40%;
  190. border-radius: 50%;
  191. }
  192.  
  193. .container {
  194. padding: 16px;
  195. }
  196.  
  197. span.psw {
  198. float: right;
  199. padding-top: 16px;
  200. }
  201.  
  202. /* The Modal (background) */
  203. .modal {
  204. display: none; /* Hidden by default */
  205. position: fixed; /* Stay in place */
  206. z-index: 1; /* Sit on top */
  207. left: 0;
  208. top: 0;
  209. width: 100%; /* Full width */
  210. height: 100%; /* Full height */
  211. overflow: auto; /* Enable scroll if needed */
  212. background-color: rgb(0,0,0); /* Fallback color */
  213. background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
  214. padding-top: 60px;
  215. }
  216.  
  217. /* Modal Content/Box */
  218. .modal-content {
  219. background-color: #fefefe;
  220. margin: 5% auto 15% auto; /* 5% from the top, 15% from the bottom and centered */
  221. border: 1px solid #888;
  222. width: 80%; /* Could be more or less, depending on screen size */
  223. }
  224.  
  225. /* The Close Button (x) */
  226. .close {
  227. position: absolute;
  228. right: 25px;
  229. top: 0;
  230. color: #000;
  231. font-size: 35px;
  232. font-weight: bold;
  233. }
  234.  
  235. .close:hover,
  236. .close:focus {
  237. color: red;
  238. cursor: pointer;
  239. }
  240.  
  241. /* Add Zoom Animation */
  242. .animate {
  243. -webkit-animation: animatezoom 0.6s;
  244. animation: animatezoom 0.6s
  245. }
  246.  
  247. @-webkit-keyframes animatezoom {
  248. from {-webkit-transform: scale(0)}
  249. to {-webkit-transform: scale(1)}
  250. }
  251.  
  252. @keyframes animatezoom {
  253. from {transform: scale(0)}
  254. to {transform: scale(1)}
  255. }
  256.  
  257. /* Change styles for span and cancel button on extra small screens */
  258. @media screen and (max-width: 300px) {
  259. span.psw {
  260. display: block;
  261. float: none;
  262. }
  263. .cancelbtn {
  264. width: 100%;
  265. }
  266. }
  267. </style>
  268. </head>
  269. <body>
  270.  
  271. <h2>Modal Login Form</h2>
  272.  
  273. <button onclick="document.getElementById('id01').style.display='block'" style="width:auto;">Login</button>
  274.  
  275. <div id="id01" class="modal">
  276.  
  277. <form class="modal-content animate" action="/test/userValid" method="POST">
  278. <div class="imgcontainer">
  279. <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span>
  280. <img src="img_avatar2.png" alt="Avatar" class="avatar">
  281. </div>
  282.  
  283. <div class="container">
  284. <label for="uname"><b>Username</b></label>
  285. <input type="text" placeholder="Enter Username" name="uname" required>
  286.  
  287. <label for="psw"><b>Password</b></label>
  288. <input type="password" placeholder="Enter Password" name="psw" required>
  289.  
  290. <button type="submit">Login</button>
  291. <label>
  292. <input type="checkbox" checked="checked" name="remember"> Remember me
  293. </label>
  294. </div>
  295.  
  296. <div class="container" style="background-color:#f1f1f1">
  297. <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button>
  298. <span class="psw">Forgot <a href="#">password?</a></span>
  299. </div>
  300. </form>
  301. </div>
  302.  
  303. <script>
  304. // Get the modal
  305. var modal = document.getElementById('id01');
  306.  
  307. // When the user clicks anywhere outside of the modal, close it
  308. window.onclick = function(event) {
  309. if (event.target == modal) {
  310. modal.style.display = "none";
  311. }
  312. }
  313. </script>
  314.  
  315. </body>
  316. </html>
  317. --------------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement