Add reset progress option to user settings
This commit is contained in:
@ -258,6 +258,15 @@ export class Settings extends React.Component {
|
|||||||
>
|
>
|
||||||
Delete my Free Code Camp account
|
Delete my Free Code Camp account
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
block={ true }
|
||||||
|
bsSize='lg'
|
||||||
|
bsStyle='danger'
|
||||||
|
className='btn-link-social'
|
||||||
|
href='/reset-my-progress'
|
||||||
|
>
|
||||||
|
Reset all of my progress and brownie points
|
||||||
|
</Button>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
@ -183,6 +183,16 @@ module.exports = function(app) {
|
|||||||
sendNonUserToMap,
|
sendNonUserToMap,
|
||||||
getAccount
|
getAccount
|
||||||
);
|
);
|
||||||
|
router.get(
|
||||||
|
'/reset-my-progress',
|
||||||
|
sendNonUserToMap,
|
||||||
|
showResetProgress
|
||||||
|
);
|
||||||
|
api.post(
|
||||||
|
'/account/resetprogress',
|
||||||
|
ifNoUser401,
|
||||||
|
postResetProgress
|
||||||
|
);
|
||||||
|
|
||||||
// Ensure these are the last routes!
|
// Ensure these are the last routes!
|
||||||
api.get(
|
api.get(
|
||||||
@ -450,6 +460,35 @@ module.exports = function(app) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showResetProgress(req, res) {
|
||||||
|
return res.render('account/reset-progress', { title: 'Reset My Progress!'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function postResetProgress(req, res, next) {
|
||||||
|
User.findById(req.user.id, function(err, user) {
|
||||||
|
if (err) { return next(err); }
|
||||||
|
return user.updateAttributes({
|
||||||
|
progressTimestamps: [{
|
||||||
|
timestamp: Date.now()
|
||||||
|
}],
|
||||||
|
currentStreak: 0,
|
||||||
|
longestStreak: 0,
|
||||||
|
currentChallengeId: '',
|
||||||
|
isBackEndCert: false,
|
||||||
|
isFullStackCert: false,
|
||||||
|
isDataVisCert: false,
|
||||||
|
isFrontEndCert: false,
|
||||||
|
challengeMap: {},
|
||||||
|
challegesCompleted: []
|
||||||
|
}, function(err) {
|
||||||
|
if (err) { return next(err); }
|
||||||
|
req.flash('info', { msg: 'You\'ve successfully reset your progress.' });
|
||||||
|
return res.redirect('/');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getReset(req, res) {
|
function getReset(req, res) {
|
||||||
if (!req.accessToken) {
|
if (!req.accessToken) {
|
||||||
req.flash('errors', { msg: 'access token invalid' });
|
req.flash('errors', { msg: 'access token invalid' });
|
||||||
|
25
server/views/account/reset-progress.jade
Normal file
25
server/views/account/reset-progress.jade
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
extends ../layout
|
||||||
|
block content
|
||||||
|
include ../partials/flyer
|
||||||
|
#modal-dialog.modal.animated.wobble
|
||||||
|
.modal-dialog
|
||||||
|
.modal-content
|
||||||
|
.modal-header
|
||||||
|
a.close(href='/settings', data-dismiss='modal', aria-hidden='true') ×
|
||||||
|
h3 You don't really want to reset your progress, do you?
|
||||||
|
.modal-body
|
||||||
|
p This will really delete all of your progress and brownie points.
|
||||||
|
p We won't be able to recover any of it for you later, even if you change your mind.
|
||||||
|
.modal-footer
|
||||||
|
a.btn.btn-success.btn-block(href='/settings', data-dismiss='modal', aria-hidden='true')
|
||||||
|
| Nevermind, I don't want to delete all of my progress and brownie points
|
||||||
|
.spacer
|
||||||
|
form(action='/account/resetprogress', method='POST')
|
||||||
|
input(type='hidden', name='_csrf', value=_csrf)
|
||||||
|
button.btn.btn-danger.btn-block(type='submit')
|
||||||
|
| I am 100% sure I want to reset all of my progress and brownie points
|
||||||
|
script.
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const modal$ = document.getElementById('modal-dialog');
|
||||||
|
modal$.classList.add('show');
|
||||||
|
});
|
Reference in New Issue
Block a user