lholland421 Posted August 14, 2014 Posted August 14, 2014 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!
nickbro Posted August 14, 2014 Posted August 14, 2014 (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 August 14, 2014 by nickbro
lholland421 Posted August 14, 2014 Author Posted August 14, 2014 Thanks for the Reply nick! i will try and figure that out and how i can use it Thanks!
lholland421 Posted August 18, 2014 Author Posted August 18, 2014 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
nickbro Posted August 18, 2014 Posted August 18, 2014 You will need to make sure you use the AJAX function not post, it requires the contentType (application/json) and set the dataType to json
lholland421 Posted August 19, 2014 Author Posted August 19, 2014 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 !
nickbro Posted August 19, 2014 Posted August 19, 2014 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
lholland421 Posted August 19, 2014 Author Posted August 19, 2014 Thanks Nick ! I have put that up on the site here: http://dev.st-augustines.worcs.sch.uk/Home/PortalLogin.html I guess im probably missing something on my server configuration as when i click submit it does nothing, Sorry for the hassle. Thanks
nickbro Posted August 19, 2014 Posted August 19, 2014 If you use firebug it usually will tell you what is wrong, in my case it was stupid cors
lholland421 Posted August 19, 2014 Author Posted August 19, 2014 Thanks for your help Nick ! All working now ! The problem was with cors . I had put it in the wrong place. Thanks !
lholland421 Posted August 19, 2014 Author Posted August 19, 2014 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now