cancel
Showing results for 
Search instead for 
Did you mean: 

Modifying Login to change error message

jlaramie9
Champ in-the-making
Champ in-the-making
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
5 REPLIES 5

zannafar
Champ in-the-making
Champ in-the-making
As I can see

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.

jlaramie9
Champ in-the-making
Champ in-the-making
Hi Diego,

Thanks for your reply!!!  I was trying to do your option 2, manipulate the error based on the "message" element, and had no success.  Would I do the validate/manipulation in login.post.json.ftl?  I tried getting the element in login.get.js and login.get.html.ftl.  I also tried making the "message" element be an argument to the page via the slingshot-login.xml but had no luck.  Would I just manipulate the login.post.json.ftl in the templates… directory?  Or can I copy it inside of the shared/extension and make changes there?

Thanks again for your help!!!!

Jim

zannafar
Champ in-the-making
Champ in-the-making
Hi jlaramie9,

Sorry for the question, I have some doubts about your post and I want to make sure what your problem is to help you better.

Are you using Alfresco Share login page? Is the Share login error message generic for you?
     - Do you want to change the label of this error message?
     - Or do you want to split this error message?

When you use Share login you do the following steps in background

1. Alfresco share login page (server:8080/share), clik en submit button
2. Alfresco redirects to dologin page (server:8080/share/dologin)
3. Dologin page calls login webscript in Alfresco tier
4. If success login, server redirect to server:8080/share/page, you are authenticated in Share!!
   If no success login, servevr redirec to login page with error variable in URL (server:8080/share/page/type/login?<strong>error=true</strong>)
5. In login page if error URL variable exist it show in bubble message: "The remote server may be unavailable or your authentication details have not been recognized."

So, if you want to change yo have to change dologin source class. I think this could be a complicated job. I would recommend to apply some validations in login page with JS client side, for example: if username text box is leaved blank disable submit button.

As niketapatel said, you could change the label of error popup modifying slingshot.properties in share/WEB-INF/classes/alfresco/messages or you could create a new .properties file with your custom labels.

I hope it helps.

Take care,
Diego.

niketapatel
Star Contributor
Star Contributor
If I understand it corrrectly, You want to disaply custom error message when user fails to login in Share UI and so you are extending alfresco webscript LoginPost just for your custom error message.

If its a static message for all possible scenarios then you can directly change message.loginautherror in customslingshot.properties which is geting displayed from login.get.html.ftl

Hop this help!

yroopa1229
Champ in-the-making
Champ in-the-making

Hi jlaramie9,

  I am also trying to change login error messages depends up on condition.if it is working successful can you please explain the steps.

Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.