Skip to content
Permalink
Browse files
Nurlan Guliyev Mortgage Application
  • Loading branch information
guliyevn committed Dec 10, 2021
0 parents commit 4ee6382ed1eb07bb60638a8a855d5dd83e0327d0
Show file tree
Hide file tree
Showing 34 changed files with 1,646 additions and 0 deletions.
7 .codio
@@ -0,0 +1,7 @@

{
"preview": {
"Live Website": "https://{{domain8080}}/{{index}}",
"Heroku Local": "https://{{domain5000}}/{{index}}"
}
}
@@ -0,0 +1,4 @@

# You Need to Add Your Hooks

They need to be in this directory.
@@ -0,0 +1 @@
web: deno run --allow-all --unstable index.js --port=${PORT}
@@ -0,0 +1,40 @@

# Getting Started

This template is designed to be installed inside a Codio box. To to this, open the terminal and run the following command:

```
$ curl -sL https://bit.ly/3yKYBTg | bash
```

This will configure the box ready for you to start development.

> The process can take up to 15 min. Make sure you don't close the browser tab _or let your computer go into sleep mode_.
To run the server:

```shell
$ deno run --allow-all --unstable index.js
```

The website database has been added with a root password of `p455w0rd` and a single **accounts** table which is pre-configured with a single account:

username: `doej`

password: `p455w0rd`

There is a secure page called **Foo Bar** which can be accessed at the `/foo` route. You will need to delete this and replace with your own secure content.

# Support Videos

https://youtu.be/X38dYaNH-HA

https://youtu.be/gdvKwBpNU7A

## Pushing to GitHub

If you can't push to the University GitHub server (you are not prompted for the username/password and the connection times out) please run the following command which will print the Codio box external IP address and send this to your module leader.

```
$ dig +short myip.opendns.com @resolver1.opendns.com
```
@@ -0,0 +1,96 @@
{
"lint": {
"files": {
"exclude": ["tmp/", "stats.js", "spa/"]
},
"rules": {
"tags": ["recommended"],
"include": [
"ban-untagged-todo",
"camelcase",
"constructor-super",
"default-param-last",
"eqeqeq",
"for-direction",
"getter-return",
"no-array-constructor",
"no-async-promise-executor",
"no-await-in-loop",
"no-class-assign",
"no-compare-neg-zero",
"no-cond-assign",
"no-const-assign",
"no-constant-condition",
"no-control-regex",
"no-delete-var",
"no-deprecated-deno-api",
"no-dupe-args",
"no-dupe-class-members",
"no-dupe-else-if",
"no-dupe-keys",
"no-duplicate-case",
"no-empty",
"no-empty-character-class",
"no-empty-enum",
"no-empty-interface",
"no-empty-pattern",
"no-eval",
"no-ex-assign",
"no-explicit-any",
"no-extra-boolean-cast",
"no-extra-non-null-assertion",
"no-extra-semi",
"no-fallthrough",
"no-func-assign",
"no-global-assign",
"no-import-assign",
"no-inferrable-types",
"no-inner-declarations",
"no-invalid-regexp",
"no-invalid-triple-slash-reference",
"no-irregular-whitespace",
"no-misused-new",
"no-namespace",
"no-new-symbol",
"no-obj-calls",
"no-octal",
"no-prototype-builtins",
"no-redeclare",
"no-regex-spaces",
"no-self-assign",
"no-setter-return",
"no-shadow-restricted-names",
"no-this-alias",
"no-this-before-super",
"no-undef",
"no-unreachable",
"no-unsafe-finally",
"no-unsafe-negation",
"no-unused-labels",
"no-unused-vars",
"no-var",
"no-window-prefix",
"no-with",
"prefer-as-const",
"prefer-ascii",
"prefer-const",
"prefer-namespace-keyword",
"require-await",
"require-yield",
"use-isnan"
]
}
},
"fmt": {
"files": {
"exclude": ["tmp/", "stats.js"]
},
"options": {
"useTabs": true,
"lineWidth": 80,
"indentWidth": 2,
"singleQuote": true,
"proseWrap": "preserve"
}
}
}
@@ -0,0 +1,58 @@

/* index.js */

import { Application } from 'https://deno.land/x/oak@v6.5.1/mod.ts'
import { Handlebars } from 'https://deno.land/x/handlebars/mod.ts'
import { parse } from 'https://deno.land/std/flags/mod.ts'

import router from './routes.js'

const defaultPort = 8080
const { args } = Deno
const argPort = parse(args).port
const port = argPort ? Number(argPort) : defaultPort

const app = new Application()
const handle = new Handlebars({ defaultLayout: '' })

// error handler
app.use(async (context, next) => {
try {
console.log(context.request.url.href)
console.log(`authorised cookie: ${context.cookies.get('authorised')}`)
await next()
} catch (err) {
console.log(err)
}
})

app.use(router.routes())
app.use(router.allowedMethods())

// static content
app.use(async (context, next) => {
const root = `${Deno.cwd()}/public`
try {
await context.send({ root })
} catch {
next()
}
})

// page not found
app.use( async context => {
try {
console.log('404 PAGE NOT FOUND')
const body = await handle.renderView('404')
context.response.body = body
// context.response.body = '404 PAGE NOT FOUND'
} catch(err) {
console.error(err)
}
})

app.addEventListener('listen', ({ port }) => {
console.log(`listening on port: ${port}`)
})

await app.listen({ port })
@@ -0,0 +1,29 @@

/* accounts.js */

import { compare, genSalt, hash } from 'https://deno.land/x/bcrypt@v0.2.4/mod.ts'

import { db } from './db.js'

const saltRounds = 10
const salt = await genSalt(saltRounds)

export async function login(data) {
console.log(data)
let sql = `SELECT count(id) AS count FROM accounts WHERE user="${data.username}";`
let records = await db.query(sql)
if(!records[0].count) throw new Error(`username "${data.username}" not found`)
sql = `SELECT pass FROM accounts WHERE user = "${data.username}";`
records = await db.query(sql)
const valid = await compare(data.password, records[0].pass)
if(valid === false) throw new Error(`invalid password for account "${data.username}"`)
return data.username
}

export async function register(data) {
const password = await hash(data.password, salt)
const sql = `INSERT INTO accounts(user, pass) VALUES("${data.username}", "${password}")`
console.log(sql)
await db.query(sql)
return true
}
@@ -0,0 +1,52 @@

/* calculator.js */

import { db } from './db.js'

export async function getMortgageOptions(data) {

let sql = `SELECT * FROM mortgageOptions where addedBy = "${data}";`
let records = await db.query(sql)

return records;
}
export async function getFinancialData(data) {

let sql = `SELECT * FROM FinancialData where user = "${data}";`
let records = await db.query(sql)

return records;
}

export async function saveOptions(data) {


const sql = `INSERT INTO mortgageOptions(totalAmount, amounttoDeposit, Years ,
totalAmountwithIntrestRate,monthlyMortgage , addedBy )
VALUES(${data.planamount * 1}, ${data.plandeposit * 1}, ${ data.years * 1 } , ${data.totalAmount * 1}, ${data.monthlyAmount * 1}, "${data.addedBy}" )`
console.log(sql)
await db.query(sql)
return true
}

export async function deleteOption(data) {


const sql = `DELETE FROM mortgageOptions WHERE id = ${+data.optionId};`
console.log(sql)
await db.query(sql)
return true
}

export async function addFinancialData(data) {

// const sql = `UPDATE mortgageOptions SET monthlyWage = ${+data.Monthlywage} , monthlyOutgoing = ${+data.montlyOutgoings} , monthlyRent = ${+data.monthlyRent} WHERE addedBy = "${data.authorised}";`
// await db.query(sql)

const sql2 = `INSERT INTO FinancialData(user, monthlyWage, monthlyOutgoing , monthlyRent,wageLeft , amountToDeposit, amounttoBorrow )
VALUES("${data.authorised}", ${data.Monthlywage}, ${ data.montlyOutgoings } , ${data.monthlyRent},
${(data.Monthlywage - data.montlyOutgoings) - data.monthlyRent }, ${data.monthlyAmount} , ${data.totalAmount} )`;
console.log(sql2)
await db.query(sql2)
return true
}
@@ -0,0 +1,29 @@

/* db.js */

import { Client } from 'https://deno.land/x/mysql/mod.ts'

const home = Deno.env.get('HOME')
console.log(`HOME: ${home}`)

const connectionData = {
'/home/codio': {
hostname: '127.0.0.1',
username: 'websiteuser',
password: 'websitepassword',
db: 'website'
},
'/app': {
hostname: 'HOSTNAME',
username: 'USERNAME',
password: 'PASSWORD',
db: 'DATABASE'
}
}

const conn = connectionData[home]
console.log(conn)

const db = await new Client().connect(conn)

export { db }
@@ -0,0 +1,4 @@
form {
width: 40%;
margin: 0 auto;
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN +28.7 KB public/images/home.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,10 @@

/* main.js */

// deno-lint-ignore-file

import { file2DataURI } from './util.js'

window.addEventListener('DOMContentLoaded', () => {
console.log('DOMContentLoaded')
})

0 comments on commit 4ee6382

Please sign in to comment.