Guest User

Untitled

a guest
Feb 11th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. `getUserDetails(username,password){ return this.http.post('api/login',{ username, password }`) }
  2.  
  3. login() {
  4. let username = this.loginForm.value.username;
  5. let password = this.loginForm.value.password;
  6. this.Auth.getUserDetails(username,password).subscribe(data =>{
  7. if(data.success){
  8. this.router.navigate(['homepage'])
  9. this.Auth.setLoggedIn(true)
  10. //sdsadad
  11. }else{
  12. document.getElementById("erro").style.visibility = "visible";
  13. window.setTimeout("location.href='login'",3000);
  14.  
  15. }
  16. })
  17.  
  18. }
  19.  
  20. app.post('/api/login', async (req,res)=>{
  21. const {username,password}=req.body
  22. const resp = await User.findOne({ username: username}).select('+password')
  23. if(password==null){
  24. res.json({success:false,
  25. message:" password can not be empty"
  26. })
  27. }else if(username==null){
  28. res.json({success:false,
  29. message:" username can not be empty "
  30. })
  31. }
  32. else if(!resp){
  33. res.json({success:false,
  34. message:"incorrect password"
  35. })
  36.  
  37. }
  38. else if(!await bcrypt.compare(password, resp.password)){
  39. //if(!resp){
  40.  
  41. res.json({success:false,
  42. message:"incorrect password"
  43. })
  44. }else {
  45. ///sessions
  46. req.session.user=username
  47. req.session.save()
  48.  
  49. res.json({
  50. success:true
  51. })
  52.  
  53. }
  54. })
Add Comment
Please, Sign In to add comment