Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function config($stateProvider, $urlRouterProvider, $ocLazyLoadProvider, IdleProvider, KeepaliveProvider) {
- $urlRouterProvider.otherwise("/dashboards/dashboard");
- $ocLazyLoadProvider.config({
- /* Set to true if you want to see what and when is dynamically loaded*/
- debug: false
- });
- $stateProvider
- .state('dashboard', {
- abstract: true,
- url: "/dashboards",
- templateUrl: "views/dashboards.html"
- })
- .state('login', {
- url: "/login",
- templateUrl: "views/login.html",
- controller: "loginCtrl",
- hideMenus: true,
- data: {pageTitle: 'Login', specialClass: 'gray-bg'},
- resolve: {
- loadPlugin: function ($ocLazyLoad) {
- return $ocLazyLoad.load([
- {
- insertBefore: '#loadBefore',
- name: 'toaster',
- files: ['js/plugins/toastr/toastr.min.js', 'css/plugins/toastr/toastr.min.css']
- }
- ]);
- }
- }
- }).state('logout', {
- url: "/logout",
- templateUrl: "",
- controller: "LogoutController"
- });
- }
- function loginCtrl($scope, $http, $location, $rootScope, toaster) {
- $scope.message = '';
- $scope.login = function() {
- var request = $http({
- method: "post",
- url: "users/ajaxLogin.php",
- dataType: 'json',
- data: {
- email: $scope.email,
- password: $scope.password
- },
- headers: {'Content-Type': 'application/x-www-form-urlencoded'}
- });
- request.success(function(data) {
- if (data.success == true) {
- $scope.message = data.msg;
- $scope.class = "alert-success";
- //$window.location.href = '#/dashboards/dashboard';
- $location.path('/dashboards.dashboard');
- }
- else {
- //$scope.class = "alert-danger";
- //$scope.message = data.msg;
- toaster.pop({
- type: 'error',
- title: 'Login Error',
- body: data.msg,
- showCloseButton: true,
- });
- }
- });
- }
- }
- function LogoutController($location, $http, $rootScope, $templateCache, $scope) {
- this.logout = function() {
- var request = $http({
- method: "post",
- url: "users/ajaxLogout",
- dataType: 'json',
- headers: {'Content-Type': 'application/x-www-form-urlencoded'}
- });
- request.success(function(data) {
- $rootScope.authenticated = false;
- $rootScope.id = '';
- $rootScope.unique_id = '';
- $rootScope.print_house_id = '';
- $rootScope.name = '';
- $rootScope.email = '';
- $rootScope.type = '';
- $rootScope.logo = '';
- $templateCache.removeAll();
- $location.path('/login');
- });
- };
- }
- angular
- .module('myApp')
- .config(config)
- .controller('loginCtrl',loginCtrl)
- .controller('LogoutController',LogoutController)
- .run(['$rootScope', '$location', '$state', function ($rootScope, $location, $state, loginFactory) {
- $rootScope.$state = $state;
- $rootScope.$on("$stateChangeStart", function (event, toState, toParams, fromState, fromParams) {
- $rootScope.authenticated = false;
- var json = (function () {
- $.ajax({
- async: false,
- global: false,
- url: 'users/testLogin.php',
- dataType: "json",
- success: function (response) {
- if (response.success) {
- $rootScope.authenticated = true;
- $rootScope.id = response.data.id;
- $rootScope.unique_id = response.data.unique_id;
- $rootScope.name = response.data.name;
- $rootScope.email = response.data.email;
- $rootScope.type = response.data.type;
- $rootScope.logo = response.data.logo;
- } else {
- var nextUrl = toState.name;
- if (nextUrl == 'signup' || nextUrl == 'login') {
- } else {
- $location.path('/login');
- }
- }
- }
- });
- })();
- });
- }]);
- $user = array();
- if ($_SESSION['user_id'] == '') {
- $user = array('id' => '', 'name' => '', 'unique_id' => '', 'email' => '', 'type' => '', 'logo' => '');
- $result['data'] = $user;
- $result['error'] = 'session not found';
- } else {
- $user = array('id' => $_SESSION['user_id'], 'name' => $_SESSION['name'], 'unique_id' => $_SESSION['unique_id'], 'email' => $_SESSION['email'], 'type' => $_SESSION['type'], 'logo' => $_SESSION['logo']);
- $result['data'] = $user;
- $result['success'] = 'session found';
- }
- echo json_encode($result);
- exit;
- $email = $_REQUEST['email'];
- $password = md5($_REQUEST['password']);
- $result = array();
- $qryUser = mysqli_query($link,"select * FROM users where email='$email', password='$password'");
- if(mysqli_num_rows($qryUser)){
- $getUser = mysqli_fetch_assoc($qryUser);
- $result['data'] = $getUser;
- $result['success'] = true;
- $result['msg'] = "Login Success...";
- } else{
- $result['success'] = false;
- $result['msg'] = "Incorrect Email or Password";
- }
- echo json_encode($result);
- exit;
- <!-- Navigation -->
- <div ng-include="'views/common/sidebar.html'"></div>
- <!-- Page wraper -->
- <!-- ng-class with current state name give you the ability to extended customization your view -->
- <div id="page-wrapper" class="gray-bg {{$state.current.name}}">
- <!-- Page wrapper -->
- <div ng-include="'views/common/topnavbar.html'"></div>
- <!-- Main view -->
- <div ui-view>Dashboard Page</div>
- <div style="clear:both;"></div>
- </div>
- <!-- End page wrapper-->
- <div ng-if="type==1">Admin</div>
- <div ng-if="type==2">Company</div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement