able to write to the db

This commit is contained in:
Michael Q Larson
2014-10-13 16:01:52 -07:00
parent a5985cd73d
commit ad929be410
9 changed files with 762 additions and 699 deletions

View File

@@ -6,7 +6,7 @@
exports.index = function(req, res) { exports.index = function(req, res) {
res.render('curriculum/curriculum', { res.render('curriculum/curriculum', {
title: 'Curriculum', title: 'Curriculum',
test: 'hi' test: 'hi',
courses: Course.all
}); });
}; };

View File

@@ -1,74 +1,28 @@
var mongoose = require('mongoose'); var mongoose = require('mongoose');
var secrets = require('../config/secrets');
var bcrypt = require('bcrypt-nodejs'); var bcrypt = require('bcrypt-nodejs');
var crypto = require('crypto'); var crypto = require('crypto');
var courses = require('../seed_data/courses.json');
var userSchema = new mongoose.Schema({ console.log(courses);
email: { type: String, unique: true, lowercase: true },
password: String,
twitter: String, var courseSchema = new mongoose.Schema({
instagram: String, name: { type: String, unique: true },
tokens: Array, link: String,
image: String,
profile: { time: Number,
name: { type: String, default: '' }, directions_1: String,
gender: { type: String, default: '' }, directions_2: String,
location: { type: String, default: '' }, directions_3: String,
website: { type: String, default: '' },
picture: { type: String, default: '' }
},
resetPasswordToken: String,
resetPasswordExpires: Date
}); });
/** var Courses = module.exports = mongoose.model('Course', courseSchema);
* Hash the password for security.
* "Pre" is a Mongoose middleware that executes before each user.save() call.
*/
userSchema.pre('save', function(next) { if (require.main === module) {
var user = this; mongoose.connect(secrets.db);
Courses.create(courses, function(err, data) {
if (!user.isModified('password')) return next(); if (err) console.log(err);
else console.log('Saved ', data );
bcrypt.genSalt(5, function(err, salt) { process.exit(0);
if (err) return next(err);
bcrypt.hash(user.password, salt, null, function(err, hash) {
if (err) return next(err);
user.password = hash;
next();
});
}); });
}); }
/**
* Validate user's password.
* Used by Passport-Local Strategy for password validation.
*/
userSchema.methods.comparePassword = function(candidatePassword, cb) {
bcrypt.compare(candidatePassword, this.password, function(err, isMatch) {
if (err) return cb(err);
cb(null, isMatch);
});
};
/**
* Get URL to a user's gravatar.
* Used in Navbar and Account Management page.
*/
userSchema.methods.gravatar = function(size) {
if (!size) size = 200;
if (!this.email) {
return 'https://gravatar.com/avatar/?s=' + size + '&d=retro';
}
var md5 = crypto.createHash('md5').update(this.email).digest('hex');
return 'https://gravatar.com/avatar/' + md5 + '?s=' + size + '&d=retro';
};
module.exports = mongoose.model('User', userSchema);

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="100px" height="100px" fill="#ddd" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="100px" height="100px" fill="#fff" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve">
<g> <g>
<path d="M74.256,81.934l-6.426-2.04l6.426-2.039c0.271-0.085,0.498-0.276,0.629-0.53c0.131-0.252,0.156-0.547,0.07-0.817 l-2.553-8.047c-0.178-0.564-0.776-0.876-1.349-0.698L50.32,74.34l-20.733-6.578c-0.567-0.178-1.171,0.134-1.348,0.698l-2.555,8.047 c-0.084,0.27-0.06,0.565,0.071,0.817c0.132,0.253,0.358,0.444,0.629,0.53l6.426,2.039l-6.426,2.04 c-0.564,0.178-0.878,0.781-0.698,1.346l2.553,8.047c0.085,0.271,0.275,0.497,0.529,0.628c0.153,0.08,0.322,0.121,0.493,0.121 c0.107,0,0.219-0.017,0.325-0.05l20.733-6.578l20.733,6.578c0.106,0.033,0.218,0.05,0.325,0.05c0.172,0,0.34-0.041,0.493-0.121 c0.254-0.131,0.444-0.357,0.53-0.628l2.553-8.047C75.132,82.715,74.82,82.112,74.256,81.934z"/> <path d="M74.256,81.934l-6.426-2.04l6.426-2.039c0.271-0.085,0.498-0.276,0.629-0.53c0.131-0.252,0.156-0.547,0.07-0.817 l-2.553-8.047c-0.178-0.564-0.776-0.876-1.349-0.698L50.32,74.34l-20.733-6.578c-0.567-0.178-1.171,0.134-1.348,0.698l-2.555,8.047 c-0.084,0.27-0.06,0.565,0.071,0.817c0.132,0.253,0.358,0.444,0.629,0.53l6.426,2.039l-6.426,2.04 c-0.564,0.178-0.878,0.781-0.698,1.346l2.553,8.047c0.085,0.271,0.275,0.497,0.529,0.628c0.153,0.08,0.322,0.121,0.493,0.121 c0.107,0,0.219-0.017,0.325-0.05l20.733-6.578l20.733,6.578c0.106,0.033,0.218,0.05,0.325,0.05c0.172,0,0.34-0.041,0.493-0.121 c0.254-0.131,0.444-0.357,0.53-0.628l2.553-8.047C75.132,82.715,74.82,82.112,74.256,81.934z"/>
<path d="M50.646,65.841c26.751-2.229,16.186-36.697,11.396-44.995C56.646,11.498,49.336,5.523,49.336,5.523 c1.946,14.062-3.691,23.684-3.691,23.684l-5.788-6.953c-2.086,16.911-11.338,23.52-5.473,34.308 C40.043,66.97,50.646,65.841,50.646,65.841z M47.231,39.783l2.545,3.057c0,0,5.359-7.878,4.503-14.062c0,0,3.304,4.616,4.806,9.119 c1.497,4.485,4.654,20.073-7.108,21.053c0,0-4.663,0.496-7.152-4.081C42.246,50.125,46.314,47.219,47.231,39.783z"/> <path d="M50.646,65.841c26.751-2.229,16.186-36.697,11.396-44.995C56.646,11.498,49.336,5.523,49.336,5.523 c1.946,14.062-3.691,23.684-3.691,23.684l-5.788-6.953c-2.086,16.911-11.338,23.52-5.473,34.308 C40.043,66.97,50.646,65.841,50.646,65.841z M47.231,39.783l2.545,3.057c0,0,5.359-7.878,4.503-14.062c0,0,3.304,4.616,4.806,9.119 c1.497,4.485,4.654,20.073-7.108,21.053c0,0-4.663,0.496-7.152-4.081C42.246,50.125,46.314,47.219,47.231,39.783z"/>

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -1,4 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="30px" height="30px" viewBox="0 0 30 30" fill="#ddd" enable-background="new 0 0 30 30" xml:space="preserve"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="30px" height="30px" viewBox="0 0 30 30" fill="#222" enable-background="new 0 0 30 30" xml:space="preserve">
<g> <g>
<path d="M-95.333,17.557v3.552H-87h8.333v-3.552h7.333v3.552h1C-67.709,21.109-57,16.875-57,4.891V0 c0-1.474-1.194-2.667-2.667-2.667h-54.667C-115.806-2.667-117-1.474-117,0v4.891c0,11.984,10.709,16.219,13.333,16.219h1v-3.552 h7.334V17.557z"/> <path d="M-95.333,17.557v3.552H-87h8.333v-3.552h7.333v3.552h1C-67.709,21.109-57,16.875-57,4.891V0 c0-1.474-1.194-2.667-2.667-2.667h-54.667C-115.806-2.667-117-1.474-117,0v4.891c0,11.984,10.709,16.219,13.333,16.219h1v-3.552 h7.334V17.557z"/>
<path d="M-78.667,29.558v-5.782H-87h-8.333v5.782h-7.333v-5.782h-1c-2.417,0-9.647-2.56-13.333-9.51v24.401 c0,1.474,1.194,2.666,2.667,2.666h54.667c1.473,0,2.667-1.192,2.667-2.666V14.266c-3.686,6.951-10.917,9.51-13.333,9.51h-1v5.782 H-78.667z"/> <path d="M-78.667,29.558v-5.782H-87h-8.333v5.782h-7.333v-5.782h-1c-2.417,0-9.647-2.56-13.333-9.51v24.401 c0,1.474,1.194,2.666,2.667,2.666h54.667c1.473,0,2.667-1.192,2.667-2.666V14.266c-3.686,6.951-10.917,9.51-13.333,9.51h-1v5.782 H-78.667z"/>

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@@ -1,4 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100" fill="#ddd" enable-background="new 0 0 100 100" xml:space="preserve"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100" fill="#222" enable-background="new 0 0 100 100" xml:space="preserve">
<g id="Capa_33" display="none"> <g id="Capa_33" display="none">
</g> </g>
<g id="Capa_35"> <g id="Capa_35">

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@@ -1,4 +1,4 @@
<svg xmlns:x="http://ns.adobe.com/Extensibility/1.0/" xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/" xmlns:graph="http://ns.adobe.com/Graphs/1.0/" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0" id="Layer_1" x="0px" y="0px" width="100px" height="81.102px" fill="#ddd" viewBox="0 0 100 81.102" enable-background="new 0 0 100 81.102" xml:space="preserve"> <svg xmlns:x="http://ns.adobe.com/Extensibility/1.0/" xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/" xmlns:graph="http://ns.adobe.com/Graphs/1.0/" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0" id="Layer_1" x="0px" y="0px" width="100px" height="81.102px" fill="#222" viewBox="0 0 100 81.102" enable-background="new 0 0 100 81.102" xml:space="preserve">
<switch> <switch>
<foreignObject requiredExtensions="http://ns.adobe.com/AdobeIllustrator/10.0/" x="0" y="0" width="1" height="1"> <foreignObject requiredExtensions="http://ns.adobe.com/AdobeIllustrator/10.0/" x="0" y="0" width="1" height="1">
</foreignObject> </foreignObject>

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -13,7 +13,7 @@
.collapse.navbar-collapse .collapse.navbar-collapse
ul.nav.navbar-nav.navbar-right ul.nav.navbar-nav.navbar-right
if !user if !user
a.btn.btn-primary.btn-nav.btn-sm(href='/login') Sign in with LinkedIn a.btn.btn-primary.btn-nav.btn-sm(href='/login') Sign in
else else
li.dropdown(class=title=='Account Management'?'active':undefined) li.dropdown(class=title=='Account Management'?'active':undefined)
a.dropdown-toggle(href='#', data-toggle='dropdown') a.dropdown-toggle(href='#', data-toggle='dropdown')