Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html ng-app="bookApp">
- <head>
- <title>Angular Assignment</title>
- <style type="text/css">
- @import "styles/style.css";
- </style>
- <script src="lib/Angular/angular.js"></script>
- <script src="lib/Angular/angular-route.js"></script>
- <script src="js/controllers.js"></script>
- <script src="js/app.js"></script>
- </head>
- <body>
- <center>
- <!--include header.html -->
- <div ng-include="'Header.html'"></div>
- </center>
- <!-- Add the required controller to this div.
- Associate the models for username and password.
- -->
- <div align="center" ng-controller="LoginCtrl">
- <h2>
- Login
- </h2>
- <div class="LoginFormDiv">
- <table border="0">
- <tr>
- <td> Username </td>
- <td>: <input ng-model="username" class="input" placeholder="Enter
- Username"/></td>
- </tr>
- <tr>
- <td> Password</td>
- <td>: <input ng-model="password" class="input" placeholder="Enter
- Password"/></td>
- </tr>
- <tr>
- <td colspan="2">
- <!-- On click of the button, call validate(user) method declared in controller-->
- <input type="submit" class="button" value="Login" ng-click="validate()"/>
- </td>
- </tr>
- </table>
- </div>
- </div>
- <!-- include footer.html -->
- <center>
- <div ng-include="'Footer.html'"></div>
- </center>
- </body>
- </html>
- var Controllers = angular.module('Controllers', ['ngRoute']);
- Controllers.controller('LoginCtrl', ['$scope','$location', '$http', '$rootScope',
- function ($scope,$location, $http, $rootScope) {
- alert("I am in LoginCtrl")
- $scope.validate=function()
- {
- alert("I am in validate function")
- $http.get('data/roles.json').success(function(data) {
- $scope.roles = data;
- });
- var count=0;
- angular.forEach($scope.roles, function(role) {
- if($scope.username==role.username && $scope.password==role.password) {
- alert("login successful");
- count=count+1;
- if($scope.roles=="student") {
- $location.path("/home/student");
- }
- else {
- $location.path("/home/librarian");
- }
- }
- else if(count!=1)
- {
- alert("Please provide valid login credentials");
- $location.path( "/main" )
- }
- });
- }
- }]);
- var bookApp = angular.module('bookApp',[
- 'Controllers','ngRoute'
- ]);
- bookApp.config(['$routeProvider',
- function($routeProvider) {
- $routeProvider.
- when('/main', {
- templateUrl: 'Login',
- controller: 'LoginCtrl'
- }).
- when('/home/student', {
- templateUrl: 'ViewBooks_Student.html',
- controller: 'BookListCtrl_Student'
- });
- when('/home/librarian', {
- templateUrl: 'ViewBooks_Librarian.html',
- controller: 'BookListCtrl_Librarian'
- });
- when('/issue/:bookId', {
- templateUrl: 'IssueBook.html',
- controller: 'IssueBookCtrl'
- });
- when('/return/:bookId', {
- templateUrl: 'ReturnBook.html',
- controller: 'ReturnBookCtrl'
- });
- otherwise({
- redirectTo: '/main'
- });
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement