This file contains hidden or 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
var express = require("express"); | |
var bodyParser = require("body-parser"); | |
var morgan = require("morgan"); | |
var config = require("./config"); | |
var mongoose = require("mongoose"); | |
var cors = require('cors'); | |
var app = express(); | |
/** |
This file contains hidden or 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
var mongoose = require('mongoose'); | |
var bcrypt = require('bcrypt-nodejs'); | |
var Schema = mongoose.Schema; | |
/** | |
* Creating user schema. | |
* @type {*|Schema} | |
*/ | |
var UserSchema = new Schema({ | |
name: String, | |
username: {type: String, required: true, index: {unique: true}}, |
This file contains hidden or 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
var mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
/** | |
* Creating Story Schema. | |
* @type {*|Schema} | |
*/ | |
var StorySchema = new Schema({ | |
owner: String, | |
title: String, |
This file contains hidden or 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
/** | |
* Create new user and save in database. | |
*/ | |
api.post('/signup', function (req, res) { | |
var user = new User({ | |
name: req.body.name, | |
username: req.body.username, | |
password: req.body.password | |
}); | |
var toekn = createToken(user); |
This file contains hidden or 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
/** | |
* Get all users from the database. | |
*/ | |
api.get('/users', function (req, res) { | |
User.find({}, function (err, users) { | |
if (err) { | |
res.send(err); | |
return; | |
} | |
res.json(users); |
This file contains hidden or 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
/** | |
* Check logged status in order to | |
* give permission to following links. | |
*/ | |
api.use(function (req, res, next) { | |
console.log("Somebody logged into system"); | |
var token = req.body.token || req.param('token') || req.headers['x-access-token']; | |
// Check if token exists. | |
if (token) { |
This file contains hidden or 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
var User = require('../models/user'); | |
var Story = require('../models/story'); | |
var config = require('../../config'); | |
var secretKey = config.secretKey; | |
var jsonwebtoken = require('jsonwebtoken'); | |
/** | |
* Create new user token for verification. | |
* @param user | |
* @returns {number} | |
*/ |
This file contains hidden or 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
module.exports = { | |
"database":"mongodb://root:[email protected]:27707/userstory", | |
"port":process.env.PORT || 3000, | |
"secretKey" : "123456789" | |
}; |
This file contains hidden or 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
{ | |
"name": "userstory", | |
"version": "1.0.0", | |
"description": "Sample app using MEAN stack", | |
"main": "server.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Chanaka De Silva", | |
"license": "ISC", |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- This web.xml file is not required when using Servlet 3.0 container, | |
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html --> | |
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> | |
<servlet> | |
<servlet-name>Jersey Web Application</servlet-name> | |
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> | |
<init-param> | |
<param-name>jersey.config.server.provider.packages</param-name> | |
<param-value>com.chanakaSample</param-value> |
OlderNewer