You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2012/12/09 13:13:52 UTC
svn commit: r1418907 - in /incubator/ambari/branches/AMBARI-666:
AMBARI-666-CHANGES.txt ambari-web/app/controllers/login_controller.js
ambari-web/app/router.js
Author: yusaku
Date: Sun Dec 9 12:13:51 2012
New Revision: 1418907
URL: http://svn.apache.org/viewvc?rev=1418907&view=rev
Log:
AMBARI-993. Hook up login with server authentication. (yusaku)
Modified:
incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
incubator/ambari/branches/AMBARI-666/ambari-web/app/controllers/login_controller.js
incubator/ambari/branches/AMBARI-666/ambari-web/app/router.js
Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1418907&r1=1418906&r2=1418907&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Sun Dec 9 12:13:51 2012
@@ -398,6 +398,8 @@ AMBARI-666 branch (unreleased changes)
IMPROVEMENTS
+ AMBARI-993. Hook up login with server authentication. (yusaku)
+
AMBARI-1059. Refactor cluster management. (yusaku)
AMBARI-1058. Implement data loading. (yusaku)
Modified: incubator/ambari/branches/AMBARI-666/ambari-web/app/controllers/login_controller.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-web/app/controllers/login_controller.js?rev=1418907&r1=1418906&r2=1418907&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-web/app/controllers/login_controller.js (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-web/app/controllers/login_controller.js Sun Dec 9 12:13:51 2012
@@ -21,18 +21,19 @@ var App = require('app');
App.LoginController = Em.Object.extend({
name: 'loginController',
+
loginName: '',
password: '',
+
errorMessage: '',
submit: function (e) {
- // console.log('Login: ' + this.get('loginName') + ' Password: ' + this.get('password'));
-
this.set('errorMessage', '');
var self = this;
+ var loginFunc = (App.testMode) ? App.get('router').mockLogin : App.get('router').login;
- var user = App.get('router').mockLogin(function (isAuthenticated) {
+ var user = loginFunc.call(App.get('router'), function (isAuthenticated) {
if (!isAuthenticated) {
console.log('Failed to login as: ' + self.get('loginName'));
self.set('errorMessage', Em.I18n.t('login.error'));
Modified: incubator/ambari/branches/AMBARI-666/ambari-web/app/router.js
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-web/app/router.js?rev=1418907&r1=1418906&r2=1418907&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-web/app/router.js (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-web/app/router.js Sun Dec 9 12:13:51 2012
@@ -122,12 +122,13 @@ App.Router = Em.Router.extend({
login: function (postLogin) {
var controller = this.get('loginController');
- var hash = window.btoa(controller.get('loginName') + ":" + controller.get('password'));
+ var loginName = controller.get('loginName');
+ var hash = window.btoa(loginName + ":" + controller.get('password'));
var router = this;
$.ajax({
- url : '/api/check',
- dataType : 'json',
+ url : '/api/users/' + loginName,
+ dataType : 'text',
type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + hash);
@@ -145,15 +146,19 @@ App.Router = Em.Router.extend({
},
success: function (data) {
console.log('login success');
+
+ var resp = $.parseJSON(data);
+ var isAdmin = resp.Users.roles.indexOf('admin') >= 0;
+
router.setAuthenticated(true);
router.setLoginName(loginName);
- // TODO: set real usr
- router.setUser(App.User.find(1));
- router.transitionTo(this.getSection());
+
+ router.setUser(App.store.createRecord(App.User, { userName: loginName, admin: isAdmin }));
+ router.transitionTo(router.getSection());
postLogin(true);
},
error: function (req) {
- console.log("login error: " + req.statusText);
+ console.log("login error: " + req.statusCode);
router.setAuthenticated(false);
postLogin(false);
}
@@ -162,11 +167,13 @@ App.Router = Em.Router.extend({
mockLogin: function (postLogin) {
var controller = this.get('loginController');
+ var loginName = controller.get('loginName');
- if (controller.get('loginName') === 'admin' && controller.get('password') === 'admin') {
+ if ((loginName === 'admin' && controller.get('password') === 'admin') ||
+ (loginName === 'user' && controller.get('password') === 'user')) {
this.setAuthenticated(true);
- this.setLoginName('admin');
- this.setUser(App.User.find(1));
+ this.setLoginName(loginName);
+ this.setUser(App.store.createRecord(App.User, { userName: loginName, admin: loginName === 'admin' }));
this.transitionTo(this.getSection());
postLogin(true);
} else {