Advertisement
Guest User

Untitled

a guest
Jun 12th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. <html ng-app="bookApp">
  2.  
  3. <head>
  4. <title>Angular Assignment</title>
  5. <style type="text/css">
  6.  
  7.  
  8.  
  9. @import "styles/style.css";
  10.  
  11. </style>
  12. <script src="lib/Angular/angular.js"></script>
  13. <script src="lib/Angular/angular-route.js"></script>
  14. <script src="js/controllers.js"></script>
  15. <script src="js/app.js"></script>
  16. </head>
  17. <body>
  18. <center>
  19. <!--include header.html -->
  20. <div ng-include="'Header.html'"></div>
  21. </center>
  22.  
  23. <!-- Add the required controller to this div.
  24. Associate the models for username and password.
  25. -->
  26. <div align="center" ng-controller="LoginCtrl">
  27. <h2>
  28. Login
  29. </h2>
  30.  
  31. <div class="LoginFormDiv">
  32. <table border="0">
  33. <tr>
  34.  
  35.  
  36. <td> Username </td>
  37. <td>: <input ng-model="username" class="input" placeholder="Enter
  38. Username"/></td>
  39. </tr>
  40. <tr>
  41. <td> Password</td>
  42. <td>: <input ng-model="password" class="input" placeholder="Enter
  43. Password"/></td>
  44. </tr>
  45. <tr>
  46. <td colspan="2">
  47. <!-- On click of the button, call validate(user) method declared in controller-->
  48. <input type="submit" class="button" value="Login" ng-click="validate()"/>
  49. </td>
  50. </tr>
  51. </table>
  52. </div>
  53.  
  54. </div>
  55. <!-- include footer.html -->
  56. <center>
  57. <div ng-include="'Footer.html'"></div>
  58. </center>
  59. </body>
  60. </html>
  61.  
  62. var Controllers = angular.module('Controllers', ['ngRoute']);
  63.  
  64. Controllers.controller('LoginCtrl', ['$scope','$location', '$http', '$rootScope',
  65.  
  66. function ($scope,$location, $http, $rootScope) {
  67. alert("I am in LoginCtrl")
  68. $scope.validate=function()
  69. {
  70. alert("I am in validate function")
  71. $http.get('data/roles.json').success(function(data) {
  72. $scope.roles = data;
  73. });
  74. var count=0;
  75. angular.forEach($scope.roles, function(role) {
  76. if($scope.username==role.username && $scope.password==role.password) {
  77. alert("login successful");
  78. count=count+1;
  79. if($scope.roles=="student") {
  80. $location.path("/home/student");
  81. }
  82. else {
  83. $location.path("/home/librarian");
  84. }
  85. }
  86.  
  87. else if(count!=1)
  88. {
  89. alert("Please provide valid login credentials");
  90. $location.path( "/main" )
  91. }
  92.  
  93. });
  94.  
  95.  
  96. }
  97.  
  98. }]);
  99.  
  100. var bookApp = angular.module('bookApp',[
  101. 'Controllers','ngRoute'
  102.  
  103. ]);
  104.  
  105. bookApp.config(['$routeProvider',
  106.  
  107. function($routeProvider) {
  108. $routeProvider.
  109. when('/main', {
  110. templateUrl: 'Login',
  111. controller: 'LoginCtrl'
  112. }).
  113. when('/home/student', {
  114. templateUrl: 'ViewBooks_Student.html',
  115. controller: 'BookListCtrl_Student'
  116. });
  117. when('/home/librarian', {
  118. templateUrl: 'ViewBooks_Librarian.html',
  119. controller: 'BookListCtrl_Librarian'
  120. });
  121. when('/issue/:bookId', {
  122. templateUrl: 'IssueBook.html',
  123. controller: 'IssueBookCtrl'
  124. });
  125. when('/return/:bookId', {
  126. templateUrl: 'ReturnBook.html',
  127. controller: 'ReturnBookCtrl'
  128. });
  129. otherwise({
  130. redirectTo: '/main'
  131. });
  132. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement