cancel
Showing results for 
Search instead for 
Did you mean: 

[WebScript] Call the 'changepassword' webscript from another

tegel
Champ in-the-making
Champ in-the-making
I want create a webscript to update the password of the user who connected to Alfresco.

I use the latest version of Alfresco (V3) so I want to call the webscript "/api/person/changepassword/{userName}, {oldpw}, {newpw}" in my WS as folow:

changer-pwd.get.js


for each (field in formdata.fields)
{
   if (field.name == "oldpassword")
   {
      oldpass = field.value;
   }
   else if (field.name == "newpassword1")
   {
      newpass1 = field.value;
   }
   else if (field.name == "newpassword2")
   {
      newpass2 = field.value;
   }
   else if (field.name == "username")
   {
      username = field.value;
   }
}

// ensure we have valid values and that the new passwords match
if (newpass1.equals(newpass2))
{
   // 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 user = people.getPerson(username);

   var result = connector.post(
         "/api/person/changepassword/" + stringUtils.urlEncode(user.name),
         jsonUtils.toJSONString(params),
         "application/json");
  var repoJSON = eval('(' + result + ')');
   //test.content = test.content + "\n repoJSON" + repoJSON ;
  
   if (repoJSON.success !== undefined)
   {
      model.success = repoJSON.success;
   }
   else
   {
      model.success = false;
      model.errormsg = repoJSON.message;
   } 
}
else
{
   model.success = false;
}

but it couldn't be executed because the remote.connect is unknown.

Is there a way to solve this problem?

Thanks in advance.
1 REPLY 1

sgartner
Champ on-the-rise
Champ on-the-rise
This is an old question, but I recently found the answer so I thought I'd post.  I found the answer at Dr. Q's Workshop at http://drquyong.com/myblog/?p=49.

Here it is (in case the Dr. Q page goes away):
One very useful root script object available for Alfresco Share or SURF extension is the “remote” object which is a configurable object that enables webscript controller ( the JavaScript template ) to invoke other REST-style services including both external services ( such as Yahoo Weather service) and internal services ( such as Alfresco CMIS services).

However the remote root script object is not enabled as default and you won’t be able to use it for repository side webscripts. To enable and use it in your repository side webscripts, you only need to make change to the following two configuration XML files.

1) WEB-INF\classes\alfresco\web-scripts-application-context.xml

You need to add a new entry which references to the remote object to the scriptObjects property of the webscripts.container bean.


<bean id="webscripts.container"
class="org.alfresco.repo.web.scripts.RepositoryContainer"
parent="webscripts.abstractcontainer">
      <property name="name"><value>Repository</value></property>
      <property name="scriptObjects">
         <map merge="true">
           <entry key="paging">
              <ref bean="webscripts.js.paging" />
           </entry>
           <!– add remote entry –>
           <entry key="remote" value-ref="webscripts.script.remote" />
         </map>
      </property>
……
</bean>

2) WEB-INF\classes\alfresco\webscript-framework-config.xml

To invoke external services, we need to add the http endpoint


……
<endpoint>
  <id>http</id>
  <name>HTTP access</name>
  <description>Generic HTTP connector</description>
  <connector-id>http</connector-id>
  <endpoint-url></endpoint-url>
  <identity>none</identity>
  <unsecure>true</unsecure>
</endpoint>
……

Once we make the changes, we need to restart Alfresco server and we should be able to use the remote object in our web scripts.

Thank you Dr. Q.