PDA

View Full Version : Login with ExtJS Django Ajax (Exchange message problem)



hitman47
4 Oct 2013, 2:56 AM
Hi all,
I work with ExtJs 4.2.1, Django 1.5.2, DB Postgresql 9.1.

I have a login form in my web site, which is shown after the user clicks on a button in a toolbar. After he/she inserts the credentials (username and password) and clicks on the Submit button, this information is sent to server.

On the server side a view.py script is called, in particular one method for login (def request_login(request)), where some checks for login and user authentication are done.
After these controls an httpResponse with text "success" or "error" is sent to the client. Unfortunately the client doesn't receive any message, but instead the index.html page.
I tried to change type of exchange's message with json, but the result is the same...no error/success message, instead the index.html page is returned.

I saw the Django's doc that explains a general situation: client with classical form (index.html) -> click on submit and send a message with method POST -> there is a view.py with some method that receives this informations -> server send the response with message. In generally there is a redirect in the same page if login is wrong or another page if login is succeffully. In my case I want that the login return in the same page (index.html).

Login form code:


var winLogin;

Ext.onReady(function(){
.........
if (formPanel.getForm().isValid()) {
Ext.Ajax.request({
url: 'editor/request_login',// call method in the django's view
method: 'POST',
params: {
username: user,
password: pass,
},
success: function (response, opts) {
var text = response.responseText;
Ext.Msg.alert('Success', text);
},
failure: function (response, opts) {
var text = response.responseText;
Ext.Msg.alert('Failure', text);
},
});

.........
});

existdissolve
4 Oct 2013, 3:26 AM
I have no clue about Django, but some quick Googling brought up some promising results: http://stackoverflow.com/questions/312925/django-authentication-and-ajax-urls-that-require-login

hitman47
30 Jan 2014, 7:59 AM
Ok, I found the error! In url option the path was wrong!

Thanks