Password impl, various enhancements
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.ria / src / argeo-ria-lib / security / class / org / argeo / security / ria / components / PasswordCredentialImpl.js
index 66e38eacf038897e4db1586e578abe142b83569a..238cc7ef106d6e1be77eaa5ebfd90a1f52535a1a 100644 (file)
@@ -4,22 +4,60 @@ qx.Class.define("org.argeo.security.ria.components.PasswordCredentialImpl", {
        events : {\r
                "modified" : "qx.event.type.Event"              \r
        },\r
+       properties : {\r
+               valid : {\r
+                       init : false\r
+               },\r
+               encoderCallback : {\r
+                       init : function(string){\r
+                               var encoderShort = org.argeo.ria.util.Encoder;\r
+                               return "{SHA}"+encoderShort.base64Encode(encoderShort.hexDecode(encoderShort.hash(string, "sha1")));\r
+                       },\r
+                       check : "Function"\r
+               }\r
+       },\r
        \r
        construct : function(){\r
                this.base(arguments);\r
                this.setLayout(new qx.ui.layout.HBox(5, "center"));\r
                this.add(new qx.ui.basic.Label("Password"), {flex:1});\r
-               this.add(new qx.ui.form.TextField(), {flex:2});\r
+               this.pass1 = new qx.ui.form.PasswordField();\r
+               this.add(this.pass1, {flex:2});\r
                this.add(new qx.ui.basic.Label("Confirm Password"), {flex:1});\r
-               this.add(new qx.ui.form.TextField(), {flex:2});\r
+               this.pass2 = new qx.ui.form.PasswordField();\r
+               this.add(this.pass2, {flex:2});\r
+               this.pass1.addListener("changeValue", function(){this.fireEvent("modified");}, this);\r
+               this.pass2.addListener("changeValue", function(){this.fireEvent("modified");}, this);\r
+               this.pass2.addListener("changeValue", this.validate, this);\r
        },\r
        \r
        members : {\r
                getContainer  : function(){\r
                        return this;\r
                },\r
-               getData    : function(format){return true;},\r
-               validate : function(){return true;},\r
+               getData : function(format){\r
+                       var encoded = null;\r
+                       if(this.pass1.getValue() != ""){\r
+                               var encoder = this.getEncoderCallback();\r
+                               encoded = encoder(this.pass1.getValue()); \r
+                       }\r
+                       return encoded;\r
+               },\r
+               clear : function(){\r
+                       this.pass1.setValue("");\r
+                       this.pass2.setValue("");                        \r
+               },\r
+               validate : function(){\r
+                       if(this.pass1.getValue() != this.pass2.getValue() || this.pass1.getValue() == ""){\r
+                               // TODO WHEN TESTING 0.8.3\r
+                               //this.pass1.setValid(false);\r
+                               //this.pass2.setValid(false); \r
+                               this.setValid(false);\r
+                       }else{\r
+                               this.setValid(true);\r
+                       }\r
+                       return this.getValid();\r
+               },\r
                setEditMode : function(editMode){return true;}          \r
        }\r
 });
\ No newline at end of file