我如何获得使用API验证SQL Management中的用户名和密码? [英] How I get & validate the username and password in SQL Management using API?
问题描述
我创建了登录页面,我想验证用户名和密码.然后,我需要使用API从数据库中获取用户详细信息.请给我发送使用ionic-3和angular-2的编码.
I created my login page and i want to validate the username and password. Then i need to get the user details using API from the database. please send me a coding using ionic-3 and angular-2.
我已经在SQL中尝试过.但是我想要在SQL管理中使用它.在下面的编码中,我使用post
方法发送参数,它将在后端获取并使用已注册的用户名和密码进行验证.
I already tried in my SQL. But i want it in SQL management. In the below coding i send the parameters using post
method and it will get at back end and validate with already registered username and password.
Username: any;
Password: any;
data:string;
constructor( ){}
//declaration of object//
var headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json' );
let option = new RequestOptions({headers: headers });
let data = {
username: this.Username.value,
password: this.Password.value
};
let loader = this.loading.create({
spinner: 'bubbles',
duration: 1000
});
//API call//
loader.present().then(() => {
this.http.post('')
.map(res => res.json())
.subscribe(res => {
console.log(res)
loader.dismiss()
if(res=="Your Login Success"){
let alert = this.altCtrl.create({
title:"CONGRATS",
subTitle:(res),
buttons: ['OK']
});
alert.present().then(()=>
this.navCtrl.push(NextPage));
}
else{
let alert = this.altCtrl.create({
title:"ERROR",
subTitle:"Your Login Username or Password is invalid",
buttons: ['OK']
});
alert.present();
}
},(err) => {
});
});
}
我希望如果用户名或密码错误,它应该显示警报用户名或密码错误".否则,它将以您的登录成功"推送到下一页.
I expect if the username or password is wrong it should show alert "username or password incorrect". in else it will push to the next page with "your login success".
推荐答案
您应该执行以下操作:
在您的Login.ts中
in your Login.ts
let loginObject = {
username: userInputValueFromUsername
password: userInputValueFromPassword
}
this.headers = {'Content-Type':'application/json'}; // set Headers for the Request
this.http.post('https://somew-url.com/api/login', JSON.stringify(loginObject), {headers: this.headers})
.subscribe(data => {
console.log(data);
if (data.success == true) {
//push to new Page
}
else{
// Show Error
}
});
这篇关于我如何获得使用API验证SQL Management中的用户名和密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!