This repository has been archived by the owner on Aug 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
148 changed files
with
11,734 additions
and
4,556 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,15 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
# Matches multiple files with brace expansion notation | ||
[*.{js,jsx,html,sass}] | ||
charset = utf-8 | ||
indent_style = tab | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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 |
---|---|---|
@@ -1,48 +1,3 @@ | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
*.so | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
*.manifest | ||
*.spec | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
*.log | ||
.python-version | ||
celerybeat-schedule | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
.ropeproject | ||
/site | ||
.mypy_cache/ | ||
.idea | ||
.data | ||
.DS_Store | ||
db.json | ||
node_modules | ||
yarn-error.log | ||
package-lock.json |
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 @@ | ||
node_modules |
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,5 @@ | ||
{ | ||
"semi": true, | ||
"trailingComma": "es5", | ||
"singleQuote": true | ||
} |
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,8 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
"config": path.resolve('config', 'index.js'), | ||
"models-path": path.resolve('models'), | ||
"seeders-path": path.resolve('seeders'), | ||
"migrations-path": path.resolve('migrations') | ||
}; |
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 |
---|---|---|
@@ -1,27 +1 @@ | ||
language: python | ||
|
||
python: | ||
- "3.5" | ||
|
||
services: | ||
- mysql | ||
- docker | ||
|
||
install: | ||
- python -V | ||
- pip install -r requirements.txt | ||
- mysql -e 'CREATE DATABASE IF NOT EXISTS $DB_NAME;' | ||
|
||
test: | ||
script: | ||
- python manage.py migrate | ||
- python manage.py test | ||
|
||
script: | ||
- docker build -t factlist/factlist-api . | ||
|
||
after_success: | ||
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin | ||
- if [ "$TRAVIS_BRANCH" == "master" ]; then | ||
docker push factlist/factlist-api; | ||
fi |
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,8 @@ | ||
FROM node:alpine | ||
WORKDIR "/app" | ||
COPY ./package.json ./ | ||
RUN npm install | ||
COPY . . | ||
CMD ["npm", "run", "docker"] | ||
|
||
EXPOSE 4000 |
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,34 @@ | ||
<p align="center"> | ||
<h1 align="center">Factlist</h1> | ||
<p align="center"><a href="http://factlist.com" target="_blank"><img width="150" src="https://avatars2.githubusercontent.com/u/33418877?s=200&v=4" /></a></p> | ||
</p> | ||
|
||
## About | ||
|
||
The Factlist API service is built with Nodejs, Graphql and latest stable versions of other npm packages. | ||
|
||
## Getting started | ||
|
||
### Development | ||
|
||
- Install npm modules: | ||
``` | ||
yarn install | ||
``` | ||
|
||
- Create database migration | ||
``` | ||
yarn db:migrate | ||
``` | ||
|
||
- Create database seed | ||
``` | ||
yarn db:seed | ||
``` | ||
|
||
- Start server watch | ||
``` | ||
yarn watch | ||
``` | ||
|
||
|
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,11 @@ | ||
const Login = require('./local/login'); | ||
const Register = require('./local/register'); | ||
const Twitter = require('./social/twitter'); | ||
const ResetPassword = require('./reset-password'); | ||
|
||
module.exports = app => { | ||
Login(app); | ||
Register(app); | ||
Twitter(app); | ||
ResetPassword(app); | ||
}; |
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 @@ | ||
const token = require('../../helpers/token'); | ||
const passport = require('passport'); | ||
const requireSignin = passport.authenticate('local', { session: false }); | ||
const config = require('../../config'); | ||
require('../../services/passport'); | ||
|
||
module.exports = app => { | ||
app.post('/auth/login', requireSignin, (req, res) => { | ||
res.send({ | ||
token: token.generate({ id: req.user.id }, config.auth.tokenLifeTime) | ||
}); | ||
}); | ||
}; |
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,23 @@ | ||
const User = require('../../models').users; | ||
const token = require('../../helpers/token'); | ||
const config = require('../../config'); | ||
module.exports = app => { | ||
app.post('/auth/register', async (req, res) => { | ||
if (!req.body.email || !req.body.password) { | ||
return res | ||
.status(500) | ||
.send({ error: config.locale.auth.must_provide_email }); | ||
} | ||
const user = await User.findOne({ where: { email: req.body.email } }); | ||
|
||
if (user) { | ||
return res | ||
.status(500) | ||
.send({ error: config.locale.auth.already_use_email }); | ||
} | ||
const createdUser = await User.create(req.body); | ||
res.send({ | ||
token: token.generate({ id: createdUser.id }, config.auth.tokenLifeTime) | ||
}); | ||
}); | ||
}; |
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,39 @@ | ||
const User = require('../../models').users; | ||
const config = require('../../config'); | ||
|
||
module.exports = app => { | ||
app.post('/auth/reset-password', async(req, res) => { | ||
try { | ||
const token = req.body.token; | ||
const password = req.body.password; | ||
const user = await User.findOne({ token }); | ||
if (!user) { | ||
return status(500).send({ error: config.locale.auth.token_invalid }); | ||
} | ||
await user.update({ password, token: '' }); | ||
res.status(500).send({ success: config.locale.success.global }); | ||
} catch (error) { | ||
res.status(500).send({ error }); | ||
} | ||
}); | ||
|
||
app.post('/auth/send-reset-password-mail', async (req, res) => { | ||
try { | ||
const email = req.body.email; | ||
|
||
const token = crypto.randomBytes(16).toString('hex'); | ||
|
||
const user = await User.findOne({ where: { email: email } }); | ||
|
||
if (!user) { | ||
return res.status(500).send({ error: config.locale.auth.failed }); | ||
} | ||
|
||
await user.update({ token }); | ||
//sns | ||
res.send(200, { success: config.locale.success.global }); | ||
} catch (error) { | ||
return res.status(500).send({ error }); | ||
} | ||
}); | ||
}; |
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,55 @@ | ||
const User = require('../../models').users; | ||
const passport = require('passport'); | ||
const TwitterStrategy = require('passport-twitter').Strategy; | ||
const config = require('../../config'); | ||
const token = require('../../helpers/token'); | ||
|
||
const platform = 'twitter'; | ||
const authRouter = '/auth/twitter'; | ||
const callbackRouter = '/auth/twitter/callback'; | ||
const failureRedirect = '/login'; | ||
const authMiddleware = passport.authenticate(platform, { failureRedirect }); | ||
const twitterOptions = { ...config.auth.twitter, passReqToCallback: true }; | ||
|
||
const userData = profile => { | ||
return { | ||
twitter: profile.id, | ||
username: profile.username, | ||
name: profile.displayName, | ||
email: profile.emails[0].value | ||
}; | ||
}; | ||
|
||
const twitterStrategy = new TwitterStrategy( | ||
twitterOptions, | ||
async (req, token, tokenSecret, profile, done) => { | ||
try { | ||
let user = await User.findOne({ where: { twitter: profile.id } }); | ||
if (!user) { | ||
user = await User.create(userData(profile)); | ||
} | ||
done(null, user); | ||
} catch (error) { | ||
done(error, false); | ||
} | ||
} | ||
); | ||
|
||
passport.serializeUser((user, done) => done(null, user)); | ||
passport.deserializeUser((user, done) => done(null, user)); | ||
|
||
const handleSocialAuth = (req, res) => { | ||
if (!req.user) { | ||
return res.send(config.locale.auth.not_authorized); | ||
} | ||
return res.send({ | ||
token: token.generate({ id: req.user.id }, config.auth.tokenLifeTime) | ||
}); | ||
}; | ||
|
||
module.exports = app => { | ||
app.get(authRouter, passport.authenticate(platform)); | ||
app.get(callbackRouter, authMiddleware, handleSocialAuth); | ||
}; | ||
|
||
passport.use(twitterStrategy); |
Oops, something went wrong.