├── .gitignore ├── config ├── database.js └── passport.js ├── server ├── routes │ ├── logoutRoute.js │ ├── homeRoute.js │ ├── billspaymentRoute.js │ ├── checkbalanceRoute.js │ ├── fundtransferRoute.js │ ├── indexRoute.js │ ├── transactionhistoryRoute.js │ ├── withdrawRoute.js │ ├── signupRoute.js │ └── depositRoute.js └── views │ ├── message.pug │ ├── index.pug │ ├── transactionhistory.pug │ ├── deposit.pug │ ├── withdraw.pug │ ├── fundtransfer.pug │ ├── checkbalance.pug │ ├── signup.pug │ ├── billspayment.pug │ ├── layout.pug │ └── home.pug ├── WalletSystemFeatures.txt ├── public ├── style.css ├── vue-config.js └── form-config.js ├── models ├── transactions.js └── accounts.js ├── README.md ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /config/database.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | database: "mongodb://localhost:27017/expresswallet", 3 | secret: "123456" 4 | }; 5 | -------------------------------------------------------------------------------- /server/routes/logoutRoute.js: -------------------------------------------------------------------------------- 1 | router.post("/logout", (req, res) => { 2 | req.logout(); 3 | req.flash("success", "You are now logged out."); 4 | res.redirect("/"); 5 | }); 6 | -------------------------------------------------------------------------------- /WalletSystemFeatures.txt: -------------------------------------------------------------------------------- 1 | Wallet System 2 | - Sign Up/ Log In 3 | - Fund Transfer 4 | - Check Balance 5 | - Deposit 6 | - Withdraw 7 | - Transaction History 8 | - Bills Payment 9 | - (Optional) Authentication and Bank Transactions -------------------------------------------------------------------------------- /public/style.css: -------------------------------------------------------------------------------- 1 | .alert-error { 2 | color: #a94442; 3 | background: #f2dede; 4 | border-color: #ebccd1; 5 | } 6 | 7 | .alert-success { 8 | color: #3c763d; 9 | background: #dff0d8; 10 | border-color: #d6e9c6; 11 | } 12 | -------------------------------------------------------------------------------- /server/routes/homeRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | 4 | router.get("/", (req, res) => { 5 | res.render("home.pug", { title: "Dashboard | Express Wallet" }); 6 | }); 7 | 8 | module.exports = router; 9 | -------------------------------------------------------------------------------- /server/views/message.pug: -------------------------------------------------------------------------------- 1 | .message 2 | each type in Object.keys(messages) 3 | each message in messages[type] 4 | div(class="alert alert-"+type) 5 | button.close(type="button" data-dismiss="alert") × 6 | p.text-center= message -------------------------------------------------------------------------------- /server/routes/billspaymentRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | 4 | router.get("/", (req, res) => { 5 | res.render("billspayment.pug", { title: "Bills Payment | Express Wallet" }); 6 | }); 7 | 8 | module.exports = router; 9 | -------------------------------------------------------------------------------- /server/routes/checkbalanceRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | 4 | router.get("/", (req, res) => { 5 | res.render("checkbalance.pug", { title: "Check Balance | Express Wallet" }); 6 | }); 7 | 8 | module.exports = router; 9 | -------------------------------------------------------------------------------- /server/routes/fundtransferRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | 4 | router.get("/", (req, res) => { 5 | res.render("fundtransfer.pug", { title: "Fund Transfer | Express Wallet" }); 6 | }); 7 | 8 | module.exports = router; 9 | -------------------------------------------------------------------------------- /public/vue-config.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | let vueConfig = new vueConfig({ 3 | el: "#vueRender", 4 | data: { 5 | firstname: null, 6 | lastname: null, 7 | email: null, 8 | password: null, 9 | con_password: null 10 | }, 11 | created: () => { 12 | var self = this; 13 | axios.get(""); 14 | }, 15 | methods: { 16 | signupHandler: () => { 17 | var self = this; 18 | var payload = {}; 19 | } 20 | } 21 | }); 22 | })(); 23 | -------------------------------------------------------------------------------- /models/transactions.js: -------------------------------------------------------------------------------- 1 | let mongoose = require("mongoose"); 2 | 3 | let transactionSchema = mongoose.Schema({ 4 | transaction_type: { 5 | type: String, 6 | required: true 7 | }, 8 | sender: { 9 | type: String, 10 | required: true 11 | }, 12 | recepient: { 13 | type: String, 14 | required: true 15 | }, 16 | amount: { 17 | type: Number, 18 | required: true 19 | }, 20 | timestamp: { 21 | type: Date, 22 | default: Date.now 23 | } 24 | }); 25 | 26 | let transactions = (module.exports = mongoose.model( 27 | "transactions", 28 | transactionSchema 29 | )); 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Wallet System 2 | A simple wallet system using Express.JS with Passport.JS integration. 3 | 4 | ## Built With 5 | Mongo, Express, Node.JS, JavaScript 6 | 7 | ## Getting Ready 8 | Clone the repo and follow the instructions. You can view each step by running these commands from the terminal. 9 | 1. Open your MongoDB. 10 | 2. Back to your repository folder, 11 | ``` 12 | npm install 13 | ``` 14 | 3. To run the app, 15 | ``` 16 | npm run start 17 | ``` 18 | ## Features 19 | - Sign Up/ Log In 20 | - Fund Transfer 21 | - Check Balance 22 | - Deposit 23 | - Withdraw 24 | - Transaction History 25 | - Bills Payment 26 | -------------------------------------------------------------------------------- /models/accounts.js: -------------------------------------------------------------------------------- 1 | let mongoose = require("mongoose"); 2 | 3 | let accountsSchema = mongoose.Schema({ 4 | email: { 5 | type: String, 6 | required: true 7 | }, 8 | password: { 9 | type: String, 10 | required: true 11 | }, 12 | firstname: { 13 | type: String, 14 | required: true 15 | }, 16 | lastname: { 17 | type: String, 18 | required: true 19 | }, 20 | timestamp: { 21 | type: Date, 22 | default: Date.now 23 | }, 24 | balance: { 25 | type: Number, 26 | required: true 27 | } 28 | }); 29 | 30 | let accounts = (module.exports = mongoose.model("accounts", accountsSchema)); 31 | -------------------------------------------------------------------------------- /public/form-config.js: -------------------------------------------------------------------------------- 1 | // function checkPassword() { 2 | // let pass = document.getElementById("password").value; 3 | // let conPass = document.getElementById("conPassword").value; 4 | // let displayErr = document.getElementById("displayErr"); 5 | // let formSubmit = document.getElementById("formSubmit"); 6 | // if (pass === conPass) { 7 | // formSubmit.removeClass("disabled"); 8 | // displayErr.style.display = "none"; 9 | // } else { 10 | // displayErr.style.display = "block"; 11 | // formSubmit.addClass("disabled"); 12 | // } 13 | // } 14 | history.pushState(null, null, location.href); 15 | window.onpopstate = function() { 16 | history.go(1); 17 | }; 18 | -------------------------------------------------------------------------------- /server/routes/indexRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const mongoose = require("mongoose"); 3 | const passport = require("passport"); 4 | const crypt = require("bcryptjs"); 5 | const router = express.Router(); 6 | 7 | router.get("/", (req, res) => { 8 | res.render("index.pug", { title: "Log In | Express Wallet" }); 9 | }); 10 | 11 | router.post("/login", (req, res, next) => { 12 | passport.authenticate("local", { 13 | successRedirect: "/home", 14 | failureRedirect: "/", 15 | failureFlash: true 16 | })(req, res, next); 17 | }); 18 | 19 | router.get("/logout", (req, res) => { 20 | req.logout(); 21 | req.flash("success", "You are now logged out."); 22 | res.redirect("/"); 23 | }); 24 | 25 | module.exports = router; 26 | -------------------------------------------------------------------------------- /server/views/index.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | .container 5 | .row 6 | .col-lg-4 7 | .col-lg-4 8 | h2.text-center.mt-3 Log In 9 | != messages('message', locals) 10 | form(action="/login", method="post") 11 | .form-group 12 | label(for="") E-mail: 13 | input.form-control(type="email", name="email" required) 14 | .form-group 15 | label(for="") Password: 16 | input.form-control(type="password", name="password" required) 17 | .form-group 18 | button.btn.btn-block.btn-success(type="submit") Log In 19 | a.btn.btn-block.btn-primary(href="/signup") Sign Up 20 | .col-lg-4 21 | -------------------------------------------------------------------------------- /server/views/transactionhistory.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | .container 5 | h2.mt-3.mb-3 Transaction History 6 | h5.text-right My Wallet: 7 | strong P#{user.balance} 8 | hr 9 | table.table.table-hover 10 | thead 11 | tr 12 | th Date and Time 13 | th Transaction ID 14 | th Transaction Type 15 | th Recepient 16 | th Amount Paid 17 | tbody 18 | each transaction in transactions 19 | if transaction.sender == user.id 20 | tr 21 | td #{transaction.timestamp} 22 | td #{transaction.id} 23 | td #{transaction.transaction_type} 24 | td #{transaction.recepient} 25 | td #{transaction.amount} 26 | -------------------------------------------------------------------------------- /server/views/deposit.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | .container 5 | h2.mt-3.mb-3 Deposit 6 | h5.text-right My Wallet: 7 | strong P#{user.balance} 8 | hr 9 | .row.mt-6 10 | .col-lg-3 11 | .col-lg-6 12 | != messages('message', locals) 13 | form(action="/deposit/add/"+user.id, method="post") 14 | .form-group 15 | label(for="") Amount to Deposit: 16 | input.form-control(type="number", name="amount" min="" max="" required) 17 | .form-group 18 | label(for="") Enter Your Password to Confirm: 19 | input.form-control(type="password", name="password" required) 20 | .form-group 21 | button.btn.btn-success.mr-2(type="submit") Confirm 22 | .col-lg-3 23 | -------------------------------------------------------------------------------- /server/views/withdraw.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | .container 5 | h2.mt-3.mb-3 Withdraw 6 | h5.text-right My Wallet: 7 | strong P#{user.balance} 8 | hr 9 | .row.mt-6 10 | .col-lg-3 11 | .col-lg-6 12 | != messages('message', locals) 13 | form(action="/withdraw/add/"+user.id, method="post") 14 | .form-group 15 | label(for="") Amount to Withdraw: 16 | input.form-control(type="number", name="amount" min="" max="" required) 17 | .form-group 18 | label(for="") Enter Your Password to Confirm: 19 | input.form-control(type="password", name="password" required) 20 | .form-group 21 | button.btn.btn-success.mr-2(type="submit") Confirm 22 | .col-lg-3 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "walletsystem", 3 | "version": "1.0.0", 4 | "description": "This is a simple wallet system using Express.JS with Passport.JS integration", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "nodemon index.js" 9 | }, 10 | "author": "Lhester Monroyo", 11 | "license": "ISC", 12 | "dependencies": { 13 | "axios": "^0.18.0", 14 | "bcryptjs": "^2.4.3", 15 | "body-parser": "^1.18.3", 16 | "connect-flash": "^0.1.1", 17 | "cookie-parser": "^1.4.3", 18 | "express": "^4.16.4", 19 | "express-messages": "^1.0.1", 20 | "express-session": "^1.15.6", 21 | "express-validator": "^5.3.0", 22 | "moment": "^2.22.2", 23 | "mongoose": "^5.3.6", 24 | "passport": "^0.4.0", 25 | "passport-local": "^1.0.0", 26 | "pug": "^2.0.3", 27 | "simple-json-store": "0.0.1" 28 | }, 29 | "devDependencies": { 30 | "nodemon": "^1.18.5" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /server/views/fundtransfer.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | .container 5 | h2.mt-3.mb-3 Fund Transfer 6 | h5.text-right My Wallet: 7 | strong P#{user.balance} 8 | hr 9 | .row.mt-6 10 | .col-lg-3 11 | .col-lg-6 12 | form(action="/", method="post") 13 | .form-group 14 | label(for="") Send Money To: 15 | input.form-control(type="email", name="email" placeholder="Enter recepient's e-mail" required) 16 | .form-group 17 | label(for="") Amount: 18 | input.form-control(type="number", name="amount" min="" max="" required) 19 | .form-group 20 | label(for="") Remarks: 21 | textarea.form-control(rows="5", name="email" required) 22 | .form-group 23 | label(for="") Enter Your Password to Confirm: 24 | input.form-control(type="password", name="password" required) 25 | .form-group 26 | button.btn.btn-success.mr-2(type="submit") Confirm 27 | .col-lg-3 28 | 29 | -------------------------------------------------------------------------------- /server/routes/transactionhistoryRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const moment = require("moment"); 3 | const Accounts = require("../../models/accounts"); 4 | const Transactions = require("../../models/transactions"); 5 | const router = express.Router(); 6 | 7 | router.get("/", (req, res) => { 8 | Accounts.find({}, (err, accounts) => { 9 | if (err) { 10 | console.log(err); 11 | } else { 12 | Transactions.find({}, (err, transactions) => { 13 | if (err) { 14 | console.log(err); 15 | } else { 16 | transactions = transactions.map(transaction => { 17 | return { 18 | ...transaction, 19 | timestamp: moment(transaction.timestamp).format("dd/mm/yyyy") 20 | }; 21 | }); 22 | console.log("modified trans:", transactions); 23 | res.render("transactionhistory.pug", { 24 | title: "Transaction History | Express Wallet", 25 | accounts, 26 | transactions 27 | }); 28 | } 29 | }); 30 | } 31 | }); 32 | }); 33 | 34 | module.exports = router; 35 | -------------------------------------------------------------------------------- /server/views/checkbalance.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | .container 5 | h2.mt-3.mb-3 Check Balance 6 | h5.text-right My Wallet: 7 | strong P#{user.balance} 8 | hr 9 | ul.list-group 10 | li.list-group-item.d-flex.justify-content-between.align-items-center 11 | | Current Wallet Balance 12 | span.badge.badge-primary.badge-pill P50000 13 | li.list-group-item.d-flex.justify-content-between.align-items-center 14 | | Recent Amount Paid 15 | span.badge.badge-primary.badge-pill P40000 16 | li.list-group-item.d-flex.justify-content-between.align-items-center 17 | | Recent Recepient 18 | span.badge.badge-primary.badge-pill Express Wallet 19 | li.list-group-item.d-flex.justify-content-between.align-items-center 20 | | Recent Transaction Type 21 | span.badge.badge-primary.badge-pill Deposit 22 | li.list-group-item.d-flex.justify-content-between.align-items-center 23 | | Transaction ID 24 | span.badge.badge-primary.badge-pill 01-2018-003 25 | li.list-group-item.d-flex.justify-content-between.align-items-center 26 | | Date and Time 27 | span.badge.badge-primary.badge-pill November 20, 2018 - 9:30am -------------------------------------------------------------------------------- /server/views/signup.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | .container 5 | .row 6 | .col-lg-4 7 | .col-lg-4 8 | h2.text-center.mt-3 Create Your Own Wallet 9 | != messages('message', locals) 10 | form(action="signup/add", method="post") 11 | //- each account in accounts 12 | //- p= account.email 13 | .form-group 14 | label(for="") Firstname: 15 | input.form-control(type="text", name="firstname" required) 16 | .form-group 17 | label(for="") Lastname: 18 | input.form-control(type="text", name="lastname" required) 19 | .form-group 20 | label(for="") E-mail: 21 | input.form-control(type="email", name="email" required) 22 | .form-group 23 | label(for="") Password: 24 | input.form-control(type="password", name="password" required) 25 | .form-group 26 | label(for="") Confirm Password: 27 | input.form-control(type="password", name="con_password" required) 28 | span#displayErr(style="display: none;") Passwords not identical. 29 | .form-group 30 | button.btn.btn-block.btn-success(type="submit") Sign Up 31 | a.btn.btn-block.btn-primary(href="/") Log In 32 | 33 | .col-lg-4 -------------------------------------------------------------------------------- /server/views/billspayment.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | .container 5 | h2.mt-3.mb-3 Bills Payment 6 | h5.text-right My Wallet: 7 | strong P#{user.balance} 8 | hr 9 | .row.mt-6 10 | .col-lg-3 11 | .col-lg-6 12 | form(action="/billpayment-process", method="post") 13 | .form-group 14 | label(for="") Pay This Biller: 15 | select.form-control(name="biller") 16 | option(value='Electricity') Electricity 17 | option(value='Water') Water 18 | option(value='Internet Provider') Internet Provider 19 | option(value='School Tuition') School Tuition 20 | option(value='Credit Payment') Credit Payment 21 | option(selected='selected') Select 22 | .form-group 23 | label(for="") Amount to Pay: 24 | input.form-control(type="number", name="amount" min="" max="" required) 25 | .form-group 26 | label(for="") Remarks: 27 | textarea.form-control(rows="5", name="remarks" required) 28 | .form-group 29 | label(for="") Enter Your Password to Confirm: 30 | input.form-control(type="password", name="password" required) 31 | .form-group 32 | button.btn.btn-success.mr-2(type="submit") Confirm 33 | .col-lg-3 34 | -------------------------------------------------------------------------------- /config/passport.js: -------------------------------------------------------------------------------- 1 | const LocalStrategy = require("passport-local").Strategy; 2 | const crypt = require("bcryptjs"); 3 | const Accounts = require("../models/accounts"); 4 | const config = require("../config/database"); 5 | 6 | module.exports = passport => { 7 | passport.use( 8 | new LocalStrategy( 9 | { usernameField: "email", passwordField: "password" }, 10 | (username, password, done) => { 11 | let query = { 12 | email: username 13 | }; 14 | Accounts.findOne(query, (err, account) => { 15 | if (err) { 16 | console.log(err); 17 | } 18 | 19 | if (!account) { 20 | return done(null, false, { 21 | message: "E-mail not registered. Please sign up first." 22 | }); 23 | } 24 | crypt.compare(password, account.password, (err, match) => { 25 | if (err) { 26 | console.log(err); 27 | } 28 | 29 | if (match) { 30 | return done(null, account); 31 | } else { 32 | return done(null, false, { 33 | message: "Password incorrect. Please try again." 34 | }); 35 | } 36 | }); 37 | }); 38 | } 39 | ) 40 | ); 41 | 42 | passport.serializeUser(function(user, done) { 43 | done(null, user.id); 44 | }); 45 | 46 | passport.deserializeUser(function(id, done) { 47 | Accounts.findById(id, function(err, user) { 48 | done(err, user); 49 | }); 50 | }); 51 | }; 52 | -------------------------------------------------------------------------------- /server/views/layout.pug: -------------------------------------------------------------------------------- 1 | 2 | html(lang="en") 3 | head 4 | meta(charset="UTF-8") 5 | meta(name="viewport", content="width=device-width, initial-scale=1.0") 6 | meta(http-equiv="X-UA-Compatible", content="ie=edge") 7 | title= title 8 | 9 | link(rel="stylesheet", href="https://bootswatch.com/4/united/bootstrap.min.css") 10 | link(rel="stylesheet", href="https://use.fontawesome.com/releases/v5.3.1/css/all.css") 11 | link(rel="stylesheet", href="style.css") 12 | body 13 | if user 14 | nav.navbar.navbar-expand-lg.navbar-dark.bg-primary 15 | .container 16 | a.navbar-brand(href='#') 17 | i.fas.fa-wallet.fa-fw 18 | | Express Wallet 19 | button.navbar-toggler(type='button' data-toggle='collapse' data-target='#navbarColor01' aria-controls='navbarColor01' aria-expanded='false' aria-label='Toggle navigation') 20 | span.navbar-toggler-icon 21 | #navbarColor01.collapse.navbar-collapse 22 | ul.navbar-nav.mr-auto.mt-2.mt-lg-0 23 | ul.navbar-nav 24 | li.nav-item.active 25 | a.nav-link(href='/home') 26 | | Home 27 | li.nav-item 28 | a.nav-link(href='/profile') Hello, #{user.firstname} #{user.lastname} 29 | li.nav-item 30 | a.nav-link(href='/logout') Log Out 31 | else 32 | p.lead.text-center 33 | i.fas.fa-wallet.fa-fw.mt-5 34 | | Express Wallet 35 | block content 36 | .footer.mt-5.mb-5 37 | .p.text-center © Express Wallet 2018. All Rights Reserved. 38 | script(src="https://bootswatch.com/_vendor/jquery/dist/jquery.min.js") 39 | script(src="https://bootswatch.com/_vendor/bootstrap/dist/js/bootstrap.min.js") 40 | script(src="https://bootswatch.com/_assets/js/custom.js") 41 | script(src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js") 42 | script(src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js") 43 | //- script(src="vue-config.js") -------------------------------------------------------------------------------- /server/routes/withdrawRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | const Accounts = require("../../models/accounts"); 4 | const Transactions = require("../../models/transactions"); 5 | const config = require("../../config/database"); 6 | const crypt = require("bcryptjs"); 7 | 8 | router.get("/", (req, res) => { 9 | res.render("withdraw.pug", { title: "Withdraw | Express Wallet" }); 10 | }); 11 | 12 | router.post("/add/:id", (req, res) => { 13 | Accounts.findById({ _id: req.params.id }, (err, account) => { 14 | if (err) { 15 | console.log(err); 16 | } 17 | 18 | console.log(account.email); 19 | 20 | crypt.compare(req.body.password, account.password, (err, match) => { 21 | if (err) { 22 | console.log(err); 23 | } 24 | 25 | if (match) { 26 | let query = { _id: req.params.id }; 27 | Accounts.findByIdAndUpdate( 28 | query, 29 | { balance: parseInt(account.balance) - parseInt(req.body.amount) }, 30 | err => { 31 | if (err) { 32 | console.log(err); 33 | } 34 | console.log("Withdraw successful!"); 35 | } 36 | ); 37 | 38 | let transaction = new Transactions({ 39 | transaction_type: "Withdraw", 40 | sender: req.params.id, 41 | recepient: req.params.id, 42 | amount: req.body.amount 43 | }); 44 | transaction.save(err => { 45 | if (err) { 46 | console.log(err); 47 | } 48 | console.log("Transaction saved!"); 49 | }); 50 | 51 | req.flash( 52 | "success", 53 | `Withdraw successful! You have withdrawed P${ 54 | req.body.amount 55 | } in your account.` 56 | ); 57 | res.redirect("/withdraw"); 58 | } else { 59 | req.flash( 60 | "danger", 61 | "Password entered was incorrect. Please try again." 62 | ); 63 | res.redirect("/withdraw"); 64 | } 65 | }); 66 | }); 67 | }); 68 | 69 | module.exports = router; 70 | -------------------------------------------------------------------------------- /server/routes/signupRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const mongoose = require("mongoose"); 3 | const crypt = require("bcryptjs"); 4 | const router = express.Router(); 5 | 6 | router.get("/", (req, res) => { 7 | Accounts.find({}, (err, accounts) => { 8 | if (err) { 9 | console.log(err); 10 | } else { 11 | res.render("signup.pug", { 12 | title: "Sign Up | Express Wallet", 13 | accounts: accounts 14 | }); 15 | } 16 | }); 17 | }); 18 | 19 | let Accounts = require("../../models/accounts"); 20 | router.post("/add", (req, res) => { 21 | if (req.body.password === req.body.con_password) { 22 | Accounts.count({ email: req.body.email }, (err, cnt) => { 23 | if (err) { 24 | console.log(err); 25 | } else { 26 | if (cnt == 0) { 27 | let account = new Accounts({ 28 | firstname: req.body.firstname, 29 | lastname: req.body.lastname, 30 | email: req.body.email, 31 | password: req.body.password, 32 | balance: parseFloat(0).toFixed(2) 33 | }); 34 | 35 | crypt.genSalt(10, (err, salt) => { 36 | crypt.hash(account.password, salt, (err, hash) => { 37 | if (err) { 38 | console.log(err); 39 | } 40 | 41 | account.password = hash; 42 | account.save(err => { 43 | if (err) { 44 | console.log(err); 45 | } else { 46 | req.flash( 47 | "success", 48 | "You have created your Express Wallet account!" 49 | ); 50 | res.redirect("/signup"); 51 | } 52 | }); 53 | }); 54 | }); 55 | } else { 56 | req.flash("danger", "E-mail already existed. Please try again."); 57 | res.redirect("/signup"); 58 | } 59 | } 60 | }); 61 | } else { 62 | req.flash("danger", "Passwords not identical. Please try again."); 63 | res.redirect("/signup"); 64 | } 65 | }); 66 | 67 | module.exports = router; 68 | -------------------------------------------------------------------------------- /server/routes/depositRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | const Accounts = require("../../models/accounts"); 4 | const Transactions = require("../../models/transactions"); 5 | const config = require("../../config/database"); 6 | const crypt = require("bcryptjs"); 7 | 8 | router.get("/", (req, res) => { 9 | res.render("deposit.pug", { title: "Deposit | Express Wallet" }); 10 | }); 11 | 12 | router.post("/add/:id", (req, res) => { 13 | Accounts.findById({ _id: req.params.id }, (err, account) => { 14 | if (err) { 15 | console.log(err); 16 | } 17 | 18 | console.log(account.email); 19 | 20 | crypt.compare(req.body.password, account.password, (err, match) => { 21 | if (err) { 22 | console.log(err); 23 | } 24 | 25 | if (match) { 26 | let query = { _id: req.params.id }; 27 | Accounts.findByIdAndUpdate( 28 | query, 29 | { 30 | balance: parseFloat(req.body.amount) + parseFloat(account.balance) 31 | }, 32 | err => { 33 | if (err) { 34 | console.log(err); 35 | } 36 | console.log("Deposit successful!"); 37 | } 38 | ); 39 | 40 | let transaction = new Transactions({ 41 | transaction_type: "Deposit", 42 | sender: req.params.id, 43 | recepient: req.params.id, 44 | amount: req.body.amount 45 | }); 46 | transaction.save(err => { 47 | if (err) { 48 | console.log(err); 49 | } 50 | console.log("Transaction saved!"); 51 | }); 52 | 53 | req.flash( 54 | "success", 55 | `Deposit successful! You have P${parseInt(req.body.amount) + 56 | parseInt(account.balance)} in your account.` 57 | ); 58 | res.redirect("/deposit"); 59 | } else { 60 | req.flash( 61 | "danger", 62 | "Password entered was incorrect. Please try again." 63 | ); 64 | res.redirect("/deposit"); 65 | } 66 | }); 67 | }); 68 | }); 69 | 70 | module.exports = router; 71 | -------------------------------------------------------------------------------- /server/views/home.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | .container 5 | h2.mt-3.mb-3 Dashboard 6 | h5.text-right My Wallet: 7 | strong P#{user.balance} 8 | hr 9 | != messages('message', locals) 10 | .row.mt-3 11 | .col-lg-4.col-sm-4 12 | .card.text-white.bg-primary.mb-3(style='max-width: 20rem;') 13 | .card-body 14 | h4.card-title Fund Transfer 15 | p.card-text Lorem, ipsum dolor sit amet consectetur adipisicing elit. 16 | a.btn.btn-primary.btn-block.border-light(href="/fundtransfer") Go to Fund Transfer 17 | .col-lg-4.col-sm-4 18 | .card.text-white.bg-success.mb-3(style='max-width: 20rem;') 19 | .card-body 20 | h4.card-title Check Balance 21 | p.card-text Lorem, ipsum dolor sit amet consectetur adipisicing elit. 22 | a.btn.btn-success.btn-block.border-light(href="/checkbalance") Go to Check Balance 23 | .col-lg-4.col-sm-4 24 | .card.text-white.bg-warning.mb-3(style='max-width: 20rem;') 25 | .card-body 26 | h4.card-title Deposit 27 | p.card-text Lorem, ipsum dolor sit amet consectetur adipisicing elit. 28 | a.btn.btn-warning.btn-block.border-light(href="/deposit") Go to Deposit 29 | .col-lg-4.col-sm-4 30 | .card.text-white.bg-info.mb-3(style='max-width: 20rem;') 31 | .card-body 32 | h4.card-title Withdraw 33 | p.card-text Lorem, ipsum dolor sit amet consectetur adipisicing elit. 34 | a.btn.btn-info.btn-block.border-light(href="/withdraw") Go to Withdraw 35 | .col-lg-4.col-sm-4 36 | .card.text-white.bg-danger.mb-3(style='max-width: 20rem;') 37 | .card-body 38 | h4.card-title Bills Payment 39 | p.card-text Lorem, ipsum dolor sit amet consectetur adipisicing elit. 40 | a.btn.btn-danger.btn-block.border-light(href="/billspayment") Go to Bills Payment 41 | .col-lg-4.col-sm-4 42 | .card.text-white.bg-dark.mb-3(style='max-width: 20rem;') 43 | .card-body 44 | h4.card-title Transaction History 45 | p.card-text Lorem, ipsum dolor sit amet consectetur adipisicing elit. 46 | a.btn.btn-dark.btn-block.border-light(href="/transactionhistory/") Go to Transaction History 47 | script(src="form-config.js") 48 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const path = require("path"); 3 | const bodyParser = require("body-parser"); 4 | const mongoose = require("mongoose"); 5 | const session = require("express-session"); 6 | const flash = require("connect-flash"); 7 | const passport = require("passport"); 8 | const expressValidator = require("express-validator"); 9 | 10 | const indexRoute = require("./server/routes/indexRoute"); 11 | const signupRoute = require("./server/routes/signupRoute"); 12 | const homeRoute = require("./server/routes/homeRoute"); 13 | const fundtransferRoute = require("./server/routes/fundtransferRoute"); 14 | const checkbalanceRoute = require("./server/routes/checkbalanceRoute"); 15 | const depositRoute = require("./server/routes/depositRoute"); 16 | const withdrawRoute = require("./server/routes/withdrawRoute"); 17 | const billspaymentRoute = require("./server/routes/billspaymentRoute"); 18 | const transactionhistoryRoute = require("./server/routes/transactionhistoryRoute"); 19 | 20 | const config = require("./config/database"); 21 | const app = express(); 22 | const port = 3000; 23 | require("./config/passport")(passport); 24 | 25 | mongoose.connect( 26 | config.database, 27 | { useNewUrlParser: true } 28 | ); 29 | let db = mongoose.connection; 30 | 31 | db.once("open", () => { 32 | console.log("Connected to MongoDB"); 33 | }); 34 | 35 | db.on("error", err => { 36 | console.log(err); 37 | }); 38 | 39 | app.use(require("connect-flash")()); 40 | app.use( 41 | session({ 42 | secret: "keyboard cat", 43 | resave: true, 44 | saveUninitialized: true 45 | }) 46 | ); 47 | app.use((req, res, next) => { 48 | res.locals.messages = require("express-messages")(req, res); 49 | next(); 50 | }); 51 | app.use( 52 | expressValidator({ 53 | errorFormatter: (param, msg, value) => { 54 | var namespace = param.split("."), 55 | root = namespace.shift(), 56 | formParam = root; 57 | 58 | while (namespace.length) { 59 | formParam += "[" + namespace.shift() + "]"; 60 | } 61 | return { 62 | param: formParam, 63 | msg: msg, 64 | value: value 65 | }; 66 | } 67 | }) 68 | ); 69 | app.use(passport.initialize()); 70 | app.use(passport.session()); 71 | 72 | app.get("*", (req, res, next) => { 73 | res.locals.user = req.user || null; 74 | next(); 75 | }); 76 | 77 | app.use(bodyParser.json()); 78 | app.use(bodyParser.urlencoded({ extended: false })); 79 | app.use(express.static("public")); 80 | app.set("views", path.join(__dirname, "server/views")); 81 | app.set("view engine", "pug"); 82 | 83 | app 84 | .use("/", indexRoute) 85 | .use("/signup", signupRoute) 86 | .use("/home", homeRoute) 87 | .use("/fundtransfer", fundtransferRoute) 88 | .use("/checkbalance", checkbalanceRoute) 89 | .use("/deposit", depositRoute) 90 | .use("/withdraw", withdrawRoute) 91 | .use("/billspayment", billspaymentRoute) 92 | .use("/transactionhistory", transactionhistoryRoute); 93 | 94 | app.listen(port, err => { 95 | if (err) { 96 | return console.error(err); 97 | } 98 | console.log(`Listening to port: ${port}`); 99 | }); 100 | --------------------------------------------------------------------------------