From 06f80b7b50619d1c997e2660eddb32a584cfc8a8 Mon Sep 17 00:00:00 2001 From: Charles du Jeu Date: Mon, 21 Sep 2009 09:01:38 +0000 Subject: [PATCH] Password impl, various enhancements git-svn-id: https://svn.argeo.org/commons/trunk@2994 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../org/argeo/security/ria/RolesApplet.js | 24 ++++++++ .../argeo/security/ria/UserEditorApplet.js | 56 +++++++++++++++---- .../org/argeo/security/ria/UsersApplet.js | 12 ---- .../ria/components/PasswordCredentialImpl.js | 26 +++++++-- .../org/argeo/security/ria/model/User.js | 11 +++- 5 files changed, 100 insertions(+), 29 deletions(-) diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/RolesApplet.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/RolesApplet.js index 7b124b928..429460b37 100644 --- a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/RolesApplet.js +++ b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/RolesApplet.js @@ -28,6 +28,18 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", */ commands : { init : { + "reload" : { + label : "Reload Data", + icon : "org.argeo.security.ria/view-refresh.png", + shortcut : "Control+h", + enabled : true, + menu : "Roles", + toolbar : "roles", + callback : function(e){ + this.loadRolesList(); + }, + command : null + }, "new_role" : { label : "Create Role", icon : "org.argeo.security.ria/list-add.png", @@ -232,7 +244,13 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", viewSel.removeListener("changeSelection", this.monitorChooserSelectionChanges, this); } selectionModel.addListener("changeSelection", this.selectionToFilter, this); + if(selectionModel.getSelectedCount()){ + var orig = selectionModel.getSelectedRanges()[0].minIndex; + } selectionModel.setSelectionMode(qx.ui.table.selection.Model.MULTIPLE_INTERVAL_SELECTION_TOGGLE); + if(orig){ + selectionModel.addSelectionInterval(orig, orig); + } this.selectionToFilter(); }else if(guiMode == "edit"){ if(!this.usersAppletReference) return; @@ -253,7 +271,13 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", } this.table.setEnabled(true); selectionModel.removeListener("changeSelection", this.selectionToFilter, this); + if(selectionModel.getSelectedCount()){ + var orig = selectionModel.getSelectedRanges()[0].minIndex; + } selectionModel.setSelectionMode(qx.ui.table.selection.Model.SINGLE_SELECTION); + if(orig){ + selectionModel.addSelectionInterval(orig, orig); + } } }, diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js index e85b52410..f7fad1df4 100644 --- a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js +++ b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js @@ -139,8 +139,14 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", rolesList : { }, - instanceId : {init:""}, - instanceLabel : {init:"Editor"}, + instanceId : { + init:"", + event : "changeInstanceId" + }, + instanceLabel : { + init:"Editor", + event : "changeInstanceLabel" + }, loaded : { init : false }, @@ -259,10 +265,15 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", }else{ user.setRoles([]); } - user.setPassword(this.passPane.getData()); // GO TO AND RETURN FROM SERVER if(user.isCreate()){ + if(!this.passPane.validate()){ + this.error("Warning, passwords differ!"); + return; + } + user.setPassword(this.passPane.getData()); + var create = true; var userExists = false; var req = org.argeo.security.ria.SecurityAPI.getUserExistsService(user.getName()); req.addListener("completed", function(response){ @@ -274,20 +285,45 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", this.error("User already exists, choose another name!"); return; } + }else{ + var pass = this.passPane.getData(); + if(pass != null && !this.passPane.validate()){ + this.error("Warning, passwords differ!"); + return; + } } - var userService = user.getSaveService(); - userService.send(); - userService.addListener("completed", function(response){ - if(response.getContent().status && response.getContent().status == "ERROR"){ - return; + this.passPane.clear(); + var saveCompletedCallback = qx.lang.Function.bind(function(){ + if(create){ + this.setInstanceLabel("User " + user.getName()); + this.setInstanceId(user.getName()); } this._setGuiInCreateMode(false); - user.load(response.getContent(), "json"); this.partialRefreshUser(user, ["details","natures"]); this.setModified(false); this.getViewSelection().triggerEvent(); - this.fireDataEvent("savedUser", user); + this.fireDataEvent("savedUser", user); }, this); + var userService = user.getSaveService(); + userService.addListener("completed", function(response){ + if(response.getContent().status && response.getContent().status == "ERROR"){ + return; + } + user.load(response.getContent(), "json"); + if(pass!=null){ + var passService = org.argeo.security.ria.SecurityAPI.getUpdateUserPassService(user.getName(), pass); + passService.addListener("completed", function(response){ + if(response.getContent().status){ + this.info(response.getContent().message); + } + saveCompletedCallback(); + }, this); + passService.send(); + }else{ + saveCompletedCallback(); + } + }, this); + userService.send(); }, _addNatureTab : function(natureClass, natureData, select){ diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js index 988e178b7..7f0c55335 100644 --- a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js +++ b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js @@ -28,18 +28,6 @@ qx.Class.define("org.argeo.security.ria.UsersApplet", */ commands : { init : { - "load_users" : { - label : "Reload Users", - icon : "org.argeo.security.ria/view-refresh.png", - shortcut : "Control+h", - enabled : true, - menu : "Users", - toolbar : "users", - callback : function(e){ - this.loadUsersList(); - }, - command : null - }, "new_user" : { label : "New User", icon : "org.argeo.security.ria/list-add.png", diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/PasswordCredentialImpl.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/PasswordCredentialImpl.js index 610e56d12..238cc7ef1 100644 --- a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/PasswordCredentialImpl.js +++ b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/PasswordCredentialImpl.js @@ -7,6 +7,13 @@ qx.Class.define("org.argeo.security.ria.components.PasswordCredentialImpl", { properties : { valid : { init : false + }, + encoderCallback : { + init : function(string){ + var encoderShort = org.argeo.ria.util.Encoder; + return "{SHA}"+encoderShort.base64Encode(encoderShort.hexDecode(encoderShort.hash(string, "sha1"))); + }, + check : "Function" } }, @@ -28,15 +35,26 @@ qx.Class.define("org.argeo.security.ria.components.PasswordCredentialImpl", { getContainer : function(){ return this; }, - getData : function(format){return true;}, + getData : function(format){ + var encoded = null; + if(this.pass1.getValue() != ""){ + var encoder = this.getEncoderCallback(); + encoded = encoder(this.pass1.getValue()); + } + return encoded; + }, + clear : function(){ + this.pass1.setValue(""); + this.pass2.setValue(""); + }, validate : function(){ - if(this.pass1.getValue() == this.pass2.getValue()){ - this.setValid(true); - }else{ + if(this.pass1.getValue() != this.pass2.getValue() || this.pass1.getValue() == ""){ // TODO WHEN TESTING 0.8.3 //this.pass1.setValid(false); //this.pass2.setValid(false); this.setValid(false); + }else{ + this.setValid(true); } return this.getValid(); }, diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/model/User.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/model/User.js index 64ba63e4c..c3f46970d 100644 --- a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/model/User.js +++ b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/model/User.js @@ -5,6 +5,10 @@ qx.Class.define("org.argeo.security.ria.model.User", { init : "", check : "String" }, + password : { + nullable : true, + check : "String" + }, roles : { check : "Array" }, @@ -23,7 +27,7 @@ qx.Class.define("org.argeo.security.ria.model.User", { this.base(arguments); this.setRoles([]); this.setNatures([]); - this.setRawData({"password":"{SHA}ieSV55Qc+eQOaYDRSha/AjzNTJE="}); + this.setRawData({password:null}); }, members : { load : function(data, format){ @@ -35,7 +39,7 @@ qx.Class.define("org.argeo.security.ria.model.User", { }, getSaveService : function(){ if(this.isCreate()){ - var userService = org.argeo.security.ria.SecurityAPI.getCreateUserService(this.toJSON()); + var userService = org.argeo.security.ria.SecurityAPI.getCreateUserService(this.toJSON(true)); }else{ var userService = org.argeo.security.ria.SecurityAPI.getUpdateUserService(this.toJSON()); } @@ -45,11 +49,12 @@ qx.Class.define("org.argeo.security.ria.model.User", { }, this); return userService; }, - toJSON : function(){ + toJSON : function(create){ var rawData = this.getRawData(); rawData.username = this.getName(); rawData.roles = this.getRoles(); rawData.userNatures = this.getNatures(); + if(create) rawData.password = this.getPassword(); return rawData; }, _getNatureByType : function(natureType){ -- 2.30.2