router.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. App.Router = Em.Router.extend({
  19. enableLogging: true,
  20. setInstallerCurrentStep: function (currentStep, completed) {
  21. var loginName = this.getLoginName();
  22. App.db.setInstallerCurrentStep(currentStep, completed);
  23. this.set('installerController.currentStep', currentStep);
  24. },
  25. getInstallerCurrentStep: function () {
  26. var loginName = this.getLoginName();
  27. var currentStep = App.db.getInstallerCurrentStep();
  28. console.log('getInstallerCurrentStep: loginName=' + loginName + ", currentStep=" + currentStep);
  29. if (!currentStep) {
  30. currentStep = '1';
  31. }
  32. console.log('returning currentStep=' + currentStep);
  33. return currentStep;
  34. },
  35. loggedIn: false,
  36. getAuthenticated: function () {
  37. // TODO: this needs to be hooked up with server authentication
  38. var auth = App.db.getAuthenticated();
  39. var authResp = (auth && auth === true);
  40. this.set('loggedIn', authResp);
  41. return authResp;
  42. },
  43. setAuthenticated: function (authenticated) {
  44. // TODO: this needs to be hooked up with server authentication
  45. console.log("TRACE: Entering router:setAuthenticated function");
  46. App.db.setAuthenticated(authenticated);
  47. this.set('loggedIn', authenticated);
  48. },
  49. getLoginName: function () {
  50. // TODO: this needs to be hooked up with server authentication
  51. return App.db.getLoginName();
  52. //return localStorage.getItem('Ambari' + 'loginName');
  53. },
  54. setLoginName: function (loginName) {
  55. // TODO: this needs to be hooked up with server authentication
  56. App.db.setLoginName(loginName);
  57. //localStorage.setItem('Ambari' + 'loginName', loginName);
  58. },
  59. login: function (loginName) {
  60. // TODO: this needs to be hooked up with server authentication
  61. console.log("In login function");
  62. this.setAuthenticated(true);
  63. this.setLoginName(loginName);
  64. this.transitionTo(this.getSection());
  65. },
  66. defaultSection: 'installer',
  67. getSection: function () {
  68. var section = App.db.getSection();
  69. console.log("The section is: " + section);
  70. var section = localStorage.getItem(this.getLoginName() + 'section');
  71. return section || this.defaultSection;
  72. },
  73. setSection: function (section) {
  74. App.db.setSection(section);
  75. },
  76. root: Em.Route.extend({
  77. index: Em.Route.extend({
  78. route: '/',
  79. redirectsTo: 'login'
  80. }),
  81. login: Em.Route.extend({
  82. route: '/login',
  83. /**
  84. * If the user is already logged in, redirect to where the user was previously
  85. */
  86. enter: function (router, context) {
  87. if (router.getAuthenticated()) {
  88. Ember.run.next(function () {
  89. console.log(router.getLoginName() + ' already authenticated. Redirecting...');
  90. router.transitionTo(router.getSection(), context);
  91. });
  92. }
  93. },
  94. connectOutlets: function (router, context) {
  95. console.log('/login:connectOutlet');
  96. console.log('currentStep is: ' + router.getInstallerCurrentStep());
  97. console.log('authenticated is: ' + router.getAuthenticated());
  98. router.get('applicationController').connectOutlet('login', App.LoginView);
  99. }
  100. }),
  101. installer: require('routes/installer'),
  102. main: require('routes/main'),
  103. logoff: function (router, context) {
  104. console.log('logging off');
  105. App.db.cleanUp();
  106. router.set('loginController.loginName', '');
  107. router.set('loginController.password', '');
  108. router.transitionTo('login', context);
  109. }
  110. })
  111. })