Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mongoose = require('mongoose');
- var Schema = mongoose.Schema;
- var StorySchema = new Schema({
- creator: {type:Schema.Types.ObjectId, ref: 'User'},
- content: String,
- create: { type:Date, default: Date.now }
- });
- module.exports = mongoose.model('Story', StorySchema);
- var mongoose = require('mongoose');
- var bcrypt = require('bcrypt-nodejs');
- var Schema = mongoose.Schema;
- var UserSchema = new Schema({
- name:String,
- username: { type:String, required: true, index: { unique: true}},
- password: { type: String, reuired: true, select: false }
- });
- UserSchema.pre('save', function(next){
- var user = this;
- if(!user.isModified('password')) return next();
- bcrypt.hash(user.password, null, null, function(err, hash){
- if(err) return next(err);
- user.password = hash;
- next();
- });
- });
- UserSchema.methods.comparePassword = function(password){
- var user = this;
- return bcrypt.compareSync(password, user.password);
- }
- module.exports = mongoose.model('User', UserSchema);
- angular.module('storyCtrl', ['storyService'])
- .controller('StoryController', function(Story, socketio){
- vm = this;
- vm.stories=[];
- vm.getStories = function(){
- Story.all()
- .success(function(data){
- vm.stories = data;
- });
- };
- vm.createStory = function(){
- vm.message = '';
- Story.create(vm.storyData)
- .success(function(data){
- vm.storyData.content = '';
- vm.message = data.message;
- // vm.getStories(); // Refresh
- // vm.stories.push(vm.storyData);
- });
- };
- vm.getStories();
- socketio.on('story', function(data){
- vm.stories.push(data);
- });
- })
- .controller('allStoriesController', function(stories, socketio){
- var vm = this;
- vm.stories = stories.data;
- socketio.on('story', function(data){
- vm.stories.push(data);
- });
- })
- <div>
- <div class="col-md-4">
- </div>
- <div class="col-md-4">
- <div class="row">
- <div class="panel panel-default">
- <div class="panel-heading">
- <h4>Stories</h4>
- </div>
- <div class="panel-body">
- <ul class="list-group" >
- <li class="list-group-item" ng-repeat="s in story.stories | reverse">
- {{ s.content | date:"h:mma 'on' MMM d, y" }}
- <small>Posted by @ {{s.creator}}</small>
- <small class="pull-right">{{s.create | date:"h:mma 'on' MMM d, y"}}</small>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div class="col-md-4">
- </div>
- </div>
Add Comment
Please, Sign In to add comment