mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-05-20 20:58:42 +00:00
[#1477] add reset account
This commit is contained in:
parent
5e51148f8e
commit
f250a98fb7
5 changed files with 38 additions and 136 deletions
|
|
@ -1,67 +1,6 @@
|
|||
helpers = require 'habitrpg-shared/script/helpers'
|
||||
algos = require 'habitrpg-shared/script/algos'
|
||||
browser = require './browser'
|
||||
items = require './items'
|
||||
misc = require './misc'
|
||||
_ = require 'lodash'
|
||||
|
||||
module.exports.app = (appExports, model) ->
|
||||
user = model.at('_user')
|
||||
|
||||
appExports.revive = ->
|
||||
[uObj, paths] = [user.get(), {}]
|
||||
algos.revive(uObj, {paths})
|
||||
_.each paths, ((v,k) -> user.set k, helpers.dotGet(k, uObj))
|
||||
|
||||
appExports.reset = (e, el) ->
|
||||
misc.batchTxn model, (uObj, paths, batch) ->
|
||||
batch.set 'tasks', {}
|
||||
['habit', 'daily', 'todo', 'reward'].forEach (type) -> batch.set("#{type}Ids", [])
|
||||
_.each {hp:50, lvl:1, gp:0, exp:0}, (v,k) -> batch.set("stats.#{k}",v)
|
||||
_.each {armor:0, weapon:0, head:0, shield:0}, (v,k) -> batch.set("items.#{k}",v)
|
||||
browser.resetDom(model)
|
||||
|
||||
appExports.closeNewStuff = (e, el) ->
|
||||
user.set('flags.newStuff', 'hide')
|
||||
|
||||
appExports.customizeGender = (e, el) ->
|
||||
user.set 'preferences.gender', $(el).attr('data-value')
|
||||
|
||||
appExports.customizeHair = (e, el) ->
|
||||
user.set 'preferences.hair', $(el).attr('data-value')
|
||||
|
||||
appExports.customizeSkin = (e, el) ->
|
||||
user.set 'preferences.skin', $(el).attr('data-value')
|
||||
|
||||
appExports.customizeArmorSet = (e, el) ->
|
||||
user.set 'preferences.armorSet', $(el).attr('data-value')
|
||||
|
||||
appExports.restoreSave = ->
|
||||
misc.batchTxn model, (uObj, paths, batch) ->
|
||||
$('#restore-form input').each ->
|
||||
[path, val] = [$(this).attr('data-for'), parseInt($(this).val() || 1)]
|
||||
batch.set(path,val)
|
||||
|
||||
appExports.toggleHeader = (e, el) ->
|
||||
user.set 'preferences.hideHeader', !user.get('preferences.hideHeader')
|
||||
|
||||
appExports.deleteAccount = (e, el) ->
|
||||
model.del "users.#{user.get('id')}", ->
|
||||
location.href = "/logout"
|
||||
|
||||
appExports.profileAddWebsite = (e, el) ->
|
||||
newWebsite = model.get('_newProfileWebsite')
|
||||
return if /^(\s)*$/.test(newWebsite)
|
||||
user.unshift 'profile.websites', newWebsite
|
||||
model.set '_newProfileWebsite', ''
|
||||
|
||||
appExports.profileEdit = (e, el) -> model.set '_profileEditing', true
|
||||
appExports.profileSave = (e, el) -> model.set '_profileEditing', false
|
||||
appExports.profileRemoveWebsite = (e, el) ->
|
||||
sites = user.get 'profile.websites'
|
||||
i = sites.indexOf $(el).attr('data-website')
|
||||
sites.splice(i,1)
|
||||
user.set 'profile.websites', sites
|
||||
|
||||
appExports.toggleResting = ->
|
||||
model.set '_user.flags.rest', !model.get('_user.flags.rest')
|
||||
|
|
|
|||
|
|
@ -64,6 +64,16 @@ habitrpg.controller('SettingsCtrl',
|
|||
});
|
||||
$rootScope.modals.restore = false;
|
||||
}
|
||||
|
||||
$scope.reset = function(){
|
||||
$http.post(API_URL + '/api/v1/user/reset')
|
||||
.success(function(){
|
||||
User.user._v--;
|
||||
User.log({});
|
||||
$rootScope.modals.reset = false;
|
||||
})
|
||||
.error(function(data){
|
||||
alert(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -533,6 +533,31 @@ api.reroll = function(req, res, next) {
|
|||
});
|
||||
};
|
||||
|
||||
api.reset = function(req, res){
|
||||
var user = res.locals.user;
|
||||
user.tasks = {};
|
||||
|
||||
_.each(['habit', 'daily', 'todo', 'reward'], function(type) {
|
||||
user[type + "Ids"] = [];
|
||||
});
|
||||
|
||||
user.stats.hp = 50;
|
||||
user.stats.lvl = 1;
|
||||
user.stats.gp = 0;
|
||||
user.stats.exp = 0;
|
||||
|
||||
user.items.armor = 0;
|
||||
user.items.weapon = 0;
|
||||
user.items.head = 0;
|
||||
user.items.shield = 0;
|
||||
|
||||
user.save(function(err, saved){
|
||||
if (err) return res.json(500,{err:err});
|
||||
res.json(saved);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Setup Stripe response when posting payment
|
||||
|
|
@ -562,79 +587,6 @@ api.buyGems = function(req, res) {
|
|||
});
|
||||
};
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------
|
||||
Party
|
||||
------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
api.getGroups = function(req, res, next) {
|
||||
var user = res.locals.user;
|
||||
/*TODO should we support non-authenticated users? just for viewing public groups?*/
|
||||
|
||||
return async.parallel({
|
||||
party: function(cb) {
|
||||
return async.waterfall([
|
||||
function(cb2) {
|
||||
return Group.findOne({
|
||||
type: 'party',
|
||||
members: {
|
||||
'$in': [user._id]
|
||||
}
|
||||
}, cb2);
|
||||
}, function(party, cb2) {
|
||||
var fields, query;
|
||||
party = party.toJSON();
|
||||
query = {
|
||||
_id: {
|
||||
'$in': party.members,
|
||||
'$nin': [user._id]
|
||||
}
|
||||
};
|
||||
fields = 'profile preferences items stats achievements party backer auth.local.username auth.facebook.first_name auth.facebook.last_name auth.facebook.name auth.facebook.username'.split(' ');
|
||||
fields = _.reduce(fields, (function(m, k, v) {
|
||||
m[k] = 1;
|
||||
return m;
|
||||
}), {});
|
||||
return User.find(query, fields, function(err, members) {
|
||||
party.members = members;
|
||||
return cb2(err, party);
|
||||
});
|
||||
}
|
||||
], function(err, members) {
|
||||
return cb(err, members);
|
||||
});
|
||||
},
|
||||
guilds: function(cb) {
|
||||
return cb(null, {});
|
||||
return Group.findOne({
|
||||
type: 'guild',
|
||||
members: {
|
||||
'$in': [user._id]
|
||||
}
|
||||
}, cb);
|
||||
},
|
||||
"public": function(cb) {
|
||||
return cb(null, {});
|
||||
return Group.find({
|
||||
privacy: 'public'
|
||||
}, {
|
||||
name: 1,
|
||||
description: 1,
|
||||
members: 1
|
||||
}, cb);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return res.json(500, {
|
||||
err: err
|
||||
});
|
||||
}
|
||||
return res.json(results);
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------
|
||||
Batch Update
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ router.post('/user/revive', auth.auth, cron, user.revive);
|
|||
router.post('/user/batch-update', auth.auth, cron, user.batchUpdate);
|
||||
router.post('/user/reroll', auth.auth, cron, user.reroll);
|
||||
router.post('/user/buy-gems', auth.auth, user.buyGems);
|
||||
router.post('/user/reset', auth.auth, user.reset);
|
||||
|
||||
/* Groups*/
|
||||
router.get('/groups', auth.auth, groups.getGroups);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ div(ng-controller='SettingsCtrl')
|
|||
p This is highly discouraged because you'll lose historical data, which is useful for graphing your progress over time. However, some people find it useful in the beginning after playing with the app for a while.
|
||||
.modal-footer
|
||||
button.btn.btn-default.cancel(ng-click='modals.reset = false') Close
|
||||
button.btn.btn-danger(data-dismiss='modal', ng-click='notPorted()') Reset
|
||||
button.btn.btn-danger(data-dismiss='modal', ng-click='reset()') Reset
|
||||
|
||||
div(modal='modals.restore')
|
||||
.modal-header
|
||||
|
|
|
|||
Loading…
Reference in a new issue