我使用 Sencha touch 2 制作了一个小型 Web 应用程序。我已经完成了登录页面。第二页的目的是获取发布产品的当前用户会话。这是登录页面
onSignInCommand: function (view, username, password) {
var me = this;
var loginView = this.getLoginView();
if (username.length == 0 || password.length == 0) {
loginView.showSignInMessage("Please enter your username and password.");
return;
}
loginView.setMasked({
xtype: "loadmask",
message:"Signing in..."
});
//Set ajax
Ext.Ajax.request({
url: "./ajax/Account.ashx",
params: {
type: "login",
username: username,
password: password
},
success: function (response) {
var loginResponse = Ext.JSON.decode(response.responseText);
if (loginResponse.success) {
me.sessionToken = loginResponse.sessionToken;
me.showSignInSuccess();
} else {
me.sessionToken = null;
me.showSignInFailedMessage(loginResponse.message);
}
},
failure: function () {
me.sessionToken = null;
me.showSignInFailedMessage('Login failed. Please try again later.');
}
});
}
和服务器端:
private void Login(HttpContext context)
{
var resultStt = "";
var userid = context.Request["username"];
var password = context.Request["password"];
if(!string.IsNullOrEmpty(userid) && !string.IsNullOrEmpty(password))
{
var user = new Select() .From<User>()
.Where("UserID").IsEqualTo(userid)
.And("UserPassword").IsEqualTo(password)
.ExecuteSingle<User>();
if(user!=null)
{
context.Session.Add("PickerUser",user);
resultStt = " {\"success\":true, \"user\":{ \"userId\":"+user.UserID+", \"sessionId\":\"" + context.Session.SessionID + "\"}}";
}
else
{
resultStt = " {\"success\":false, \"message\":\"Login failed. Please enter the correct credentials.\"}";
}
}
context.Response.Write(resultStt);
}
我需要的第二页获取用户创建的列表产品
store: {
autoload:true,
...
proxy: {
type: "ajax",
url: "./ajax/process.ashx?type=loadassigned",
reader:{
type:"json",
rootProperty: "data"
}
}
},
无法获取会话,因为在启动应用程序时加载了 ajax
var currenUser = context.Session["PickerUser"] as User;