-
Notifications
You must be signed in to change notification settings - Fork 0
/
loginrouter.js
60 lines (49 loc) · 1.6 KB
/
loginrouter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import jwt from 'jsonwebtoken'
import bcrypt from 'bcrypt'
import { client } from './index.js';
import dotenv from 'dotenv'
import express from 'express';
import nodemailer from 'nodemailer'
var login = express.Router()
login.post("/",async function(req,res){
var {username,password} = req.body
let result =await client.db("movie").collection("users")
.findOne({username});
if(!result){
return res.status(401).send({msg:"invalid creditial"})
}else{
const storedPassword = result.password;
var comparepassword = await bcrypt.compare(password,storedPassword);
if(comparepassword){
const token = await jwt.sign({id:result._id},process.env.key)
async function nodemail(){
var transfer = nodemailer.createTransport({
service:"hotmail",
auth:{
user:"example@gmail.com",
pass:"sljdjshds"
}
})
const options={
from:"santhoshbalaji304@gmail.com",
to:username,
subject:"sending mail from the scratch",
text:"hello this is santhosh am from the guvi network"
}
transfer.sendMail(options,(err)=>{
if(err){
console.log(err)
}else{
console.log({msg:"mail send"})
}
})
transfer.verify()
}
nodemail()
res.send({msg:"login sucessfully",token:token})
}else{
res.status(401).send({msg:"invalid creditial"})
}
}
})
export const logins = login