Skip to content

Commit

Permalink
aplicando mean
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoq committed Dec 23, 2013
1 parent 14147f7 commit c87b01f
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 6 deletions.
101 changes: 101 additions & 0 deletions app/controllers/eventos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Eventos = mongoose.model('Eventos'),
_ = require('lodash');


/**
* Find article by id
*/
exports.article = function(req, res, next, id) {
Eventos.load(id, function(err, article) {
if (err) return next(err);
if (!article) return next(new Error('Failed to load article ' + id));
req.article = article;
next();
});
};


/**
* Show cadastroEvento form
*/
exports.cadastro = function(req, res) {
res.render('eventos/cadastro', {
title: 'Sign up',
eventos: new Eventos()
});
};

/**
* Create a article
*/
exports.create = function(req, res) {
var article = new Eventos(req.body);
article.user = req.user;

article.save(function(err) {
if (err) {
return res.send('users/signup', {
errors: err.errors,
article: article
});
} else {
res.jsonp(article);
}
});
};

/**
* Update a article
*/
exports.update = function(req, res) {
var article = req.article;

article = _.extend(article, req.body);

article.save(function(err) {
res.jsonp(article);
});
};

/**
* Delete an article
*/
exports.destroy = function(req, res) {
var article = req.article;

article.remove(function(err) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(article);
}
});
};

/**
* Show an article
*/
exports.show = function(req, res) {
res.jsonp(req.article);
};

/**
* List of Eventoss
*/
exports.all = function(req, res) {
Eventos.find().sort('-created').populate('user', 'name username').exec(function(err, articles) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(articles);
}
});
};
10 changes: 10 additions & 0 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ exports.signup = function(req, res) {
});
};

/**
* Show cadastroBeneficiario form
*/
exports.cadastroBeneficiario = function(req, res) {
res.render('users/cadastroBeneficiario', {
title: 'Sign up',
user: new User()
});
};

/**
* Logout
*/
Expand Down
42 changes: 42 additions & 0 deletions app/models/eventos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
config = require('../../config/config'),
Schema = mongoose.Schema;


/**
* Article Schema
*/
var EventosSchema = new Schema({
created: {
type: Date,
default: Date.now
},
name: {
type: String,
default: '',
trim: true
},
locale: {
type: String,
default: '',
trim: true
},
user: {
type: Schema.ObjectId,
ref: 'User'
}
});

/**
* Statics
*/
EventosSchema.statics.load = function(id, cb) {
this.findOne({
_id: id
}).populate('user', 'name username').exec(cb);
};

mongoose.model('Eventos', EventosSchema);
21 changes: 21 additions & 0 deletions app/views/eventos/cadastro.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<section data-ng-controller="EventosController">
<form class="form-horizontal" data-ng-submit="create()">
<div class="control-group">
<label class="control-label" for="title">Nome</label>
<div class="controls">
<input type="text" data-ng-model="name" id="name" placeholder="Nome" required>
</div>
</div>
<div class="control-group">
<label class="control-label" for="content">Local</label>
<div class="controls">
<input type="text" data-ng-model="locale" id="locale" placeholder="Local" required>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" class="btn">
</div>
</div>
</form>
</section>
4 changes: 2 additions & 2 deletions app/views/includes/head.jade
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ head
meta(property='og:type', content='website')
meta(property='og:url', content='APP_URL')
meta(property='og:image', content='APP_LOGO')
meta(property='og:site_name', content='MEAN - A Modern Stack')
meta(property='og:site_name', content='Causas do Bem')
meta(property='fb:admins', content='APP_ADMIN')

link(rel='stylesheet', href='/lib/bootstrap/docs/assets/css/bootstrap.css')
//- link(rel='stylesheet', href='/lib/bootstrap/dist/css/bootstrap-responsive.css')
link(rel='stylesheet', href='/lib/bootstrap/dist/css/bootstrap-responsive.css')
link(rel='stylesheet', href='/css/common.css')

link(rel='stylesheet', href='/css/views/articles.css')
Expand Down
34 changes: 34 additions & 0 deletions app/views/users/cadastro.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
extends auth

block auth
form.signup.form-horizontal(action="/cadastro", method="post")
.control-group
label.control-label(for='name') Nome:
.controls
input#name(type='text', name="name", placeholder='Nome', value=user.name)

.control-group
label.control-label(for='email') Endereço:
.controls
input#email(type='text', name="email", placeholder='Endereço', value=user.email)

.control-group
label.control-label(for='email') E-mail:
.controls
input#username(type='text', name="email", placeholder='E-mail', value=user.email)

.control-group
label.control-label(for='password') Password
.controls
input#password(type='password', name="password", placeholder='Password', value=user.password)

.control-group
label.control-label(for='cpf') CPF
.controls
input#password(type='text', name="cpf", placeholder='CPF', value=user.cpf)

.form-actions
button.btn.btn-primary(type='submit') Sign up
&nbsp;
| or&nbsp;
a.show-login(href="/signin") login
34 changes: 34 additions & 0 deletions app/views/users/cadastroBeneficiario.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
extends auth

block auth
form.signup.form-horizontal(action="/cadastroBeneficiario/create", method="post")
.control-group
label.control-label(for='name') Nome:
.controls
input#name(type='text', name="name", placeholder='Nome', value=user.name)

.control-group
label.control-label(for='email') Endereço:
.controls
input#email(type='text', name="email", placeholder='Endereço', value=user.email)

.control-group
label.control-label(for='email') E-mail:
.controls
input#username(type='text', name="email", placeholder='E-mail', value=user.email)

.control-group
label.control-label(for='password') Password
.controls
input#password(type='password', name="password", placeholder='Password', value=user.password)

.control-group
label.control-label(for='cpf') CPF
.controls
input#password(type='text', name="cpf", placeholder='CPF', value=user.cpf)

.form-actions
button.btn.btn-primary(type='submit') Sign up
&nbsp;
| or&nbsp;
a.show-login(href="/signin") login
14 changes: 14 additions & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module.exports = function(app, passport, auth) {
var users = require('../app/controllers/users');
app.get('/signin', users.signin);
app.get('/signup', users.signup);
app.get('/cadastro-beneficiario', users.cadastroBeneficiario);
app.get('/signout', users.signout);
app.get('/users/me', users.me);

//Setting up the users api
app.post('/users', users.create);
app.post('/cadastroBeneficiario/create', users.create);

//Setting the local strategy route
app.post('/users/session', passport.authenticate('local', {
Expand Down Expand Up @@ -70,6 +72,18 @@ module.exports = function(app, passport, auth) {
//Finish with setting up the articleId param
app.param('articleId', articles.article);

//Eventos Routes
var eventos = require('../app/controllers/eventos');
app.get('/eventos', eventos.all);
app.get('/eventos/cadastro', eventos.cadastro);
app.post('/eventos', auth.requiresLogin, eventos.create);
//app.get('/eventos/:articleId', eventos.show);
//app.put('/eventos/:articleId', auth.requiresLogin, auth.article.hasAuthorization, eventos.update);
//app.del('/eventos/:articleId', auth.requiresLogin, auth.article.hasAuthorization, eventos.destroy);

//Finish with setting up the articleId param
//app.param('articleId', eventos.article);

//Home route
var index = require('../app/controllers/index');
app.get('/', index.render);
Expand Down
3 changes: 3 additions & 0 deletions public/js/controllers/eventos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
angular.module('mean.system').controller('IndexController', ['$scope', 'Global', function ($scope, Global) {
$scope.global = Global;
}]);
21 changes: 21 additions & 0 deletions public/views/eventos/cadastro.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<section data-ng-controller="EventosController">
<form class="form-horizontal" data-ng-submit="create()">
<div class="control-group">
<label class="control-label" for="title">Nome</label>
<div class="controls">
<input type="text" data-ng-model="name" id="name" placeholder="Nome" required>
</div>
</div>
<div class="control-group">
<label class="control-label" for="content">Local</label>
<div class="controls">
<input type="text" data-ng-model="locale" id="locale" placeholder="Local" required>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" class="btn">
</div>
</div>
</form>
</section>
2 changes: 1 addition & 1 deletion public/views/header.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="navbar-inner" data-ng-controller="HeaderController">
<ul class="nav">
<li>
<a class="brand" href="/">MEAN - A Modern Stack</a>
<a class="brand" href="/">Causas do Bem</a>
</li>
<li data-ng-repeat="item in menu" data-ng-show="global.user" ui-route="/{{item.link}}" ng-class="{active: $uiRoute}">
<a href="#!/{{item.link}}">{{item.title}}</a>
Expand Down
19 changes: 16 additions & 3 deletions public/views/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
<section data-ng-controller="IndexController">
<h1>This is the home view</h1>
</section>
<div data-ng-controller="IndexController">
<div class="container">
<h1 class="logo">causasdobem</h1>
<hr>
<div class="jumbotron">
<p>
<a class="btn btn-lg btn-success" href="#">Voluntários</a>
<a class="btn btn-lg btn-success" href="#">Beneficiário</a>
</p>
</div>
<p>
Quero <a href="#" class="btn btn-default">Ajudar!</a> / <a href="#" class="btn btn-default">Ser ajudado!</a>
</p>

</div>
</div>

0 comments on commit c87b01f

Please sign in to comment.