AnsweredAssumed Answered

calling change password rest api from a webscript without login

Question asked by skumar.us on Jun 24, 2015
Latest reply on Jul 3, 2015 by skumar.us
I have written a webscript to change the password of alfresco which need to be called from outside alfresco.
I have taken the webscript from change password module.The problem I am facing here is the webscript is registered as a share webscript . when I am calling this with the admin user ticket, it is returning false.
what are the changes need to be done in the controller script If I have to register it as a repo webscript?

/**
* User Profile Change Password Update method
*
* @method POST
*/

function main()
{
   var oldpass = args.oldpassword;
   var newpass1 = args.newpassword;
   logger.log("here");
  
   // ensure we have valid values and that the new passwords match
  
      // perform the REST API to change the user password
      var params = new Array(2);
      params["oldpw"] = oldpass;
      params["newpw"] = newpass1;
      var connector = remote.connect("alfresco");
      var result = connector.post(
            "/api/person/changepassword/" + args.username,
            jsonUtils.toJSONString(params),
            "application/json");
      if (result.status.code == 401)
      {
         model.success = false;
         if (result.status.message != "")
         {
            model.errormsg = result.status.message;
         }
         else
         {
            // The proxy has eaten the message
            // This is caused by some SSO compatibility code somewhere…
            model.errormsg = msg.get("message.passwordchangeauthfailed");
         }
      }
      else
      {
         var repoJSON = JSON.parse(result);
         if (repoJSON.success !== undefined)
         {
            model.success = repoJSON.success;
         }
         else
         {
            model.success = false;
            model.errormsg = repoJSON.message;
         }
      }
 
}

main();


<webscript>
  <shortname>Change Password POST</shortname>
  <description>Change user password POST form submission processing</description>
  <format default="json" />
  <url>/components/profile/ChangePasswordPostWebscript</url>
  <arg>
      <shortname>username</shortname>
   </arg>
   <arg>
      <shortname>oldpassword</shortname>
   </arg>
   <arg>
      <shortname>newpassword</shortname>
   </arg>
   <arg>
      <shortname>alf_ticket</shortname>
   </arg>
   
  <authentication>user</authentication>
</webscript>

<code>
{
   "success": ${success?string},
   "message": "<#if errormsg??>${errormsg}</#if>"
}
<code>

Outcomes