mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 19:47:03 +00:00
[#1532] add better validation on preferences.dayStart, and a migration to
cleanup corrupt ones
This commit is contained in:
parent
a4fb0b42ad
commit
2b128f71f4
3 changed files with 12 additions and 2 deletions
5
migrations/20131126_clean_dayStart.js
Normal file
5
migrations/20131126_clean_dayStart.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
db.users.find({'preferences.dayStart':{$exists:1}},{'preferences.dayStart':1}).forEach(function(user){
|
||||
var dayStart = +user.preferences.dayStart;
|
||||
dayStart = (_.isNaN(dayStart) || dayStart < 0 || dayStart > 24) ? 0 : dayStart;
|
||||
db.users.update({_id:user._id}, {$set:{'preferences.dayStart':dayStart}});
|
||||
});
|
||||
|
|
@ -27,10 +27,11 @@ habitrpg.controller('SettingsCtrl',
|
|||
|
||||
$scope.saveDayStart = function(){
|
||||
var dayStart = +User.user.preferences.dayStart;
|
||||
if (dayStart < 0 || dayStart > 24) {
|
||||
if (_.isNaN(dayStart) || dayStart < 0 || dayStart > 24) {
|
||||
dayStart = 0;
|
||||
return alert('Please enter a number between 0 and 24');
|
||||
}
|
||||
User.log({'op':'set', data:{'preferences.dayStart': dayStart}});
|
||||
User.set('preferences.dayStart', dayStart);
|
||||
}
|
||||
|
||||
$scope.language = window.env.language;
|
||||
|
|
|
|||
|
|
@ -259,6 +259,10 @@ UserSchema.virtual('tasks').get(function () {
|
|||
UserSchema.pre('save', function(next) {
|
||||
//this.markModified('tasks');
|
||||
|
||||
if (_.isNaN(this.preferences.dayStart) || this.preferences.dayStart < 0 || this.preferences.dayStart > 0) {
|
||||
this.preferences.dayStart = 0;
|
||||
}
|
||||
|
||||
if (!this.profile.name) {
|
||||
var fb = this.auth.facebook;
|
||||
this.profile.name =
|
||||
|
|
|
|||
Loading…
Reference in a new issue