Skip to content
Permalink
Browse files

Initial on new repo.

  • Loading branch information...
n1try
n1try committed Nov 16, 2016
0 parents commit e9bc01c8c5e9a3362d8d2cc109ee29637a7bad7f
Showing with 4,200 additions and 0 deletions.
  1. +12 −0 .gitignore
  2. +108 −0 Gruntfile.js
  3. +25 −0 app.js
  4. +69 −0 app/controllers/auth.js
  5. +187 −0 app/controllers/collection.js
  6. +61 −0 app/controllers/image.js
  7. +38 −0 app/controllers/shared.js
  8. +37 −0 app/controllers/shortlink.js
  9. +28 −0 app/models/collection.js
  10. +25 −0 app/models/image.js
  11. +22 −0 app/models/shortlink.js
  12. +51 −0 app/models/user.js
  13. +19 −0 app/views/error.jade
  14. +9 −0 bower.json
  15. +18 −0 cluster.js
  16. +32 −0 config/auth.js
  17. +53 −0 config/config.js
  18. +93 −0 config/express.js
  19. +21 −0 config/log.js
  20. +14 −0 config/middlewares/error.js
  21. +20 −0 config/middlewares/filetype.js
  22. +9 −0 config/middlewares/jwtauth.js
  23. +9 −0 config/middlewares/log.js
  24. +161 −0 config/passport.js
  25. +42 −0 package.json
  26. +21 −0 public/.editorconfig
  27. +9 −0 public/.gitignore
  28. +390 −0 public/Gruntfile.js
  29. +12 −0 public/README.md
  30. +152 −0 public/app/404.html
  31. BIN public/app/favicon.ico
  32. BIN public/app/images/beta.png
  33. BIN public/app/images/facebook.png
  34. BIN public/app/images/germany.png
  35. BIN public/app/images/google.png
  36. BIN public/app/images/logo.png
  37. BIN public/app/images/twitter.png
  38. BIN public/app/images/yeoman.png
  39. +165 −0 public/app/index.html
  40. +4 −0 public/app/robots.txt
  41. +131 −0 public/app/scripts/app.js
  42. +5 −0 public/app/scripts/controllers/api.js
  43. +10 −0 public/app/scripts/controllers/auth.js
  44. +142 −0 public/app/scripts/controllers/collection.js
  45. +91 −0 public/app/scripts/controllers/image.js
  46. +37 −0 public/app/scripts/controllers/login.js
  47. +5 −0 public/app/scripts/controllers/main.js
  48. +44 −0 public/app/scripts/controllers/shortlink.js
  49. +36 −0 public/app/scripts/controllers/signup.js
  50. +5 −0 public/app/scripts/controllers/terms.js
  51. +22 −0 public/app/scripts/controllers/view-collection.js
  52. +48 −0 public/app/scripts/controllers/view-image.js
  53. +16 −0 public/app/scripts/directives/apicall.js
  54. +16 −0 public/app/scripts/directives/myenter.js
  55. +13 −0 public/app/scripts/filters/imageLinkFilters.js
  56. +41 −0 public/app/scripts/services/auth.js
  57. +16 −0 public/app/scripts/services/collection.js
  58. +15 −0 public/app/scripts/services/config.js
  59. +9 −0 public/app/scripts/services/image.js
  60. +6 −0 public/app/scripts/services/shortlink.js
  61. +10 −0 public/app/scripts/services/snackbar.js
  62. +195 −0 public/app/styles/custom.css
  63. +73 −0 public/app/styles/main.css
  64. +172 −0 public/app/views/api.html
  65. +120 −0 public/app/views/collection.html
  66. +84 −0 public/app/views/image.html
  67. +40 −0 public/app/views/login.inc.html
  68. +26 −0 public/app/views/main.html
  69. +38 −0 public/app/views/shortlink.html
  70. +39 −0 public/app/views/signup.inc.html
  71. +30 −0 public/app/views/templates/apicall.tpl.html
  72. +29 −0 public/app/views/terms.html
  73. +53 −0 public/app/views/view-collection.html
  74. +104 −0 public/app/views/view-image.html
  75. +33 −0 public/bower.json
  76. +35 −0 public/package.json
  77. +87 −0 public/test/karma.conf.js
  78. +23 −0 public/test/spec/controllers/about.js
  79. +23 −0 public/test/spec/controllers/api.js
  80. +23 −0 public/test/spec/controllers/auth.js
  81. +23 −0 public/test/spec/controllers/collection.js
  82. +23 −0 public/test/spec/controllers/image.js
  83. +23 −0 public/test/spec/controllers/login.js
  84. +23 −0 public/test/spec/controllers/main.js
  85. +23 −0 public/test/spec/controllers/shortlink.js
  86. +23 −0 public/test/spec/controllers/signup.js
  87. +23 −0 public/test/spec/controllers/terms.js
  88. +23 −0 public/test/spec/controllers/view-image.js
  89. +20 −0 public/test/spec/directives/apicall.js
  90. +20 −0 public/test/spec/directives/myenter.js
  91. +18 −0 public/test/spec/services/auth.js
  92. +4 −0 public/test/spec/services/collection.js
  93. +18 −0 public/test/spec/services/config.js
  94. +18 −0 public/test/spec/services/image.js
  95. +18 −0 public/test/spec/services/shortlink.js
  96. +18 −0 public/test/spec/services/snackbar.js
  97. +21 −0 utils.js
@@ -0,0 +1,12 @@
node_modules/
public/components
.sass-cache
.idea
.bowerrc
.data
data
log/*
*.log
.vscode
snippets/history.json
snippets/*.log
@@ -0,0 +1,108 @@
'use strict';

var request = require('request');

module.exports = function (grunt) {
// show elapsed time at the end
require('time-grunt')(grunt);
// load all grunt tasks
require('load-grunt-tasks')(grunt);

var reloadPort = 35729, files;

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
develop: {
server: {
file: 'app.js'
}
},
watch: {
options: {
nospawn: true,
livereload: reloadPort
},
js: {
files: [
'app.js',
'app/**/*.js',
'config/*.js'
],
tasks: ['develop', 'delayed-livereload']
},
css: {
files: [
'public/css/*.css'
],
options: {
livereload: reloadPort
}
},
views: {
files: [
'app/views/*.jade',
'app/views/**/*.jade'
],
options: { livereload: reloadPort }
}
},

env: {
dev: {
NODE_ENV : 'development'
},
test: {
NODE_ENV : 'test'
},
production: {
NODE_ENV : 'production'
}
},

execute: {
cluster: {
src: ['cluster.js']
},
single: {
src: ['app.js']
}
}
});

grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-execute');

grunt.config.requires('watch.js.files');
files = grunt.config('watch.js.files');
files = grunt.file.expand(files);

grunt.registerTask('delayed-livereload', 'Live reload after the node server has restarted.', function () {
var done = this.async();
setTimeout(function () {
request.get('http://localhost:' + reloadPort + '/changed?files=' + files.join(','), function(err, res) {
var reloaded = !err && res.statusCode === 200;
if (reloaded)
grunt.log.ok('Delayed live reload successful.');
else
grunt.log.error('Unable to make a delayed live reload.');
done(reloaded);
});
}, 500);
});


grunt.registerTask('default', [
'develop',
'watch'
]);

grunt.registerTask('production', [
'env:production',
'execute:cluster'
]);

grunt.registerTask('single', [
'env:production',
'execute:single'
]);
};
25 app.js
@@ -0,0 +1,25 @@
var express = require('express')
, config = require('./config/config')
, glob = require('glob')
, mongoose = require('mongoose')
, fs = require('fs')
, loggers = require('./config/log')();

mongoose.connect(config.db);
var db = mongoose.connection;
db.on('error', function () {
throw new Error('unable to connect to database at ' + config.db);
});

var models = glob.sync(config.root + '/app/models/*.js');
models.forEach(function (model) {
require(model);
});
var app = express();

require('./config/express')(app, config);

app.listen(config.port, function () {
loggers.default.info('Express server listening on port ' + config.port);
});

@@ -0,0 +1,69 @@
var express = require('express')
, router = express.Router()
, jwt = require('jsonwebtoken')
, config = require('./../../config/config')
, log = require('./../../config/middlewares/log')()
, utils = require('../../utils')
, mongoose = require('mongoose')
, Collection = mongoose.model('Collection');

module.exports = function (app, passport) {
app.use('/api/auth', router);

router.use(log);

router.post('/signup', function (req, res, next) {
passport.authenticate('local-signup', function (err, user) {
if (err || !user) return res.makeError(400, err.message || 'Unknown error during signup.', err);

res.status(201).end();
})(req, res, next);
});

router.post('/token', function (req, res, next) {
passport.authenticate('local-login', function (err, user) {
if (err || !user) return res.makeError(400, err.message || 'Unknown error during login.', err);

res.status(200).send({token : user.jwtSerialize('local')});
initUser(user);
})(req, res, next);
});

router.get('/facebook', passport.authenticate('facebook', { scope : ['email']}));

router.get('/facebook/callback', function (req, res, next) {
passport.authenticate('facebook', function (err, user) {
if (!user) return res.makeError(401, 'Unauthorized.', err, true);

res.redirect(config.clientUrl + 'auth/' + user.jwtSerialize('facebook'));
initUser(user);
})(req, res, next);
});

router.get('/google', passport.authenticate('google', { scope : ['profile', 'email']}));

router.get('/google/callback', function (req, res, next) {
passport.authenticate('google', function (err, user) {
if (!user) return res.makeError(401, 'Unauthorized.', err, true);

res.redirect(config.clientUrl + 'auth/' + user.jwtSerialize('google'));
initUser(user);
})(req, res, next);
});
};

function initUser(user) {
Collection.findOne({name : 'My shortlinks', owner : user._id}, function (err, result) {
if (err) return res.makeError(500, err.message, err);
if (result) return true;
else {
new Collection({
_id: utils.generateUUID(),
name: 'My shortlinks',
links: [],
owner: user._id,
shared : false
}).save();
}
});
}

0 comments on commit e9bc01c

Please sign in to comment.
You can’t perform that action at this time.