This repository has been archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Florian Wendelborn
committed
Feb 22, 2017
1 parent
7ef4254
commit 6fcde49
Showing
9 changed files
with
234 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# SmartFlat Modules | ||
|
||
[Back to Modules](./) | ||
|
||
## Installation Guide | ||
|
||
To manually install a SmartFlat module, put the module into `smartflat/modules` and run `yarn run build`. You may need to create the `modules` folder. | ||
|
||
Afterwards restart SmartFlat and the module should work. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Storage modules | ||
|
||
Storage modules are used to allow SmartFlat to persist sensor & user data. | ||
|
||
## Types | ||
|
||
| Name | Purpose | Persistance required? | | ||
|:---------|:---------------------------------------|:----------------------| | ||
| users | username, password, permissions, etc. | :white_check_mark: | | ||
| settings | SmartFlat settings. Required. | :white_check_mark: | | ||
| devices | device configurations, not sensor data | :white_check_mark: | | ||
| sensor | sensor data | :x: | | ||
| logs | generic stuff like "module installed" | :x: | | ||
|
||
## API | ||
|
||
```javascript | ||
export default ({api}) => ({ | ||
subscribe: { | ||
user: async (type, id, data) => {/*...*/} | ||
}, | ||
provide: { | ||
user: async (type, id) => {/*...*/} | ||
} | ||
}) | ||
``` | ||
|
||
## Caveats | ||
|
||
1. Multiple storage modules may subscribe to a type, but only one per type can provide data. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// region import | ||
|
||
import * as session from './session' | ||
|
||
// endregion | ||
|
||
// region export | ||
|
||
export default { | ||
session | ||
} | ||
|
||
// endregion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// region import | ||
|
||
import crypto from 'crypto' | ||
import jwt from 'jsonwebtoken' | ||
|
||
// internal | ||
|
||
import {provide} from '../utilities/modules' | ||
|
||
// endregion | ||
|
||
// region crypto | ||
|
||
const key = 'secret' | ||
const hashPassword = async ({password, salt}) => new Promise((resolve, reject) => | ||
crypto.pbkdf2(key, salt, 64000, 512, 'sha512', (error, key) => error | ||
? reject(error) | ||
: resolve(key.toString('base64')) | ||
) | ||
) | ||
|
||
// endregion | ||
|
||
// region export | ||
|
||
export const verify = async (token) => | ||
jwt.verify(token, key, { | ||
algorithms: ['HS256'] | ||
}) | ||
|
||
export const signIn = async ({name, password}) => { | ||
const {salt, hash} = await provide.user({name}) | ||
const realHash = await hashPassword({password, salt}) | ||
|
||
if (hash === realHash) return jwt.sign({ | ||
name | ||
}, key, { | ||
expiresIn: '10s' | ||
}) | ||
|
||
throw 'wrong password' | ||
} | ||
|
||
// endregion |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters