I've been working with Alfresco Community adapting it to my company needs for a couple months with the help of a lot of great information from this forum but I've hit a wall. We are looking to show specific error messages on the login page when a user has not been successful. I copied the LoginPost class and have been able to catch the bubbled up error message I want to display. With some server side logging of the response being written I verified the JSON data has the new error message set in the data as "message" and here it is:
{
"status" :
{
"code" : 403,
"name" : "Forbidden",
"description" : "Server understood the request but refused to fulfill it."
},
"message" : "08270001 Invalid Credentials",
"exception" : "",
"callstack" :
[
],
"server" : "Community v4.2.0 (4576) schema 6,022",
"time" : "Sep 27, 2013 10:57:01 AM"
}
I tried accessing it in the ftl as {message}, I tried making it a argument to the login.get.js by editing slingshot-login.xml and changing the properties from
<!– Login form –>
<component>
<region-id>components</region-id>
<url>/components/guest/login</url>
<properties>
<error>{error}</error>
</properties>
</component>
</components>
to
<!– Login form –>
<component>
<region-id>components</region-id>
<url>/components/guest/login</url>
<properties>
<error>{error}</error>
<errorDisplay>{message}</errorDisplay>
</properties>
</component>
</components>
I even tried {data.message} as another programmer suggested that "most" JSON developers call the JSON string used as a parameter to the function as data. I also tried to pass the data into the page via the Map returned by the executeImpl method but to no avail. My gut says that it has to do with the error status that is set but don't know. Any ideas, I'm left scratching my head???
Thanks for any help,
Jim
{
"status" :
{
"code" : 403,
"name" : "Forbidden",
"description" : "Server understood the request but refused to fulfill it."
},
"message" : "08270001 Invalid Credentials",
"exception" : "",
"callstack" :
[
],
"server" : "Community v4.2.0 (4576) schema 6,022",
"time" : "Sep 27, 2013 10:57:01 AM"
}
I tried accessing it in the ftl as {message}, I tried making it a argument to the login.get.js by editing slingshot-login.xml and changing the properties from
<!– Login form –>
<component>
<region-id>components</region-id>
<url>/components/guest/login</url>
<properties>
<error>{error}</error>
</properties>
</component>
</components>
to
<!– Login form –>
<component>
<region-id>components</region-id>
<url>/components/guest/login</url>
<properties>
<error>{error}</error>
<errorDisplay>{message}</errorDisplay>
</properties>
</component>
</components>
I even tried {data.message} as another programmer suggested that "most" JSON developers call the JSON string used as a parameter to the function as data. I also tried to pass the data into the page via the Map returned by the executeImpl method but to no avail. My gut says that it has to do with the error status that is set but don't know. Any ideas, I'm left scratching my head???
Thanks for any help,
Jim
LoginPost class is the web script controller for "login.post" webscript in Alfresco tier, in this class, when an error presents, WebScriptException is catched and webscript is redirected to a standard status template, in the following lines:
try
{
return login(username, password);
}
catch(WebScriptException e)
{
status.setCode(e.getStatus());
status.setMessage(e.getMessage());
status.setRedirect(true); /********** HERE *********/
return null;
}
Status templates in webscripts allow to present errors easy without having to create error presentation in FTL templates. So login.post.json.ftl is never called, and as you can see there are no information in your FTL about this error.
You have 2 options here, in the code instead call status templates you can create an "errorMessaje" in model Map to recover this in login.post.json.ftl, but remember a good practice in Alfresco is never change code.
Another option is in Share in login page that is calling this webscript you could validate this JSON response, the main part in status templates is the following element: "message" : "08270001 Invalid Credentials", so you could manipulate or create a custom error message in Share based in this "message" element.
Making some tests I've checked that only 2 error messages could be returned from this webscript in Share login calls.
1. "message" : "08300006 Username not specified"
2. "message" : "08300007 Login failed"
I hope it helps!
Best regards,
Diego.