You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by Rakhee Mohan <rm...@microsanconsulting.in> on 2019/08/05 18:46:47 UTC

login api- ajax call

	

	

	

	

Hi,

I am trying to  call to login api from ajax client.It is hitting the server.

Here I can only connect to the server.Is this process correct?Or should 
do any further improvements?I need the output in a json format.

I am sharing my code snippet used.

//controller.xml

  <request-map uri="login">
         <security https="true" auth="false"/>
         <event type="java" 
path="org.apache.ofbiz.webapp.control.LoginWorker" invoke="login"/>
         <response name="success" type="view" value="main"/>
         <response name="requirePasswordChange" type="view" 
value="requirePasswordChange"/>
         <response name="error" type="view" value="login"/>
         <response name="response" type="request" value="json" />
     </request-map>

Sample ajax code:


<head>
LOGIN AUTHENTICATION
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

</head>

<body>
<br>

Username: <input type="text" name="username" value="admin" id="na"><br>
Password: <input type="password" name="password" value="ofbiz" id="pa"><br>
           <button name="login" id="login">Login</button>

<script>



$("#login").click(function(){

     var username = $('#na').val();
     alert("user"+ username);
     var password = $('#pa').val();
     alert("pass" +password);
     $.ajax({
         url: 'https://localhost:8443/ordermgr/control/login.json',
         type:"POST",
         datatype : "application/json",
         //contentType: "text/plain",
         contentType: "json",
         data: {username:username,password:password},

         success: function() {
         alert("success");
         window.location.href = 
"https://localhost:8443/ordermgr/control/login.";
         return true;

     },
           error: function(){
           alert("wrong data");
           }

     });
});


</script>

</body>
</html>




Kind Regards,

Rakhee Mohan.I



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

Re: login api- ajax call

Posted by Aditya Sharma <ad...@apache.org>.
Hi Rakhee Mohan,


>>         <response name="response" type="request" value="json" />
Have you done any custom change LoginWorker.login() corresponding to this
response.


Thanks & Regards
Aditya Sharma



On Mon, Aug 5, 2019 at 11:46 AM Rakhee Mohan <rm...@microsanconsulting.in>
wrote:

>
>
>
>
>
>
>
>
>
> Hi,
>
> I am trying to  call to login api from ajax client.It is hitting the
> server.
>
> Here I can only connect to the server.Is this process correct?Or should
> do any further improvements?I need the output in a json format.
>
> I am sharing my code snippet used.
>
> //controller.xml
>
>   <request-map uri="login">
>          <security https="true" auth="false"/>
>          <event type="java"
> path="org.apache.ofbiz.webapp.control.LoginWorker" invoke="login"/>
>          <response name="success" type="view" value="main"/>
>          <response name="requirePasswordChange" type="view"
> value="requirePasswordChange"/>
>          <response name="error" type="view" value="login"/>
>          <response name="response" type="request" value="json" />
>      </request-map>
>
> Sample ajax code:
>
>
> <head>
> LOGIN AUTHENTICATION
> <script type="text/javascript"
> src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
> "></script>
>
> </head>
>
> <body>
> <br>
>
> Username: <input type="text" name="username" value="admin" id="na"><br>
> Password: <input type="password" name="password" value="ofbiz" id="pa"><br>
>            <button name="login" id="login">Login</button>
>
> <script>
>
>
>
> $("#login").click(function(){
>
>      var username = $('#na').val();
>      alert("user"+ username);
>      var password = $('#pa').val();
>      alert("pass" +password);
>      $.ajax({
>          url: 'https://localhost:8443/ordermgr/control/login.json',
>          type:"POST",
>          datatype : "application/json",
>          //contentType: "text/plain",
>          contentType: "json",
>          data: {username:username,password:password},
>
>          success: function() {
>          alert("success");
>          window.location.href =
> "https://localhost:8443/ordermgr/control/login.";
>          return true;
>
>      },
>            error: function(){
>            alert("wrong data");
>            }
>
>      });
> });
>
>
> </script>
>
> </body>
> </html>
>
>
>
>
> Kind Regards,
>
> Rakhee Mohan.I
>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>