Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/LoginForm/LoginForm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<category>Behavior</category>
<description>Display a progress bar while signing in</description>
</property>
<property key="forceUserLowercase" type="boolean" defaultValue="false">
<caption>Lower case username</caption>
<category>Display</category>
<description>Automatically converts the username entered to lowercase before authenticating.</description>
</property>
<property key="showPasswordView" type="boolean" defaultValue="false">
<caption>Show/mask password toggle</caption>
<category>Password</category>
Expand Down Expand Up @@ -97,6 +102,33 @@
<category>Mobile</category>
<description>Enables/disables auto capitalize functionality on username input field for mobile devices</description>
</property>
<property key="contextEntity" type="entity" required="false" allowNonPersistableEntities="true">
<caption>Context Entity</caption>
<category>Before Login</category>
<description>The context entity, which will be passed to the before login microflow.</description>
</property>
<property key="userAttr" type="attribute" required="false" entityProperty="contextEntity">
<caption>Username Attribute</caption>
<category>Before Login</category>
<description>The username attribute of the context entity</description>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
</property>
<property key="passwordAttr" type="attribute" required="false" entityProperty="contextEntity">
<caption>Password Attribute</caption>
<category>Before Login</category>
<description>The password attribute of the context entity</description>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
</property>
<property key="beforeloginmf" type="microflow" required="false" entityProperty="contextEntity">
<caption>Before login microflow</caption>
<category>Before Login</category>
<description>Microflow fire before trying to log in. Useful for custom SSO solutions.</description>
<returnType type="Boolean"/>
</property>
</properties>
</widget>

158 changes: 105 additions & 53 deletions src/LoginForm/widget/LoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@
* ======================
*/
_handle: null,
_contextObj: null,
beforeloginmf: "",
userAttr: "",
passwordAttr: "",
forceUserLowercase: false,

// Extra variables
_userInput : null,
_passInput : null,
_captionShow : null,
_captionHide : null,
_currentE: null,

_indicator : null,
_i18nmap : null,
Expand Down Expand Up @@ -78,7 +84,9 @@
*/

update: function (obj, callback) {


this._contextObj = obj;

// Execute callback.
if (typeof callback !== 'undefined') {
callback();
Expand Down Expand Up @@ -186,58 +194,7 @@
// Attach events to newly created nodes.
_setupEvents: function () {

on(this.submitButton, 'click', lang.hitch(this, function(e) {

var user = null,
pass = null,
promise = null;

domStyle.set(this.messageNode, 'display', 'none');

if (attr.get(this._passInput, 'type') === 'text') {
attr.set(this._passInput, 'type', 'password');
dom.byId(this.id + '_view').innerHTML = this._captionShow;
}

logger.debug(this.id + '.submitForm');

user = this._userInput.value;
pass = this._passInput.value;

if(user && pass) {
if (typeof this._indicator !== 'undefined' && this._indicator){
this._indicator.start();
}

dojo.rawXhrPost({
url : mx.baseUrl,
mimetype : 'application/json',
contentType : 'application/json',
handleAs : 'json',
headers : {
'csrfToken' : mx.session.getCSRFToken()
},
postData : dojoJSON.toJson({
action : "login",
params : {
username : user,
password : pass,
locale : ""
}
}),
handle : lang.hitch(this, this._validate)
});

} else {
domStyle.set(this.messageNode, 'display', 'block');
this.messageNode.innerHTML = this.emptytext;
}

event.stop(e);

return false;

}));
on(this.submitButton, 'click', lang.hitch(this, this._onSubmit));

if(this.forgotmf)
{
Expand Down Expand Up @@ -316,6 +273,101 @@
this.messageNode.innerHTML = message; // is only reached when xhrstatus !== 200
domStyle.set(this.messageNode, 'display', 'block');
},

_onSubmit: function(e) {
this._currentE = e;

if(this.beforeloginmf) {
this._contextObj.set(this.userAttr, this._userInput.value);
this._contextObj.set(this.passwordAttr, this._passInput.value);
event.stop(e);

mx.data.action({
params: {
applyto: "selection",
actionname: this.beforeloginmf,
guids: [ this._contextObj.getGuid() ]
},
store: {
caller: this.mxform
},
callback: lang.hitch(this, function(obj) {
if(obj) {
this._loginSubmit(this._currentE);
} else {
this.messageNode.innerHTML = "Failed to authenticate";
domStyle.set(this.messageNode, 'display', 'block');
}
}),
error: lang.hitch(this, function(error) {
logger.error(this.id + ": An error occurred while executing microflow: " + error.description);
})
}, this);
} else {
this._loginSubmit(e);
}

},

_loginSubmit: function(e) {

var user = null,
pass = null,
promise = null;

domStyle.set(this.messageNode, 'display', 'none');

if (attr.get(this._passInput, 'type') === 'text') {
attr.set(this._passInput, 'type', 'password');
dom.byId(this.id + '_view').innerHTML = this._captionShow;
}

logger.debug(this.id + '.submitForm');

user = this._userInput.value;
pass = this._passInput.value;

//ET 3/31/2016
if (this.forceUserLowercase) {
user = user.toLowerCase();
}


if(user && pass) {
if (typeof this._indicator !== 'undefined' && this._indicator){
this._indicator.start();
}

dojo.rawXhrPost({
url : mx.baseUrl,
mimetype : 'application/json',
contentType : 'application/json',
handleAs : 'json',
headers : {
'csrfToken' : mx.session.getCSRFToken()
},
postData : dojoJSON.toJson({
action : "login",
params : {
username : user,
password : pass,
locale : ""
}
}),
handle : lang.hitch(this, this._validate)
});

} else {
domStyle.set(this.messageNode, 'display', 'block');
this.messageNode.innerHTML = this.emptytext;
}

event.stop(e);

return false;

},


_getI18NMap : function() {
logger.debug(this.id + '.injectI18NMap');
Expand Down
2 changes: 1 addition & 1 deletion src/package.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://www.mendix.com/package/1.0/">
<clientModule name="LoginForm widget" version="3.2.0" xmlns="http://www.mendix.com/clientModule/1.0/">
<clientModule name="LoginForm" version="3.2.0" xmlns="http://www.mendix.com/clientModule/1.0/">
<widgetFiles>
<widgetFile path="LoginForm/LoginForm.xml"/>
</widgetFiles>
Expand Down
Binary file modified test/LoginForm Test.mpr
Binary file not shown.
Binary file added test/LoginForm Test.mpr.bak
Binary file not shown.
Binary file modified test/widgets/LoginForm.mpk
Binary file not shown.