Skip to content
Permalink
Browse files
Initial Commit for Assignment Template
Fixed Style.css implement
  • Loading branch information
Hassan committed Jul 15, 2020
1 parent ff2cf79 commit 3f1e0292c5ce8f75d9b533eda37de1853e028276
Show file tree
Hide file tree
Showing 21 changed files with 11,244 additions and 0 deletions.
@@ -0,0 +1,4 @@

docs/**
node_modules/**
coverage/**
@@ -0,0 +1,77 @@

{
"env": {
"es6": true,
"jasmine": true,
"node": true,
"browser": true,
"jest": true
},
"parserOptions": {
"ecmaVersion": 2018,
"noInlineConfig": true,
"reportUnusedDisableDirectives": true,
"sourceType": "module"
},
"rules": {
"arrow-body-style": "error",
"arrow-spacing": ["warn", {"before": true, "after": true}],
"brace-style": "error",
"camelcase": ["error", {"properties": "never"}],
"complexity": ["error", 5],
"eol-last": "warn",
"eqeqeq": "error",
"func-call-spacing": ["error", "never"],
"global-require": "error",
"handle-callback-err": "warn",
"indent": ["warn", "tab", {"SwitchCase": 1}],
"key-spacing": ["error", {"beforeColon": false, "afterColon": true}],
"linebreak-style": ["warn", "unix"],
"max-depth": ["error", 3],
"max-len": ["warn", { "code": 120, "tabWidth": 4 }],
"max-lines": ["warn", {"max": 150, "skipBlankLines": true, "skipComments": true}],
"max-lines-per-function": ["warn", {"max": 20, "skipBlankLines": true, "skipComments": true}],
"max-nested-callbacks": ["error", 4],
"max-params": ["error", 5],
"max-statements": ["error", 20],
"no-cond-assign": "error",
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty": "warn",
"no-empty-function": "error",
"no-multiple-empty-lines": "warn",
"no-extra-parens": "error",
"no-func-assign": "error",
"no-irregular-whitespace": "error",
"no-magic-numbers": ["warn", {"ignore": [-1, 0, 1]}],
"no-multi-spaces": "warn",
"no-multi-str": "off",
"no-unexpected-multiline": "error",
"no-unreachable": "error",
"no-self-assign": "error",
"no-trailing-spaces": "warn",
"no-undef": "error",
"no-unused-vars": "warn",
"no-var": 2,
"prefer-arrow-callback": "warn",
"prefer-const": "error",
"prefer-template": "error",
"quotes": ["warn", "single"],
"semi": ["warn", "never"],
"space-before-blocks": ["error", { "functions": "always", "keywords": "always", "classes": "always" }],
"space-before-function-paren": ["error", "never"],
"strict": ["error", "global"],
"yoda": "error"
},
"overrides": [{
"files": [ "*.test.js", "*.spec.js", "*.steps.js" ],
"rules": {
"global-require": "off",
"max-lines-per-function": "off",
"max-lines": "off",
"max-statements": "off",
"no-magic-numbers": "off"
}
}]
}
@@ -0,0 +1,38 @@

.DS_Store
node_modules/
coverage/
screenshots/*
docs/


npm-debug.log*
yarn-debug.log*
yarn-error.log*

/.idea

data/
coverage/
sessions/
screenshots/
__image_snapshots_/
__diff_output__/
trace/
.node-persist/

*.db
*snap.png
*diff.png
*trace.json
*.0x

config.json
#Should probably be re-added
#Or at least provide documentation on how to populate

*.pptx
*.mp4

*.codio
*.c9
@@ -0,0 +1,44 @@

# Assignment Code

This is the template code that you will need to use as a starting point for your coursework.

You should make sure you are accessing Codio using a standards-compliant web browser such as **Google Chrome** or **Chromium**.

## Running Your Server

All the core packages have already been installed so all you need to do to get your server running is to open the **terminal** from the **Tools** menu (if it is not already open) and run the following command:

```shell
$ node index.js
```

This will start your web server. To view your website click on the dropdown list labelled **Live Site** at the top of the Codio window and choose the **New browser tab** option. This will open your website in a new tab.

To make life easier you can split your editor window both horizontally and/or vertically so you can see both the code and the terminal. Use the **View > Panels** and **View > Layout** menus.

## Setting up a Git Repository

As part of the assignment you are expected to make regular commits to your git repository. Follow this step by step guide:

### Local Config Settings

Before you make any commits you need to update the [local config settings](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup). Start by using the Terminal (or Git Bash on Windows) navigate inside the project. Once you are in this directory run the following commands, substituting you name as it appears on your ID badge and your university email address (without the `uni.` domain prefix).

```bash
git config user.name 'John Doe'
git config user.email 'doej@coventry.ac.uk'
git config core.hooksPath .githooks
git config --add merge.ff false
```

### Create a New Remote Repository

1. Log onto the [University GitHub server](github.coventry.ac.uk) using your University username and password.
2. Your assignment brief will give you the _organisation url_, this will take you to the module page on GitHub.
3. Create a new repository using the green **New** button:
1. The name of the repository should be your university username, eg. `doej`. If you are taking the resit add the `-resit` suffix, eg. `doej-resit`.
2. The description should be the topic you were assigned (eg. **Customer Relationship Manager**).
3. The repository should be **private**.
4. Now follow the instructions git provides under the heading **create a new repository on the command line**.
1. Don't run the first `echo` command as this will delete these instructions!
@@ -0,0 +1,31 @@

const Koa = require('koa')
const session = require('koa-session')
const staticDir = require('koa-static')
const views = require('koa-views')

const apiRouter = require('./routes/routes')

const app = new Koa()
app.keys = ['darkSecret']

const defaultPort = 8080
const port = process.env.PORT || defaultPort

app.use(staticDir('public'))
app.use(session(app))
app.use(views(`${__dirname}/views`, { extension: 'handlebars' }, {map: { handlebars: 'handlebars' }}))

app.use( async(ctx, next) => {
console.log(`${ctx.method} ${ctx.path}`)
ctx.hbs = {
authorised: ctx.session.authorised,
host: `https://${ctx.host}`
}
for(const key in ctx.query) ctx.hbs[key] = ctx.query[key]
await next()
})

app.use(apiRouter.routes(), apiRouter.allowedMethods())

module.exports = app.listen(port, async() => console.log(`listening on port ${port}`))
@@ -0,0 +1,22 @@

{
"tags": {
"allowUnknownTags": true,
"dictionaries": ["jsdoc","closure"]
},
"source": {
"include": [ "." ],
"exclude": [ "node_modules" ],
"includePattern": ".+\\.js(doc|x)?$",
"excludePattern": "(^|\\/|\\\\)_"
},
"plugins": ["jsdoc-route-plugin"],
"templates": {
"cleverLinks": false,
"monospaceLinks": false
},
"opts": {
"destination": "docs/jsdoc",
"recurse": true
}
}
@@ -0,0 +1,62 @@

const bcrypt = require('bcrypt-promise')
const sqlite = require('sqlite-async')

const saltRounds = 10

module.exports = class User {

constructor(dbName = ':memory:') {
return (async() => {
this.db = await sqlite.open(dbName)
// we need this table to store the user accounts
const sql = 'CREATE TABLE IF NOT EXISTS users\
(id INTEGER PRIMARY KEY AUTOINCREMENT, user TEXT, pass TEXT, email TEXT);'
await this.db.run(sql)
return this
})()
}

/**
* registers a new user
* @param {String} user the chosen username
* @param {String} pass the chosen password
* @returns {Boolean} returns true if the new user has been added
*/
async register(user, pass, email) {
Array.from(arguments).forEach( val => {
if(val.length === 0) throw new Error('missing field')
})
let sql = `SELECT COUNT(id) as records FROM users WHERE user="${user}";`
const data = await this.db.get(sql)
if(data.records !== 0) throw new Error(`username "${user}" already in use`)
sql = `SELECT COUNT(id) as records FROM users WHERE email="${email}";`
const emails = await this.db.get(sql)
if(emails.records !== 0) throw new Error(`email address "${email}" is already in use`)
pass = await bcrypt.hash(pass, saltRounds)
sql = `INSERT INTO users(user, pass, email) VALUES("${user}", "${pass}", "${email}")`
await this.db.run(sql)
return true
}

/**
* checks to see if a set of login credentials are valid
* @param {String} username the username to check
* @param {String} password the password to check
* @returns {Boolean} returns true if credentials are valid
*/
async login(username, password) {
let sql = `SELECT count(id) AS count FROM users WHERE user="${username}";`
const records = await this.db.get(sql)
if(!records.count) throw new Error(`username "${username}" not found`)
sql = `SELECT pass FROM users WHERE user = "${username}";`
const record = await this.db.get(sql)
const valid = await bcrypt.compare(password, record.pass)
if(valid === false) throw new Error(`invalid password for account "${username}"`)
return true
}

async tearDown() {
await this.db.close()
}
}

0 comments on commit 3f1e029

Please sign in to comment.