Advertisement
Guest User

Untitled

a guest
Mar 14th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  9. <title>Login</title>
  10.  
  11. <!-- Bootstrap -->
  12. <link href="css/bootstrap.min.css" rel="stylesheet">
  13.  
  14. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  15. <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  16. <!--[if lt IE 9]>
  17. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  18. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  19. <![endif]-->
  20. <!-- Angular -->
  21. <script src="js/angular.min.js"></script>
  22. </head>
  23.  
  24. <body ng-app="myApp">
  25. <div class="container">
  26. <div class="row">
  27. <div class="col-md-12">
  28. <!-- Code start here -->
  29. <h1 class="page-header">Login</h1>
  30. <div ng-controller="myController">
  31. <!-- Form-->
  32. <!-- novalidate is to prevent modern browser to validate so our awesome angular code will validate the form-->
  33. <form name="loginForm" ng-submit="submitForm(loginForm.$valid)" novalidate>
  34. <div class="col-md-6 col-md-offset-3 well">
  35. <div class="form-group">
  36. <label>Username</label>
  37. <input type="text" name="username" class="form-control" ng-model="username" required>
  38. <p ng-show="loginForm.username.$invalid && !loginForm.username.$pristine" class="help-block">Username is required.</p>
  39. </div>
  40.  
  41. <div class="form-group">
  42. <label>Password</label>
  43. <input type="password" name="password" class="form-control" ng-model="password" ng-minlength="5" ng-maxlength="14">
  44. <p ng-show="loginForm.password.$error.minlength" class="help-block">Password is too short.</p>
  45. <p ng-show="loginForm.password.$error.maxlength" class="help-block">Password is too long.</p>
  46. </div>
  47.  
  48. <button type="submit" class="btn btn-primary btn-block">Login</button>
  49. <br>
  50.  
  51. <!-- Notification -->
  52. <div ng-show="notificationDisplayed">
  53. <div class="alert alert-{{ notificationColor }} alert-dismissible" role="alert">
  54. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  55. <strong>{{ notificationTitle }}!</strong> {{ message }}
  56. </div>
  57. </div>
  58. </div>
  59. </form>
  60. </div>
  61. {{ test }}
  62. <!-- Code end here -->
  63. </div>
  64. </div>
  65. </div>
  66.  
  67. <!-- Angular JS Code Start Here -->
  68. <script>
  69. var app = angular.module('myApp', []);
  70.  
  71. app.controller('myController', function($scope, $http, $timeout) {
  72. $scope.notificationDisplayed = false;
  73.  
  74. $scope.submitForm = function(isValid) {
  75. if (isValid) {
  76. $scope.check_credentials();
  77. // alert('yay');
  78. }
  79. }
  80.  
  81. $scope.check_credentials = function() {
  82. var request = $http({
  83. method: "post",
  84. url: "auth.php",
  85. data: {
  86. username: $scope.username,
  87. password: $scope.password,
  88. },
  89. headers: {
  90. 'Content-Type': 'application/x-www-form-urlencoded'
  91. }
  92. });
  93.  
  94. /* Check whether the HTTP Request is successful or not. */
  95. request.success(function(data) {
  96. $scope.notificationDisplayed = true;
  97.  
  98. if (data == 'success') {
  99. $scope.message = "Login successful. You will be redirected in 3 seconds.";
  100. $scope.notificationColor = "success";
  101. $scope.notificationTitle = "Success";
  102.  
  103. // redirect after 3 seconds
  104. $timeout(function() {
  105. window.location.href = 'datatable.html';
  106. }, 3000)
  107. } else {
  108. $scope.message = "Invalid username and password combination";
  109. $scope.notificationColor = "danger";
  110. $scope.notificationTitle = "Fail";
  111. }
  112. });
  113. }
  114. });
  115. </script>
  116. <!-- Angular JS Code End Here-->
  117.  
  118. <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
  119. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  120. <!-- Include all compiled plugins (below), or include individual files as needed -->
  121. <script src="js/bootstrap.min.js"></script>
  122. </body>
  123.  
  124. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement