Advertisement
Guest User

Untitled

a guest
Aug 10th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.07 KB | None | 0 0
  1. function config($stateProvider, $urlRouterProvider, $ocLazyLoadProvider, IdleProvider, KeepaliveProvider) {
  2. $urlRouterProvider.otherwise("/dashboards/dashboard");
  3.  
  4. $ocLazyLoadProvider.config({
  5. /* Set to true if you want to see what and when is dynamically loaded*/
  6. debug: false
  7. });
  8.  
  9. $stateProvider
  10. .state('dashboard', {
  11. abstract: true,
  12. url: "/dashboards",
  13. templateUrl: "views/dashboards.html"
  14. })
  15. .state('login', {
  16. url: "/login",
  17. templateUrl: "views/login.html",
  18. controller: "loginCtrl",
  19. hideMenus: true,
  20. data: {pageTitle: 'Login', specialClass: 'gray-bg'},
  21. resolve: {
  22. loadPlugin: function ($ocLazyLoad) {
  23. return $ocLazyLoad.load([
  24. {
  25. insertBefore: '#loadBefore',
  26. name: 'toaster',
  27. files: ['js/plugins/toastr/toastr.min.js', 'css/plugins/toastr/toastr.min.css']
  28. }
  29. ]);
  30. }
  31. }
  32. }).state('logout', {
  33. url: "/logout",
  34. templateUrl: "",
  35. controller: "LogoutController"
  36. });
  37.  
  38. }
  39.  
  40. function loginCtrl($scope, $http, $location, $rootScope, toaster) {
  41. $scope.message = '';
  42. $scope.login = function() {
  43. var request = $http({
  44. method: "post",
  45. url: "users/ajaxLogin.php",
  46. dataType: 'json',
  47. data: {
  48. email: $scope.email,
  49. password: $scope.password
  50. },
  51. headers: {'Content-Type': 'application/x-www-form-urlencoded'}
  52. });
  53. request.success(function(data) {
  54. if (data.success == true) {
  55. $scope.message = data.msg;
  56. $scope.class = "alert-success";
  57. //$window.location.href = '#/dashboards/dashboard';
  58. $location.path('/dashboards.dashboard');
  59. }
  60. else {
  61. //$scope.class = "alert-danger";
  62. //$scope.message = data.msg;
  63. toaster.pop({
  64. type: 'error',
  65. title: 'Login Error',
  66. body: data.msg,
  67. showCloseButton: true,
  68. });
  69. }
  70. });
  71. }
  72. }
  73.  
  74.  
  75. function LogoutController($location, $http, $rootScope, $templateCache, $scope) {
  76. this.logout = function() {
  77. var request = $http({
  78. method: "post",
  79. url: "users/ajaxLogout",
  80. dataType: 'json',
  81. headers: {'Content-Type': 'application/x-www-form-urlencoded'}
  82. });
  83. request.success(function(data) {
  84. $rootScope.authenticated = false;
  85. $rootScope.id = '';
  86. $rootScope.unique_id = '';
  87. $rootScope.print_house_id = '';
  88. $rootScope.name = '';
  89. $rootScope.email = '';
  90. $rootScope.type = '';
  91. $rootScope.logo = '';
  92. $templateCache.removeAll();
  93. $location.path('/login');
  94. });
  95. };
  96. }
  97.  
  98.  
  99.  
  100.  
  101. angular
  102. .module('myApp')
  103. .config(config)
  104. .controller('loginCtrl',loginCtrl)
  105. .controller('LogoutController',LogoutController)
  106. .run(['$rootScope', '$location', '$state', function ($rootScope, $location, $state, loginFactory) {
  107. $rootScope.$state = $state;
  108.  
  109. $rootScope.$on("$stateChangeStart", function (event, toState, toParams, fromState, fromParams) {
  110. $rootScope.authenticated = false;
  111. var json = (function () {
  112. $.ajax({
  113. async: false,
  114. global: false,
  115. url: 'users/testLogin.php',
  116. dataType: "json",
  117. success: function (response) {
  118. if (response.success) {
  119. $rootScope.authenticated = true;
  120. $rootScope.id = response.data.id;
  121. $rootScope.unique_id = response.data.unique_id;
  122. $rootScope.name = response.data.name;
  123. $rootScope.email = response.data.email;
  124. $rootScope.type = response.data.type;
  125. $rootScope.logo = response.data.logo;
  126. } else {
  127. var nextUrl = toState.name;
  128. if (nextUrl == 'signup' || nextUrl == 'login') {
  129.  
  130. } else {
  131. $location.path('/login');
  132. }
  133. }
  134. }
  135. });
  136. })();
  137.  
  138.  
  139. });
  140. }]);
  141.  
  142. $user = array();
  143. if ($_SESSION['user_id'] == '') {
  144. $user = array('id' => '', 'name' => '', 'unique_id' => '', 'email' => '', 'type' => '', 'logo' => '');
  145. $result['data'] = $user;
  146. $result['error'] = 'session not found';
  147. } else {
  148. $user = array('id' => $_SESSION['user_id'], 'name' => $_SESSION['name'], 'unique_id' => $_SESSION['unique_id'], 'email' => $_SESSION['email'], 'type' => $_SESSION['type'], 'logo' => $_SESSION['logo']);
  149. $result['data'] = $user;
  150. $result['success'] = 'session found';
  151. }
  152. echo json_encode($result);
  153. exit;
  154.  
  155. $email = $_REQUEST['email'];
  156. $password = md5($_REQUEST['password']);
  157. $result = array();
  158. $qryUser = mysqli_query($link,"select * FROM users where email='$email', password='$password'");
  159. if(mysqli_num_rows($qryUser)){
  160. $getUser = mysqli_fetch_assoc($qryUser);
  161. $result['data'] = $getUser;
  162. $result['success'] = true;
  163. $result['msg'] = "Login Success...";
  164. } else{
  165. $result['success'] = false;
  166. $result['msg'] = "Incorrect Email or Password";
  167. }
  168. echo json_encode($result);
  169. exit;
  170.  
  171. <!-- Navigation -->
  172. <div ng-include="'views/common/sidebar.html'"></div>
  173.  
  174. <!-- Page wraper -->
  175. <!-- ng-class with current state name give you the ability to extended customization your view -->
  176. <div id="page-wrapper" class="gray-bg {{$state.current.name}}">
  177.  
  178. <!-- Page wrapper -->
  179. <div ng-include="'views/common/topnavbar.html'"></div>
  180.  
  181. <!-- Main view -->
  182. <div ui-view>Dashboard Page</div>
  183.  
  184.  
  185. <div style="clear:both;"></div>
  186. </div>
  187. <!-- End page wrapper-->
  188.  
  189. <div ng-if="type==1">Admin</div>
  190. <div ng-if="type==2">Company</div>
  191.  
  192. +-----+----------+------------+---------------+---------------+
  193. | id | name | type | email | password |
  194. +-----+----------+------------+---------------+---------------+
  195. | 1 | aaa | 1 | aaa@gmail.com | pwd_here |
  196. | 2 | zzz | 2 | zzz@gmail.com | pwd_here |
  197. +-----+----------+------------+---------------+---------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement