mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
[#1532] add better validation on preferences.dayStart, and a migration to
cleanup corrupt ones
This commit is contained in:
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(){
|
$scope.saveDayStart = function(){
|
||||||
var dayStart = +User.user.preferences.dayStart;
|
var dayStart = +User.user.preferences.dayStart;
|
||||||
if (dayStart < 0 || dayStart > 24) {
|
if (_.isNaN(dayStart) || dayStart < 0 || dayStart > 24) {
|
||||||
dayStart = 0;
|
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;
|
$scope.language = window.env.language;
|
||||||
|
|||||||
@@ -259,6 +259,10 @@ UserSchema.virtual('tasks').get(function () {
|
|||||||
UserSchema.pre('save', function(next) {
|
UserSchema.pre('save', function(next) {
|
||||||
//this.markModified('tasks');
|
//this.markModified('tasks');
|
||||||
|
|
||||||
|
if (_.isNaN(this.preferences.dayStart) || this.preferences.dayStart < 0 || this.preferences.dayStart > 0) {
|
||||||
|
this.preferences.dayStart = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.profile.name) {
|
if (!this.profile.name) {
|
||||||
var fb = this.auth.facebook;
|
var fb = this.auth.facebook;
|
||||||
this.profile.name =
|
this.profile.name =
|
||||||
|
|||||||
Reference in New Issue
Block a user