PDA

View Full Version : ASP login help please



tasomaniac
5 May 2011, 12:28 AM
I have a webpage that only has a username password form and a login button. It works OK. I want to make the same page using Sencha Touch. But I simply couldn't.

The original page is: http://home.ku.edu.tr/~sdane/denem.htm

The one I am trying to do is: http://home.ku.edu.tr/~sdane/sensa/examples/forms/

And the Sencha Touch js code is:

Ext.setup({
icon: 'icon.png',
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
glossOnIcon: false,
onReady: function() {

var form;

Ext.regModel('User', {
fields: [
{name: 'USERID', type: 'string'},
{name: 'PASSWORD', type: 'password'}
]
});


var formBase = {
scroll: 'vertical',
url : 'https://ais.ku.edu.tr/kuaiss/frmSLogin.asp',
standardSubmit : false,
items: [{
xtype: 'fieldset',
id: 'loginFormSet',
title: 'KUAIS Student Authentication',
instructions: 'Please enter your User ID and Password.',
defaults: {
labelAlign: 'left',
labelWidth: '40%'
},
items: [
{
xtype: 'textfield',
name : 'USERID',
id: 'USERID',
label: 'Name',
useClearIcon: true,
autoCapitalize : false,
allowBlank: false
}, {
xtype: 'passwordfield',
name : 'PASSWORD',
label: 'Password',
useClearIcon: false,
allowBlank: false
}]
}],
listeners : {
submit : function(form, result){
console.log('success', Ext.toArray(arguments));
},
exception : function(form, result){
console.log('failure', Ext.toArray(arguments));
}
},

dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
items: [
{xtype: 'spacer'},
{
text: 'Reset',
handler: function() {
form.reset();
}
},
{
xtype: 'button',
text: 'Login',
ui: 'confirm',
scope:this,
handler: function() {
form.submit({
url : 'https://ais.ku.edu.tr/kuaiss/frmSLogin.asp',

method:'POST',
//params: {USERID: form.getValues().USERID, PASSWORD : form.getValues().PASSWORD},

waitTitle:'Connecting',
waitMsg:'Sending data...',


success:function(){
Ext.Msg.alert('Status', 'Login Successful!', function(btn, text){
if (btn == 'ok'){
var redirect = 'http://tasomaniac.com';
window.location = redirect;
}
});
},

failure:function(response, opts){
if(opts.failureType == 'server'){
obj = Ext.util.JSON.decode(opts.response.responseText);
Ext.Msg.alert('Login Failed!', obj.errors.reason);
}else{
Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + opts.response.responseText);
}
form.reset();
},
scope:this
});

}
}
]
}
]
};

var doLogin1 = function()
{
if(formBase.user){
form.updateRecord(formBase.user, true);
}
form.submit({
waitMsg : {message:'Submitting', cls : 'demos-loading'}
});
var LoginData = new Object;
LoginData.USERID = form.getValues().USERID;
LoginData.PASSWORD = form.getValues().PASSWORD;
Ext.Msg.alert('Login Error', data.errorMessage, Ext.emptyFn);

Ext.Ajax.request({
url : 'https://ais.ku.edu.tr/kuaiss/frmSLogin.asp',
method: 'POST',
//params: {USERID: form.getValues().USERID, PASSWORD : form.getValues().PASSWORD},
failure : function(response, opts){
data = Ext.decode(response.responseText);
Ext.Msg.alert('Login Error', data.errorMessage, Ext.emptyFn);
},
success: function(response, opts) {
data = Ext.decode(response.responseText);
if (data.errorMessage != null)
{
Ext.Msg.alert('Login Error', data.errorMessage, Ext.emptyFn);
mainPanel.setLoading(false);
} else {
form.hide();
//hide the Loading mask
//mainPanel.setLoading(false);
//show the next screen
//mainPanel.setActiveItem(dashboard, 'slide');
}
},
scope: this,
jsonData: LoginData
});
}
if (Ext.is.Phone) {
formBase.fullscreen = true;
} else {
Ext.apply(formBase, {
autoRender: true,
floating: true,
modal: true,
centered: true,
hideOnMaskTap: false,
height: 385,
width: 480
});
}

form = new Ext.form.FormPanel(formBase);
form.show();
}
});

bnw
5 May 2011, 1:49 AM
I used this simply form. I don't know if can be useful for you:


Ext.setup({
onReady: function() {
var formBase = {
id: 'formLogin',
scroll: 'vertical',
standardSubmit: true,
method: 'POST',
items: [
{
xtype: 'fieldset',
title: 'Login',
instructions: '',
defaults: {
required: true,
labelAlign: 'left'
},
items: [
{
xtype: 'textfield',
name: 'Username',
label: 'Username'
},
{
xtype: 'passwordfield',
name: 'Password',
label: 'Password'
}
]
},
{
xtype: 'button',
width: 150,
centered: true,
text: "Accedi",
handler: function() {
form.submit({
waitMsg: { message: 'Submitting', cls: 'demos-loading' },
url: 'Login.aspx'
}
});
}
}
]
}; //formBase
formBase.fullscreen = true;
form = new Ext.form.FormPanel(formBase);
form.show();
} //onReady
});

tasomaniac
5 May 2011, 2:33 AM
Ok this simply works. Thank you.

Now, it redirects to the webpage but I want to redirect to another webpage. How can I do that?
I want to bypass the actual thing and show a sencha touch menu.

adding

succes:function()
{
}

doesn't work.

bnw
5 May 2011, 3:04 AM
This is my problem too!
In this moment I make a redirect to another page from the server side of my application if the result of login operation was ok, but i would like to make this in another way.

In my application, login operation returns a code that I use to show a list in another page.
I'm not able to use this code to make a redirect as i like.

I hope that someone may be helpful.

P.S. Sorry for my english! :">

AndreaCammarata
5 May 2011, 6:18 AM
Hi guys.
I had to face the some problem in Ext JS some months ago, and I tell you how I fixed.
The issue is caused because "window.location" seems doesn't work inside the async success function, so I solved in two steps:

First Step
Define a custom delay function



function loginCompleted(){
window.location = '/app.html';
}


Second Step
Call the custom function with SetTimeout function.



success: function() {
setTimeout('loginCompleted()', 500);
}


This makes the trick ;)
Hope this Help.

bnw
5 May 2011, 6:59 AM
Thank you Andrea for the answer!

Your solution in my project dont'work! :((

I've always the problem of passing parameters from one page to another.
In fact i qould like to send parameters in post and not in the query string.

Unfortunately for me this situation is in different page and still i've not found a workable solution.

Thanks in advance!

AndreaCammarata
5 May 2011, 11:22 PM
Hi bnw.
I can't understand your problem: Do you want to make a redirect, you want to make an AjaxRequest to another page to get some new data from serverside, or you want to display a new panel? :)

Are you targeting your application to Desktop Browser (Safari / Chrome)?
I ask you because if you say that you want to load a list in another page (on mobile device), this mean that you want to exit your application and open a new page to display a list.

Alternativelly, why don't you render the the main application viewport (with your list) only when the login is completed inside the same page?

Hope this Helps.

tasomaniac
6 May 2011, 2:01 AM
I have the same problem also. Your advise didnt work for me.

I am currently trying to make a mobile webpage. When I press login button, if the username and password are correct, it redirects to the original page. But I want to login and keep cookies but display another 'menu page'. How can I do that?

I am know trying to overwrite the submit function but i couldn't. Thank you.

bnw
17 May 2011, 12:29 AM
Alternativelly, why don't you render the the main application viewport (with your list) only when the login is completed inside the same page?


Hi Andrea!
Sorry for delay but i was focused in other acitivities.

Have you any advice on what i've quoted?

Thanks in advance!