diff options
| -rw-r--r-- | routes/user.js | 51 | ||||
| -rw-r--r-- | views/add_solutions.hbs | 7 | ||||
| -rw-r--r-- | views/layouts/layout.hbs | 2 | ||||
| -rw-r--r-- | views/user_profile_alt.hbs | 24 |
4 files changed, 49 insertions, 35 deletions
diff --git a/routes/user.js b/routes/user.js index cfa3a79..c558d5f 100644 --- a/routes/user.js +++ b/routes/user.js @@ -182,7 +182,7 @@ router.get('/signin', loggedOut, function (req, res, next) { }); router.get('/verify', function(req, res, next) { - res.render('verification', {noHeader: true}); + res.render('verification', {noHeader: true, noFooter: true}); }); router.post('/signup', loggedOut, function(req, res, next) { req.assert('fname', 'Please enter a valid first name.').notEmpty().withMessage('First name required.').isAlpha(); @@ -239,9 +239,10 @@ router.post('/user_profile/send_message', loggedIn, function(req, res, next) { if (req.user.user_name === req.body.receiver_username) { req.session.messages = {error : 'You cannot send a message to yourself.'}; res.redirect('/user/user_profile/'); - } - - else { + } else if (!req.body.message){ + req.session.messages = {error: 'You cannot send an empty message.'}; + res.redirect('/user/user_profile/'); + } else { var date = new Date(); var current_date = date.toString().slice(0, 24); var subject = req.body.subject; @@ -292,24 +293,32 @@ router.post('/submit_solution/:examID/:qID', function(req,res){ var examID = req.params.examID; var qID = req.params.qID; - var text = req.body.solution, - votes = 0, - comments = [], - author = req.user.user_name; - - var fields = [examID, qID, text, author]; - console.log(fields); - // Add to database - dbFile.add_solution(fields, function(addedSolution, statusMsg){ - if(addedSolution){ - req.session.messages = {success : statusMsg}; - }else{ - req.session.messages = {error : statusMsg}; - } - //Redirect to solutions page again - res.redirect('/solutions/' + examID + '/' + qID); + if (!req.body.solution) { + req.session.messages = {error: 'You cannot submit an empty solution.'}; + res.redirect('/user/add_solution/' + examID + '/' + qID); + } else { + var text = req.body.solution, + votes = 0, + comments = [], + author = req.user.user_name; + + var fields = [examID, qID, text, author]; + console.log(fields); + // Add to database + dbFile.add_solution(fields, function(addedSolution, statusMsg){ + if(addedSolution){ + req.session.messages = {success : statusMsg}; + }else{ + req.session.messages = {error : statusMsg}; + } + //Redirect to solutions page again + res.redirect('/solutions/' + examID + '/' + qID); + + }); + } + + - }); }); diff --git a/views/add_solutions.hbs b/views/add_solutions.hbs index 2865a88..fe90408 100644 --- a/views/add_solutions.hbs +++ b/views/add_solutions.hbs @@ -3,10 +3,15 @@ <div class="row" id="solutions-main"> <div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3"> + {{# if messages.error }} + <section class="alert alert-danger custom-Alert"> + <h4>{{ messages.error }}</h4> + </section> + {{/if}} <h3><i class="fa fa-wpforms" aria-hidden="true"></i> Add Solution </h3> <form action="/user/submit_solution/{{examID}}/{{qID}}" method="post"> <div class="form-group"> - <input type="text" class="form-control" placeholder="Enter Solution" name="solution"> + <textarea class="form-control" placeholder="Enter solution here..." rows="5" name="solution"></textarea> </div> <input type="hidden" name="_csrf" value="{{ csrfToken }}"> <button class="btn btn-primary">Submit</button> diff --git a/views/layouts/layout.hbs b/views/layouts/layout.hbs index aecff1d..8ffbdb5 100644 --- a/views/layouts/layout.hbs +++ b/views/layouts/layout.hbs @@ -45,7 +45,7 @@ {{/if}} {{{ body }}} - {{# if noHeader}} + {{# if noFooter}} {{else}} {{> footer }} {{/if}} diff --git a/views/user_profile_alt.hbs b/views/user_profile_alt.hbs index cf657db..a193062 100644 --- a/views/user_profile_alt.hbs +++ b/views/user_profile_alt.hbs @@ -44,6 +44,18 @@ class="img-circle img-responsive"> </div> --> <!-- User Details --> + {{# if messages.success }} + <section class="alert alert-success"> + <!-- Change those to banners later --> + <h3>{{ messages.success }}</h3> + </section> + {{ else }} + {{# if messages.error }} + <section class="alert alert-danger"> + <h3>{{ messages.error }}</h3> + </section> + {{/if}} + {{/if}} <div> <table class="table table-user-information"> <tbody> @@ -157,18 +169,6 @@ </div> --> <div class="row" id="profile-send-message"> - {{# if messages.success }} - <section class="alert alert-success"> - <!-- Change those to banners later --> - <h3>{{ messages.success }}</h3> - </section> - {{ else }} - {{# if messages.error }} - <section class="alert alert-danger"> - <h3>{{ messages.error }}</h3> - </section> - {{/if}} - {{/if}} <h3>Send Message</h3> <div class="col-xs-offset-1 col-sm-offset-3 col-xs-10 col-sm-6"> |
