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
var mongoose = require('mongoose'), | |
secrets = require('./secrets'); | |
var db = mongoose.connection; | |
mongoose.connect(secrets.db); | |
module.exports = { | |
dbconnect: function(){ | |
db.on('error', console.error.bind( console, 'MongoDB Connection Error. Please make sure that MongoDB is running.')); | |
db.once('open', function callback(){ |
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
{ | |
"name": "yourtube", | |
"version": "0.0.0", | |
"homepage": "https://github.com/goodheads/yourtube", | |
"authors": [ | |
"Prosper Otemuyiwa <prosperotemuyiwa@gmail.com>" | |
], | |
"moduleType": [ | |
"amd", | |
"es6", |
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
TOKEN_SECRET=yourtube | |
MONGODB=mongodb://localhost:27017/yourtube |
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
var mongoose = require('mongoose'), | |
bcrypt = require('bcrypt'), | |
userSchema = mongoose.Schema({ | |
fullName: { type: String }, | |
email: { type: String, required: true, unique: true, lowercase: true }, | |
password: { type: String, required: true }, | |
user_avatar: { type: String, default: 'http://s3.amazonaws.com/37assets/svn/765-default-avatar.png' }, | |
registered_on: { type: Date, default: Date.now } | |
}); |
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
var User = require('../models/user.server.model'), | |
cloudinary = require('cloudinary'), | |
gravatar = require('gravatar'), | |
secrets = require('../../config/secrets'), | |
token = require('../../config/token'); | |
module.exports = { | |
/** | |
* Welcome Notice | |
* @param req |
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
1. The welcome function simply returns a json response that says "Welcome to Yourtube Api" | |
2. The registerUser function, with the aid of the User model checks if a user already exists with that email coming from the user input. If no user exists with that email, It gets the avatar of the user, saves the user details and creates a secure token else it returns an appropriate message. token.createJWT does the work of creating the token. The createJWT function can be found in the config/token file. | |
3. The getLoggedInUserDetail function queries the user collection and returns the user detail. | |
4. The updateLoggedInUserDetail function updates the user details in the user collection. | |
5. The authenticate function verifies if the email and password matches before returning a valid token. |
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
var User = require('./controllers/user.server.controller'), | |
token = require('../config/token'); | |
module.exports = function(app) { | |
app.get('/api', User.welcome); | |
app.post('/api/login', User.authenticate); | |
app.post('/api/register', User.registerUser); | |
app.get('/api/me', User.getLoggedInUserDetail); |
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
var jwt = require('jwt-simple'), | |
secrets = require('./secrets'), | |
moment = require('moment'); | |
/* | |
|-------------------------------------------------------------------------- | |
| Generate JSON Web Token | |
|-------------------------------------------------------------------------- | |
*/ | |
function createJWT(user) { |
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
var User = require('./controllers/user.server.controller'), | |
token = require('../config/token'); | |
module.exports = function(app) { | |
app.get('/api', token.ensureAuthenticated, User.welcome); | |
app.post('/api/login', User.authenticate); | |
app.post('/api/register', User.registerUser); | |
app.get('/api/me', token.ensureAuthenticated, User.getLoggedInUserDetail); |
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
<!doctype html> | |
<html lang="en" ng-app="yourtube"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="author" content="Prosper Otemuyiwa"> | |
<meta name="HandheldFriendly" content="true"> | |
<meta property="og:title" content="Yourtube"> | |
<meta property="og:type" content="website"> | |
<meta property="og:url" content="https://yourtube.com"> |