mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
moved UI stuff into the settings area, moved authWithSession to the Auth controller
This commit is contained in:
@@ -31,6 +31,7 @@ window.habitrpg = angular.module('habitrpg',
|
||||
.when('/options/groups/guilds', '/options/groups/guilds/public')
|
||||
.when('/options/inventory', '/options/inventory/inventory')
|
||||
.when('/options/inventory/stable', '/options/inventory/stable/pets')
|
||||
.when('/options/settings', '/options/settings/settings')
|
||||
|
||||
// redirect states that don't match
|
||||
.otherwise("/tasks");
|
||||
@@ -68,10 +69,6 @@ window.habitrpg = angular.module('habitrpg',
|
||||
url: "/profile",
|
||||
templateUrl: "partials/options.profile.profile.html"
|
||||
})
|
||||
.state('options.profile.data', {
|
||||
url: "/profile/data",
|
||||
templateUrl: "partials/options.profile.data.html"
|
||||
})
|
||||
|
||||
// Options > Groups
|
||||
.state('options.social', {
|
||||
@@ -165,6 +162,18 @@ window.habitrpg = angular.module('habitrpg',
|
||||
controller: 'SettingsCtrl',
|
||||
templateUrl: "partials/options.settings.html"
|
||||
})
|
||||
.state('options.settings.settings', {
|
||||
url: "/settings",
|
||||
templateUrl: "partials/options.settings.settings.html"
|
||||
})
|
||||
.state('options.settings.api', {
|
||||
url: "/api",
|
||||
templateUrl: "partials/options.settings.api.html"
|
||||
})
|
||||
.state('options.settings.export', {
|
||||
url: "/export",
|
||||
templateUrl: "partials/options.settings.export.html"
|
||||
})
|
||||
|
||||
// Options > Settings
|
||||
.state('options.admin', {
|
||||
|
||||
@@ -13,6 +13,7 @@ var api = module.exports;
|
||||
|
||||
var NO_TOKEN_OR_UID = { err: "You must include a token and uid (user id) in your request"};
|
||||
var NO_USER_FOUND = {err: "No user found."};
|
||||
var NO_SESSION_FOUND = { err: "You must be logged in." };
|
||||
|
||||
/*
|
||||
beforeEach auth interceptor
|
||||
@@ -40,6 +41,19 @@ api.auth = function(req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
api.authWithSession = function(req, res, next) { //[todo] there is probably a more elegant way of doing this...
|
||||
var uid;
|
||||
uid = req.session.userId;
|
||||
if (!(req.session && req.session.userId)) {
|
||||
return res.json(401, NO_SESSION_FOUND);
|
||||
}
|
||||
return User.findOne({_id: uid,}, function(err, user) {
|
||||
if (err) return res.json(500, {err: err});
|
||||
if (_.isEmpty(user)) return res.json(401, NO_USER_FOUND);
|
||||
res.locals.user = user;
|
||||
return next();
|
||||
});
|
||||
};
|
||||
|
||||
api.registerUser = function(req, res, next) {
|
||||
var confirmPassword, e, email, password, username, _ref;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
var _ = require('lodash');
|
||||
var csv = require('express-csv');
|
||||
var User = require('../models/user').model;
|
||||
var nconf = require('nconf');
|
||||
var moment = require('moment');
|
||||
var dataexport = module.exports;
|
||||
@@ -26,26 +25,3 @@ dataexport.history = function(req, res) {
|
||||
});
|
||||
return res.csv(output);
|
||||
}
|
||||
|
||||
dataexport.auth = function(req, res, next) { //[todo] there is probably a more elegant way of doing this...
|
||||
var uid;
|
||||
uid = req.session.userId;
|
||||
if (!(req.session && req.session.userId)) {
|
||||
return res.json(401, "You must be logged in.");
|
||||
}
|
||||
return User.findOne({
|
||||
_id: uid,
|
||||
}, function(err, user) {
|
||||
if (err) {
|
||||
return res.json(500, {
|
||||
err: err
|
||||
});
|
||||
}
|
||||
if (_.isEmpty(user)) {
|
||||
return res.json(401, "No user found.");
|
||||
}
|
||||
|
||||
res.locals.user = user;
|
||||
return next();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
var express = require('express');
|
||||
var router = new express.Router();
|
||||
var dataexport = require('../controllers/dataexport');
|
||||
var auth = require('../controllers/auth');
|
||||
var nconf = require('nconf');
|
||||
|
||||
/* Data export */
|
||||
router.get('/history.csv',dataexport.auth,dataexport.history); //[todo] encode data output options in the data controller and use these to build routes
|
||||
router.get('/history.csv',auth.authWithSession,dataexport.history); //[todo] encode data output options in the data controller and use these to build routes
|
||||
|
||||
module.exports = router;
|
||||
@@ -105,9 +105,6 @@ script(id='partials/options.profile.profile.html', type='text/ng-template')
|
||||
textarea.option-content(style='height:15em;', placeholder='Blurb', ng-model='editingProfile.blurb')
|
||||
include ../shared/formatting-help
|
||||
|
||||
script(id='partials/options.profile.data.html', type="text/ng-template")
|
||||
a(href="/export/history.csv") Export History (CSV)
|
||||
|
||||
script(id='partials/options.profile.html', type="text/ng-template")
|
||||
ul.nav.nav-tabs
|
||||
li(ng-class="{ active: $state.includes('options.profile.avatar') }")
|
||||
@@ -119,9 +116,6 @@ script(id='partials/options.profile.html', type="text/ng-template")
|
||||
li(ng-class="{ active: $state.includes('options.profile.profile') }")
|
||||
a(ui-sref='options.profile.profile')
|
||||
| Profile
|
||||
li(ng-class="{ active: $state.includes('options.profile.data') }")
|
||||
a(ui-sref='options.profile.data')
|
||||
| My Data
|
||||
|
||||
.tab-content
|
||||
.tab-pane.active
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
script(type='text/ng-template', id='partials/options.settings.html')
|
||||
script(id='partials/options.settings.html', type="text/ng-template")
|
||||
ul.nav.nav-tabs
|
||||
li(ng-class="{ active: $state.includes('options.settings.settings') }")
|
||||
a(ui-sref='options.settings.settings')
|
||||
| Settings
|
||||
li(ng-class="{ active: $state.includes('options.settings.api') }")
|
||||
a(ui-sref='options.settings.api')
|
||||
| API
|
||||
li(ng-class="{ active: $state.includes('options.settings.export') }")
|
||||
a(ui-sref='options.settings.export')
|
||||
| Data Export
|
||||
|
||||
.tab-content
|
||||
.tab-pane.active
|
||||
div(ui-view)
|
||||
|
||||
script(type='text/ng-template', id='partials/options.settings.settings.html')
|
||||
.row-fluid
|
||||
.personal-options.span6.border-right
|
||||
.personal-options.span6
|
||||
h2 Settings
|
||||
h4 Custom Day Start
|
||||
.option-group.option-short
|
||||
@@ -36,6 +52,9 @@ script(type='text/ng-template', id='partials/options.settings.html')
|
||||
a.btn.btn-danger(ng-click='modals.reset = true', tooltip='Resets your entire account (dangerous).') Reset
|
||||
a.btn.btn-danger(ng-click='modals.restore = true', tooltip='Restores attributes to your character.') Restore
|
||||
a.btn.btn-danger(ng-click='modals.delete = true', tooltip='Delete your account.') Delete
|
||||
|
||||
script(type='text/ng-template', id='partials/options.settings.api.html')
|
||||
.row.fluid
|
||||
.span6
|
||||
h2 API
|
||||
small Copy these for use in third party applications.
|
||||
@@ -45,3 +64,11 @@ script(type='text/ng-template', id='partials/options.settings.html')
|
||||
pre.prettyprint {{user.apiToken}}
|
||||
h6 QR Code
|
||||
img(src='https://chart.googleapis.com/chart?cht=qr&chs=200x200&chl=%7Baddress%3A%22https%3A%2F%2Fhabitrpg.com%22%2Cuser%3A%22{{user.id}}%22%2Ckey%3A%22{{user.apiToken}}%22%7D,&choe=UTF-8&chld=L', alt='qrcode')
|
||||
|
||||
script(id='partials/options.settings.export.html', type="text/ng-template")
|
||||
.row.fluid
|
||||
.span6
|
||||
h2 Data Export
|
||||
small Here are a few options for saving your Habit data.
|
||||
h4 Habit History
|
||||
a(href="/export/history.csv") Export History (CSV)
|
||||
|
||||
Reference in New Issue
Block a user