Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
shahbaz-rao committed May 17, 2022
2 parents b8b98e2 + 8b40078 commit 5db5df4
Show file tree
Hide file tree
Showing 28 changed files with 804 additions and 80 deletions.
6 changes: 3 additions & 3 deletions backend/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"files": {
"main.css": "/static/css/main.e6c13ad2.css",
"main.js": "/static/js/main.d833e689.js",
"main.js": "/static/js/main.0e85d97e.js",
"static/js/787.16cf1214.chunk.js": "/static/js/787.16cf1214.chunk.js",
"index.html": "/index.html",
"main.e6c13ad2.css.map": "/static/css/main.e6c13ad2.css.map",
"main.d833e689.js.map": "/static/js/main.d833e689.js.map",
"main.0e85d97e.js.map": "/static/js/main.0e85d97e.js.map",
"787.16cf1214.chunk.js.map": "/static/js/787.16cf1214.chunk.js.map"
},
"entrypoints": [
"static/css/main.e6c13ad2.css",
"static/js/main.d833e689.js"
"static/js/main.0e85d97e.js"
]
}
2 changes: 1 addition & 1 deletion backend/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.d833e689.js"></script><link href="/static/css/main.e6c13ad2.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Attendence App</title><script defer="defer" src="/static/js/main.0e85d97e.js"></script><link href="/static/css/main.e6c13ad2.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
Binary file modified backend/build/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions backend/build/static/js/main.0e85d97e.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/build/static/js/main.0e85d97e.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions backend/build/static/js/main.d833e689.js

This file was deleted.

1 change: 0 additions & 1 deletion backend/build/static/js/main.d833e689.js.map

This file was deleted.

53 changes: 47 additions & 6 deletions backend/controllers/attendance_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const fs = require("fs");

module.exports.attendance = async (req, res) => {
const DateStr = new Date(req.body.Date);
console.log("Body Date ",req.body.Date);
console.log("Converted Date ",DateStr);
const TransactionType = req.body.TransactionType;
const ActionDetails = {
ActionTakenByName: req.user.FirstName + ' ' + req.user.LastName,
Expand Down Expand Up @@ -112,7 +114,7 @@ module.exports.report = (req, res) => {
const aggr = [
{
$match: {
'TakenIn': {
'ActionDetails.ActionTakenOn': {
'$gte': new Date(req.body.StartDate),
'$lte': new Date(new Date(req.body.EndDate).setHours(23, 59, 59))
}
Expand Down Expand Up @@ -148,23 +150,62 @@ module.exports.report = (req, res) => {
$cond: [{ $eq: ['$WorkingHours', true] }, 1, 0]
}
},

}
}
]

const ShowLeaveagg = [
{
'$match': {
'Date.Month': req.body.Month,
'Date.Day': req.body.Day,
'Date.Year': req.body.Year
}
},
{
'$group': {
'_id': '$UserID',
'Details': {
'$push': '$$ROOT'
},

'TotalHolidays': {
'$sum': {
$cond: [{ $eq: ['$Title', "Holiday"] }, 1, 0]
$cond: [{ $eq: ['$TransactionType', "Holiday"] }, 1, 0]
}
},
'Leave': {
'$sum': {
$cond: [{ $eq: ['$Title', "Leave"] }, 1, 0]
'$cond': [
{
'$and': [
{
'$eq': [
'$TransactionType', 'Leave'
]
}, {
'$eq': [
'$Status', 'Approved'
]
}
]
}, 1, 0
]
}
},
},

}

}
]
]
if (req.body.userIds && req.body.userIds.length) {
aggr[0].$match['UserName'] = { $in: req.body.userIds }
}
attendance_repo.aggregate(aggr)
attendance_repo.aggregate(aggr);
attendance_repo.aggregate(ShowLeaveagg);
let attendance = [];
attendance.push(aggr.ShowLeaveagg)
.then(attendance => {
res.send({ Status: true, data: attendance })
})
Expand Down
98 changes: 98 additions & 0 deletions backend/controllers/email_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const MailSetupRepo = require("../repository/email_repo");

exports.CreateMailSetup = (req, res) => {
let ActionDetails = {
ActionTakenByName: req.user.FirstName + " " + req.user.LastName,
ActionTakenByID: req.user._id,
ActionTakenOn: new Date(),
ActionTakenByLoginID: req.user.LoginID,
Designation : req.user.Designation
};

let mailSetupObj ={
SenderName : req.body.senderName,
HOST : req.body.HOST,
CreationDetails: ActionDetails,
Email: req.body.USERID,
Password : req.body.Password
};
if(req.body.PORT){
mailSetupObj["PORT"] = req.body.PORT
}

console.log(JSON.stringify(mailSetupObj))
console.log(JSON.stringify(ActionDetails))

MailSetupRepo.create(mailSetupObj).then((success) =>{
const mailSetup = success
if(mailSetup.HOST == "Gmail"){
process.env.Email = mailSetup.UserID
process.env.Password = mailSetup.Password
process.env.Host = mailSetup.HOST
process.env.SenderName = mailSetup.SenderName
console.log("GMail " , mailSetup);
}else{
process.env.Email = mailSetup.UserID
process.env.Password = mailSetup.Password
process.env.Host = mailSetup.HOST
process.env.Port = mailSetup.PORT
process.env.SenderName = mailSetup.SenderName

}
res.status(200).json({status : true , data:success})
}).catch(err =>{
res.status(500).json({status : false,error :err})
})

};

exports.GetMailSetup = (req, res) => {
MailSetupRepo.find({}, true).then((success) =>{
res.status(200).json({status : true, data:success})
}).catch(err =>{
res.status(500).json({status : false,error :err})
})

};

exports.UpdateMailSetup = (req, res) => {
let query = {_id : req.body._id};
let update = {$set : {...req.body}};
update["$set"]["Email"] = req.body.USERID
update["$set"]["SenderName"] = req.body.senderName
// delete update["$set"]["Email"]
delete update["$set"]["_id"]
if(update["$set"]["HOST"] === "Gmail"){
update["$set"]['PORT'] = ""
}
else update["$set"]["PORT"] = req.body.PORT
console.log(update, "update<----")
console.log(query, "querye<----")
MailSetupRepo.updateOne(query, update).then((success) =>{
res.status(200).json({status : true , success})
}).catch(err =>{
console.log(err, "err")
res.status(500).json({status : false,error :err})
})
MailSetupRepo.find({}, true).then((success) =>{
const mailSetup = success
if(mailSetup.HOST == "Gmail"){
process.env.Email = mailSetup.UserID
process.env.Password = mailSetup.Password
process.env.Host = mailSetup.HOST
process.env.SenderName = mailSetup.SenderName
console.log("GMail " , mailSetup);
}else{
process.env.Email = mailSetup.UserID
process.env.Password = mailSetup.Password
process.env.Host = mailSetup.HOST
process.env.Port = mailSetup.PORT
process.env.SenderName = mailSetup.SenderName

}
console.log("Set environment and update successfully");
}).catch(err =>{
console.log("update but not set in environment " , err);
})

};
104 changes: 95 additions & 9 deletions backend/controllers/user_controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const user_repo = require('../repository/user_repo');
const uuid = require('uuid').v1;
const jwt = require("jsonwebtoken");
const emailer = require('../services/mailer');

module.exports.login = async (req, res) => {
try {
Expand All @@ -19,14 +20,14 @@ module.exports.login = async (req, res) => {
res.send({ status: false, message: 'User id or password does not match!' });
}
else if (req.body.IsWeb) {
const checkAdmin = user_repo.find({RightsTitle:{$in:["Admin"]}})
console.log(checkAdmin,"------")
if(!checkAdmin) {
const checkAdmin = user_repo.find({ RightsTitle: { $in: ["Admin"] } })
console.log(checkAdmin, "------")
if (!checkAdmin) {

res.send({ status: false, message: 'No rights to Access!' });
}
else {

const token = uuid();
const assignJwt = jwt.sign({ UID: token, expiresIn: "4h" }, process.env.JWT_SECRET);
user_repo.updateOne({ _id: user._id }, { $set: { Login_JWT_Token_ID: token } }).then(upd => {
Expand All @@ -35,10 +36,10 @@ module.exports.login = async (req, res) => {
let user_to_send = user.toObject();
res.send({ data: user_to_send, status: true, token: assignJwt, message: 'User Login Successfully!' });
}

}
else {

const token = uuid();
const assignJwt = jwt.sign({ UID: token, expiresIn: "4h" }, process.env.JWT_SECRET);
user_repo.updateOne({ _id: user._id }, { $set: { Login_JWT_Token_ID: token } }).then(upd => {
Expand Down Expand Up @@ -110,7 +111,7 @@ module.exports.editUser = async (req, res) => {
}

module.exports.ChangePassword = (req, res) => {
user_repo.find({ _id:req.body?._id }, true, true, {})
user_repo.find({ _id: req.body?._id }, true, true, {})
.then(user => {
if (!user) {
console.log("User not found!");
Expand Down Expand Up @@ -154,4 +155,89 @@ module.exports.ChangePassword = (req, res) => {
res.send(err);
});

}
}


module.exports.ForgotPassword = async (req, res) => {
try {
let emailID = req.body.resetEmail;
console.log("object", req.body)
let user = await user_repo.find({ Email: emailID }, true);
if (user) {
console.log(user, "------")
const token = uuid();
let EmailMessage =
"Dear &nbsp;<u>" +
user.FirstName +
" " +
user.LastName +
"</u><br> We are sending this email to your request for reset the password in Attendance App" +
"<br>" +
"Please find below the link to reset your password!" +
'<br><a href="';
console.log(EmailMessage, "sgshgs")
EmailMessage +=
process.env.NODE_ENV === 'production' ? req.protocol + '://' + req.hostname + '/auth/change-password?token=' + token :
req.protocol + '://localhost:3001' + '/auth/change-password?token=' + token +
'">' +
'Reset Password' +
"</a>"
console.log(EmailMessage, 'some info')
await user_repo.updateOne({ Email: emailID }, { $set: { Password_ResetToken: token, ForgotPasswordEmailSentTimeStamp: new Date() } })
let email_to_send_for_reset = {
To: emailID,
Subject: 'Reset Email',
message: EmailMessage

};
emailer.sendEmail(email_to_send_for_reset, emailID)
.then(success => {
console.log('Email Sent: ', success);
res.send({ status: true, message: 'Email has been sent' });
})
.catch(err => {
console.log('Error in Email: ', err);
res.send({ status: true, message: 'Email could not be sent!' });
});
}
} catch (e) {
res.send(e);
}
}



module.exports.ResetPassword = (req, res) => {
try {
console.log(req.body)
let token = req.body.token;
// let user = await user_repo.find({Password_ResetToken : token}, {$set: {Password_ResetToken: undefined,ForgotPasswordEmailSentTimeStamp:undefined}});
user_repo.find({ Password_ResetToken: token }, true, true, null, null)
.then(user => {
console.log("Inside User Found!", user);
if (!user) {
console.log("User not found!");
return res.send({
message: "Your Token is Expire or Not valid.",
status: false
});
} else {
user.Password = req.body.new_password
user.Password_ResetToken = undefined
user.ForgotPasswordEmailSentTimeStamp = undefined
user.save().then((success) => {
console.log('Password Changed Successfully!');

res.send({ status: true, message: 'Password changed!' })
}).catch(err => {
res.send(err)
})
}
})
}
catch (e) {
res.send(e);
}
}


3 changes: 2 additions & 1 deletion backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ app.get('/', function (req, res) {

// Change the 404 message modifing the middleware
app.use(function(req, res, next) {
res.status(404).send("Sorry, that route doesn't exist. Have a nice day :)");
console.log(path.join(__dirname, "build", "index.html"))
res.sendFile(path.join(__dirname, "build", "index.html"));
});

// start the server in the port 3000 !
Expand Down
24 changes: 24 additions & 0 deletions backend/models/email_schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ObjectId = Schema.ObjectId;



const ActionDetails = {
ActionTakenByName: { type: String },
ActionTakenByID: { type: Schema.ObjectId },
ActionTakenOn: { type: Date },
ActionTakenByLoginID: { type: String },
CardNumber: String
};

const MailSchema = new Schema({
SenderName: String,
HOST : String,
PORT : String,
CreationDetails: ActionDetails,
Email: String, //0 inactive 1 active,
Password : String,
})

module.exports = mongoose.model("MailSetup", MailSchema);
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"express": "^4.17.3",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.2.8",
"nodemailer": "^6.7.3",
"uuid": "^8.3.2"
}
}
Loading

0 comments on commit 5db5df4

Please sign in to comment.