mirror of
https://github.com/bodyrep/DemoApp.git
synced 2025-12-06 06:01:48 +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({
|
||||
username: {type: String, unique: true, required: true},
|
||||
name: String,
|
||||
email: {type: String, unique: true, required: true},
|
||||
password: String,
|
||||
dob_month: String,
|
||||
dob_year: String,
|
||||
location: String,
|
||||
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'}],
|
||||
exercisestats: [ExerciseStat]
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ $(document).ready(function() {
|
||||
|
||||
//just everything works better when synchro
|
||||
$.ajax({async:false});
|
||||
|
||||
|
||||
jQuery.extend({
|
||||
getValues: function(url) {
|
||||
@@ -208,8 +209,11 @@ $(document).ready(function() {
|
||||
|
||||
$("#Leftpane").delegate("button.map-link", "click",function () {
|
||||
var id = $(this).attr('value');
|
||||
$('div#Rightpane').empty().load(id);
|
||||
$("button").button();
|
||||
$('div#Rightpane').empty().load(id , function(){
|
||||
$("button").button();
|
||||
$( ".buttonset" ).buttonset();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$(document).on('click', '.addthisExercise',(function() {
|
||||
|
||||
@@ -52,6 +52,7 @@ li.floatleft {
|
||||
display: block;
|
||||
float: left;
|
||||
overflow: hidden;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
#userphoto {
|
||||
|
||||
@@ -130,13 +130,9 @@ app.get('/admin/exercises', loggedIn, isAdmin, 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;
|
||||
console.log("Upsert exercise " + JSON.stringify(exercise));
|
||||
var docid = req.body._id;
|
||||
console.log("DOCID " + docid);
|
||||
delete exercise["_id"];
|
||||
console.log("Upsert document " + JSON.stringify(exercise));
|
||||
Exercise.findByIdAndUpdate(docid, exercise, {upsert: false}, function(err) {
|
||||
if (err) {
|
||||
if (err.code === 11000) {
|
||||
|
||||
@@ -48,10 +48,6 @@ module.exports = function(app) {
|
||||
});
|
||||
|
||||
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;
|
||||
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) {
|
||||
|
||||
@@ -3,16 +3,16 @@ h2= user.name
|
||||
User Pictures
|
||||
|
||||
- if (session.user)
|
||||
- if (session.user.name === requested)
|
||||
- if (session.user.username === requested)
|
||||
h2 Private View
|
||||
div
|
||||
button.recent-link(value= encodeURIComponent(session.user.name) ) Recent workouts
|
||||
div
|
||||
button.newex-link(value="/workouts/new") Create new workout
|
||||
div
|
||||
button Placeholder1
|
||||
button.map-link(value="/users/admin/edit") Edit User
|
||||
div
|
||||
button Palceholder2
|
||||
button Placeholder2
|
||||
- else
|
||||
h2 Public View
|
||||
|
||||
|
||||
Reference in New Issue
Block a user