Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `getUserDetails(username,password){ return this.http.post('api/login',{ username, password }`) }
- 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);
- }
- })
- }
- 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 bcrypt.compare(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
- })
- }
- })
Add Comment
Please, Sign In to add comment