我正在尝试使用Sencha Touch 2构建一个多日志系统,用户必须选择他是否为代理或自动。到目前为止,我已经能够提出一个简单的登录表单。没有功能。我的代码是这样的:
Ext.define("ikhlas.view.login", {
extend: 'Ext.Panel',
xtype: 'loginpanel',
config:{
title: 'Login',
iconCls: 'more',
styleHtmlContent: true,
layout:{
type: 'vbox',
},
items: [
{
xtype: 'fieldset',
iconCls: 'add',
items: [
{
xtype: 'emailfield',
name: 'email',
placeHolder: 'Username'
},
{
xtype: 'passwordfield',
name: 'password',
placeHolder: 'Password'
},
{
xtype: 'selectfield',
label: 'User Type',
options: [
{text: 'Agent', value: '0'},
{text: 'Follower', value: '1'}
]
}
]},
{
xtype: 'button',
text: 'LogIn',
ui: 'confirm',
width: '40%',
height: '7%',
flex: 1,
left: '55%',
action: 'submitContact'
},
{
xtype: 'button',
text: 'Forgot Username',
ui: 'confirm',
width: '41%',
height: '4%',
top: '90%',
flex: 1,
action: 'ForgotUsername'
},
{
xtype: 'button',
text: 'Forgot Password',
ui: 'confirm',
width: '40%',
height: '4%',
top: '90%',
flex: 1,
left: '47%',
action: 'ForgotPassword'
},
]}
});
现在我想知道如何从API验证用户信息(用户名和密码)(将给出一个URL),以便在允许访问之前确认登录用户名和密码是否正确应用程序。其次,如果用户名或密码不正确,我想抛出一条错误消息。
答案 0 :(得分:0)
很明显,您必须对服务器端进行身份验证。假设你已经拥有一个,那么剩下的并不是很难。
最简单的方法就是发送Ext.Ajax.request
:
Ext.Ajax.request({
url: your_API_url,
params: {
username: your_username_from_formpanel,
password: your_password_from_formpanel
},
timeout: 10000, // time out for your request
success: function(result) {
// here, base on your response, provide suitable messages
// and further processes for your users
},
failure: function(){
Ext.Msg.alert("Could not connect to server.");
}
});
注意:出于安全原因,您应该在将用户密码发送到服务器之前对其进行加密。