Advertisement
Guest User

script.js

a guest
Mar 26th, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //script.js
  2. require('electron-cookies');
  3.  
  4. var _ipc    = window.require('electron').ipcRenderer;
  5. var openbmc = angular.module('openbmc', ['ngRoute', 'ngResource', 'ngCookies']);
  6.  
  7. var win = require('remote').getCurrentWindow();
  8.  
  9. // configure routes
  10. openbmc.config(function($routeProvider, $httpProvider) {
  11.   $routeProvider
  12.  
  13.   // route for the home page
  14.   .when('/', {
  15.     templateUrl: 'pages/login.html',
  16.     controller: 'mainController'
  17.   })
  18.  
  19.   // route for the login page
  20.   .when('/login', {
  21.     templateUrl: 'pages/login.html',
  22.     controller: 'mainController'
  23.   })
  24.  
  25.   // route for the app
  26.   .when('/app', {
  27.     templateUrl: 'pages/app.html',
  28.     controller: 'appController'
  29.   });
  30.  
  31.   $httpProvider.defaults.withCredentials = true;
  32. });
  33.  
  34. openbmc.controller('mainController', function($scope, $http, $cookies) {
  35.   $scope.message = 'This is the login page!';
  36.   $scope.regex = '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$';
  37.  
  38.   $scope.expandWindow = function() {
  39.     console.log("Expand the window!");
  40.     _ipc.send('resize', 600, 800);
  41.   };
  42.  
  43.   $scope.login = function() {
  44.     console.log("Form was submitted! Here's the data:");
  45.     console.log($scope.ipAddress);
  46.     console.log($scope.port);
  47.     console.log($scope.username);
  48.     console.log($scope.password);
  49.  
  50.     // $http.jsonp("http://9.41.164.53:10080/login?callback=?")
  51.     // .then(function(json) {
  52.     //   console.log(json);
  53.     // });
  54.  
  55.     $http({
  56.       url: 'http://9.41.164.53:10080/login',
  57.       method: 'POST',
  58.       data: JSON.stringify({"data": ["root", "0penBmc"]}),
  59.       withCredentials: true,
  60.       headers: {
  61.         'Content-Type': 'application/json'
  62.       }
  63.     }).then(function(response) {
  64.       console.log(response);
  65.       // I need to set the cookie here!
  66.     });
  67.   }
  68. });
  69.  
  70. openbmc.controller('appController', function($scope) {
  71.   $scope.message = 'This is the app page!';
  72.   $scope.shrinkWindow = function() {
  73.     console.log("Shrink the window!");
  74.     _ipc.send('resize', 300, 400);
  75.   };
  76. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement