Jump to content

Recommended Posts

Posted

Hi, I am trying to create a simple php form to put on my website as a login straight from the front page to Home access plus.

 

Here's the code i am trying to use.

</pre><form action="https://portal.st-augustines.worcs.sch.uk/HAP/login.aspx" method="post" name="form" id="form">
 

 

 

</form><b

 

The problem i have is that it isnt logging me into HAP its just showing me the login page. Where have i gone wrong?

 

I am using Wordpress for my website if that helps at all ?

Thanks!

Posted (edited)

You won't be able to use that code to auto login, as ASP.net will reject the post as it doesn't contain a session id or any other .net related fields.

 

There is however a JSON API which you can use (it's actually used by the Win 8 App).

 

Do a jquery POST call to /api/ad/

 

/hap/api/ad/?2345666

{ "Username": "someusername", "Password": "somepassword" }

application/json

 

This is what is returned:

{
   "FirstName":"String content",
   "SiteName":"String content",
   "Token1":"String content",
   "Token2":"String content",
   "Token2Name":"String content",
   "Username":"String content",
   "isValid":true
}

 

You then set 2 cookies, one is called "token" with the content of Token1, the other is called he content of Token2Name, with the content of Token2. Set this as a session cookie, is a HTTPS cookie.

 

That should be all you need to do, in theory.

 

In theory someone could write a php front end for HAP+ and just use the .net system as a back end JSON server. In theory.

Edited by nickbro
Posted

HI Nick, I have come up with some code but cannot seem to get a reply at all. i know i am doing something wrong as im new to programming.

 

heres my code

 





<br />
$(document).ready(function(){<br />
  $("button").click(function(){<br />
    $.post("https://portal.st-augustines.worcs.sch.uk/hap/api/ad/application/json",<br />
    {<br />
      Username:"hapusername",<br />
      Password:"happassword"<br />
    },<br />
    function(data,status){<br />
      alert("Data: " + data + "\nStatus: " + status);<br />
    });<br />
  });<br />
});<br />





Send a Rquest






I am doing this to test to see if i can get a reply.

 

Any help would be good

Posted

Thanks for your help so far Nick appreciated

 

Here is what i have now, still cant seem to get any response.

 



<br />
$(document).ready(function(){<br />
  $("button").click(function(){<br />
var formData = {Username:"someusername",Password:"somepassword"};<br />
    $.ajax({<br />
    url : "https://portal.st-augustines.worcs.sch.uk/hap/api/ad/application/json",<br />
    type: "POST",<br />
	contentType:"application/json",<br />
	dataType:"json",<br />
    data : formData,<br />
    success: function(data, textStatus, jqXHR)<br />
    {<br />
        //data - response from server<br />
    },<br />
    error: function (jqXHR, textStatus, errorThrown)<br />
    {<br />
 <br />
    }<br />
    <br />
   });<br />
  });<br />
});<br />



Send POST

 

Thanks Nick !

Posted

Ok, here's some working code, some changes are needed to the web.config file

 

Add this to the element:

        
           
               
           
       

You can replace * with your top level domain name if you want, e.g. st-augustines.worcs.sch.uk

 

This is my test code I then used:




   
   
   


   Username: 
   

   Password: 
   

   
   <br />
        $("#login").click(function () {<br />
            $.ajax({<br />
                url: "https://portal.st-augustines.worcs.sch.uk/hap/api/ad/" + $("#username").val() + "/" + $("#password").val(),<br />
                type: "GET",<br />
                success: function (data, textStatus, jqXHR) {<br />
                    Set_Cookie("token", data.Token1.replace(" ", "+"), "/", ".st-augustines.worcs.sch.uk", true)<br />
                    Set_Cookie(data.Token2Name, data.Token2, "/", ".st-augustines.worcs.sch.uk", true)<br />
                    location.href = "https://portal.st-augustines.worcs.sch.uk/hap/";<br />
                },<br />
                error: function (jqXHR, textStatus, errorThrown) {<br />
<br />
                }<br />
            });<br />
            return false;<br />
        });<br />
<br />
        function Set_Cookie(name, value, path, domain, secure) {<br />
            document.cookie = name + "=" + value +<br />
            ((path) ? ";path=" + path : "") +<br />
            ((domain) ? ";domain=" + domain : "") +<br />
            ((secure) ? ";secure" : "");<br />
        }<br />
    

 

You will need to add a way of detecting failed logins.

 

The one problem with this method is it doesn't allow the user to log off unless they close the browser. One way of possibly solving could be via setting the forms authentication domain component to the top level domain

 

Then to the element add domain=".st-augustines.worcs.sch.uk"

 

But I haven't tested that

Posted

Just been thinking about the failed login, i assume that when the wrong username and password is entered HAP gives an error back. Could i not code it so upon error display Wrong username and password?

 

Thanks Nick

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...