如何把我的登录与角度不同用户级别
我怎么把我的登录与用户diffent级这样的水平,如果其1用户的超级管理员,如果2用户的管理员,如果它的3其采用我采用了棱角分明的NodeJS 7和MongoDB这是链接到我的项目
这是我的代码
AUTH文件getUserDetails(用户名,密码){返回this.http.post( 'API /登录',{用户名,密码})}
登录组件
login() {
let username = this.loginForm.value.username;
let password = this.loginForm.value.password;
this.Auth.getUserDetails(username,password).subscribe(data =>{
if(data.success){
this.router.navigate(['homepage'])
this.Auth.setLoggedIn(true)
//sdsadad
}else{
document.getElementById("erro").style.visibility = "visible";
window.setTimeout("location.href='login'",3000);
}
})
}
nodejs
app.post('/api/login', async (req,res)=>{
const {username,password}=req.body
const resp = await User.findOne({ username: username}).select('+password')
if(password==null){
res.json({success:false,
message:" password can not be empty"
})
}else if(username==null){
res.json({success:false,
message:" username can not be empty "
})
}
else if(!resp){
res.json({success:false,
message:"incorrect password"
})
}
else if(!await bcryptpare(password, resp.password)){
//if(!resp){
res.json({success:false,
message:"incorrect password"
})
}else {
///sessions
req.session.user=username
req.session.save()
res.json({
success:true
})
}
})
回答如下:
// declare golbal variable
responce: any;
login() {
let username = this.loginForm.value.username;
let password = this.loginForm.value.password;
this.Auth.getUserDetails(username, password).subscribe(data => {
this.responce = data
if (this.responce.user == 'level1') {
this.router.navigate(['homepage'])
this.Auth.setLoggedIn(true)
//sdsadad
} else if (this.responce.user == 'level2') {
this.router.navigate(['secondpage'])
}
else if (this.responce.user == 'level3') {
this.router.navigate(['thirdpage'])
}
})
}
如何把我的登录与角度不同用户级别
我怎么把我的登录与用户diffent级这样的水平,如果其1用户的超级管理员,如果2用户的管理员,如果它的3其采用我采用了棱角分明的NodeJS 7和MongoDB这是链接到我的项目
这是我的代码
AUTH文件getUserDetails(用户名,密码){返回this.http.post( 'API /登录',{用户名,密码})}
登录组件
login() {
let username = this.loginForm.value.username;
let password = this.loginForm.value.password;
this.Auth.getUserDetails(username,password).subscribe(data =>{
if(data.success){
this.router.navigate(['homepage'])
this.Auth.setLoggedIn(true)
//sdsadad
}else{
document.getElementById("erro").style.visibility = "visible";
window.setTimeout("location.href='login'",3000);
}
})
}
nodejs
app.post('/api/login', async (req,res)=>{
const {username,password}=req.body
const resp = await User.findOne({ username: username}).select('+password')
if(password==null){
res.json({success:false,
message:" password can not be empty"
})
}else if(username==null){
res.json({success:false,
message:" username can not be empty "
})
}
else if(!resp){
res.json({success:false,
message:"incorrect password"
})
}
else if(!await bcryptpare(password, resp.password)){
//if(!resp){
res.json({success:false,
message:"incorrect password"
})
}else {
///sessions
req.session.user=username
req.session.save()
res.json({
success:true
})
}
})
回答如下:
// declare golbal variable
responce: any;
login() {
let username = this.loginForm.value.username;
let password = this.loginForm.value.password;
this.Auth.getUserDetails(username, password).subscribe(data => {
this.responce = data
if (this.responce.user == 'level1') {
this.router.navigate(['homepage'])
this.Auth.setLoggedIn(true)
//sdsadad
} else if (this.responce.user == 'level2') {
this.router.navigate(['secondpage'])
}
else if (this.responce.user == 'level3') {
this.router.navigate(['thirdpage'])
}
})
}