mirror of
https://github.com/bodyrep/DemoApp.git
synced 2026-02-06 04:22:12 +00:00
started adding more user flags, added user editing screen
This commit is contained in:
@@ -11,9 +11,16 @@ var ExerciseStat = new Schema({
|
|||||||
var UserSchema = new mongoose.Schema({
|
var UserSchema = new mongoose.Schema({
|
||||||
username: {type: String, unique: true, required: true},
|
username: {type: String, unique: true, required: true},
|
||||||
name: String,
|
name: String,
|
||||||
|
email: {type: String, unique: true, required: true},
|
||||||
password: String,
|
password: String,
|
||||||
|
dob_month: String,
|
||||||
|
dob_year: String,
|
||||||
|
location: String,
|
||||||
is_admin: {type: Boolean, 'default': false },
|
is_admin: {type: Boolean, 'default': false },
|
||||||
is_imperial: {type: Boolean, 'default': false },
|
gender: {type: Number, 'default': 1, min: 0 , max: 1 },
|
||||||
|
units_weight: {type: Number, 'default': 1, min: 0 , max: 1},
|
||||||
|
units_distance: {type: Number, 'default': 1, min: 0 , max: 1},
|
||||||
|
units_energy: {type: Number, 'default': 1, min: 0 , max: 1},
|
||||||
favorites: [{ type: Schema.ObjectId, ref: 'Exercises'}],
|
favorites: [{ type: Schema.ObjectId, ref: 'Exercises'}],
|
||||||
exercisestats: [ExerciseStat]
|
exercisestats: [ExerciseStat]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
//just everything works better when synchro
|
//just everything works better when synchro
|
||||||
$.ajax({async:false});
|
$.ajax({async:false});
|
||||||
|
|
||||||
|
|
||||||
jQuery.extend({
|
jQuery.extend({
|
||||||
getValues: function(url) {
|
getValues: function(url) {
|
||||||
@@ -208,8 +209,11 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
$("#Leftpane").delegate("button.map-link", "click",function () {
|
$("#Leftpane").delegate("button.map-link", "click",function () {
|
||||||
var id = $(this).attr('value');
|
var id = $(this).attr('value');
|
||||||
$('div#Rightpane').empty().load(id);
|
$('div#Rightpane').empty().load(id , function(){
|
||||||
$("button").button();
|
$("button").button();
|
||||||
|
$( ".buttonset" ).buttonset();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', '.addthisExercise',(function() {
|
$(document).on('click', '.addthisExercise',(function() {
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ li.floatleft {
|
|||||||
display: block;
|
display: block;
|
||||||
float: left;
|
float: left;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
width: 80%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#userphoto {
|
#userphoto {
|
||||||
|
|||||||
@@ -130,13 +130,9 @@ app.get('/admin/exercises', loggedIn, isAdmin, function(req, res, next){
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.post('/admin/exercises/:_id', function(req, res, next){
|
app.post('/admin/exercises/:_id', function(req, res, next){
|
||||||
console.log("Upsert data " + JSON.stringify(req.body));
|
|
||||||
var exercise = req.body;
|
var exercise = req.body;
|
||||||
console.log("Upsert exercise " + JSON.stringify(exercise));
|
|
||||||
var docid = req.body._id;
|
var docid = req.body._id;
|
||||||
console.log("DOCID " + docid);
|
|
||||||
delete exercise["_id"];
|
delete exercise["_id"];
|
||||||
console.log("Upsert document " + JSON.stringify(exercise));
|
|
||||||
Exercise.findByIdAndUpdate(docid, exercise, {upsert: false}, function(err) {
|
Exercise.findByIdAndUpdate(docid, exercise, {upsert: false}, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err.code === 11000) {
|
if (err.code === 11000) {
|
||||||
|
|||||||
@@ -48,10 +48,6 @@ module.exports = function(app) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/users/:name', loadUser, function(req, res, next){
|
app.get('/users/:name', loadUser, function(req, res, next){
|
||||||
// req.user.recentworkouts(function(err, workouts) {
|
|
||||||
// if (err) {
|
|
||||||
// return next(err);
|
|
||||||
// }
|
|
||||||
|
|
||||||
var page = req.query.page && parseInt(req.query.page, 10) || 0;
|
var page = req.query.page && parseInt(req.query.page, 10) || 0;
|
||||||
async.parallel([
|
async.parallel([
|
||||||
@@ -101,6 +97,37 @@ module.exports = function(app) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/users/:name/edit', loadUser, function(req, res, next){
|
||||||
|
res.render('users/edit', {
|
||||||
|
user: req.user,
|
||||||
|
requested: req.params.name
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
app.post('/users/:name/edit', function(req, res, next){
|
||||||
|
console.log("Upsert data " + JSON.stringify(req.body));
|
||||||
|
var user = req.body;
|
||||||
|
var docid = req.body._id;
|
||||||
|
delete user["_id"];
|
||||||
|
User.findByIdAndUpdate(docid, user, {upsert: true}, function(err) {
|
||||||
|
if (err) {
|
||||||
|
if (err.code === 11000) {
|
||||||
|
res.send('Conflict', 409);
|
||||||
|
} else {
|
||||||
|
if (err.name === 'ValidationError') {
|
||||||
|
return res.send(Object.keys(err.errors).map(function(errField) {
|
||||||
|
return err.errors[errField].message;
|
||||||
|
}).join('. '), 406);
|
||||||
|
} else {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.redirect('/users/' + req.body.username );
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
app.post('/users', notLoggedIn, function(req, res, next) {
|
app.post('/users', notLoggedIn, function(req, res, next) {
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ h2= user.name
|
|||||||
User Pictures
|
User Pictures
|
||||||
|
|
||||||
- if (session.user)
|
- if (session.user)
|
||||||
- if (session.user.name === requested)
|
- if (session.user.username === requested)
|
||||||
h2 Private View
|
h2 Private View
|
||||||
div
|
div
|
||||||
button.recent-link(value= encodeURIComponent(session.user.name) ) Recent workouts
|
button.recent-link(value= encodeURIComponent(session.user.name) ) Recent workouts
|
||||||
div
|
div
|
||||||
button.newex-link(value="/workouts/new") Create new workout
|
button.newex-link(value="/workouts/new") Create new workout
|
||||||
div
|
div
|
||||||
button Placeholder1
|
button.map-link(value="/users/admin/edit") Edit User
|
||||||
div
|
div
|
||||||
button Palceholder2
|
button Placeholder2
|
||||||
- else
|
- else
|
||||||
h2 Public View
|
h2 Public View
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user