Skip to content

Instantly share code, notes, and snippets.

View xavidram's full-sized avatar

Xavid Ramirez xavidram

View GitHub Profile
'use strict';
const express = require('express');
// Import the Controller so we may assign specific functions to a route
const controller = require('./user.controller');
// Assign the route variable to an Express.Route handler
const router = express.Router();
/**
* path: /api/user
'use strict';
const User = require('./user.model');
/**
* Handles validation errors and returns the error to the user.
* @param {Express.Response} res - an Express Response object
* @param {number} statusCode - the result status code number
*/
function validationError(res, statusCode) {
statusCode = statusCode || 422;
import { AuthService } from './../providers/auth.service';
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { Observable } from 'rxjs';
import 'rxjs/add/operator/map';
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
const Schema = mongoose.Schema; // Mongoose model is a Schema
// User Model Definition below
const UserSchema = new Schema({
name: String,
email: {
type: String,
lowercase: true,
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
// Importing new installs
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
const connectMongo = require('connect-mongo');
const session = require('express-session');
const MongoStore = connectMongo(session);
const path = require('path');
const _ = require('lodash');
/**
* Configuration settings for DB and application
*/
const all = {
// secrets used to encrypt session data
secrets: {
// this secret is used to encrypt express session logs as well as user password
// We set the route of the templates and give it to expres
app.set('views', `${__dirname}/server/views`);
// Tell express's engine what file format we are targeting and what
// library to use, in this case we use EJS and it;d renderfile engine
app.engine('html', require('ejs').renderFile);
// And lastly we set the 'view engine' to be HTML
app.set('view engine', 'html');
const errors = require('./components/errors');
const path = require('path');
/**
* Sets up all the routes for the Express app.
* @param {Express} app - contains a reference to the Express App in the app.js file in the root of the project
* @param {__dirname} root - contains an Object value pointing to the root of the project
*/
module.exports = function routes(app, root) {
// Any new endpoints you create you will want to add them here
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
/**
* We create the app variable and initialize it to be an Express Application
*/
const app = express();