Skip to content

Commit 7793beb

Browse files
committed
Deprecate some routes
* Normalize on `/login`... keep `register` to ourselves in the code... we already do this a lot... think `index.js` vs `main`. * Removed one dead route... why would we want to do `/github` to `/`... means to me that it's dead... just return a default 404. * Fixed one doc send with status 302 to redirect instead... default is 302 ... would use a 307 but that's only HTTP/1.1 and would definitely rule out any older browser although may be reconsidered at a later date * Some white space treatment Applies to OpenUserJS#1198 OpenUserJS#135 and post OpenUserJS#1174
1 parent b54f20a commit 7793beb

5 files changed

Lines changed: 21 additions & 17 deletions

File tree

controllers/auth.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ exports.auth = function (aReq, aRes, aNext) {
9494
var strategy = aReq.body.auth || aReq.params.strategy;
9595
var username = aReq.body.username || aReq.session.username ||
9696
(authedUser ? authedUser.name : null);
97-
var authOpts = { failureRedirect: '/register?stratfail' };
97+
var authOpts = { failureRedirect: '/login?stratfail' };
9898
var passportKey = aReq._passport.instance._key;
9999

100100
// Yet another passport hack.
@@ -118,7 +118,7 @@ exports.auth = function (aReq, aRes, aNext) {
118118
}
119119

120120
if (!username) {
121-
aRes.redirect('/register?noname');
121+
aRes.redirect('/login?noname');
122122
return;
123123
}
124124
// Clean the username of leading and trailing whitespace,
@@ -127,7 +127,7 @@ exports.auth = function (aReq, aRes, aNext) {
127127

128128
// The username could be empty after the replacements
129129
if (!username) {
130-
aRes.redirect('/register?noname');
130+
aRes.redirect('/login?noname');
131131
return;
132132
}
133133

@@ -164,7 +164,7 @@ exports.auth = function (aReq, aRes, aNext) {
164164
}
165165

166166
if (!strategy) {
167-
aRes.redirect('/register');
167+
aRes.redirect('/login');
168168
return;
169169
} else {
170170
auth();
@@ -243,7 +243,7 @@ exports.callback = function (aReq, aRes, aNext) {
243243
console.error(colors.red('`User` not found'));
244244
}
245245

246-
aRes.redirect(doneUri + (doneUri === '/' ? 'register' : '') + '?authfail');
246+
aRes.redirect(doneUri + (doneUri === '/' ? 'login' : '') + '?authfail');
247247
return;
248248
}
249249

@@ -296,8 +296,7 @@ exports.callback = function (aReq, aRes, aNext) {
296296

297297
exports.validateUser = function validateUser(aReq, aRes, aNext) {
298298
if (!aReq.session.user) {
299-
aRes.location('/login');
300-
aRes.status(302).send();
299+
aRes.redirect('/login');
301300
return;
302301
}
303302
aNext();

controllers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ exports.register = function (aReq, aRes) {
243243
options.redirectTo = getRedirect(aReq);
244244

245245
// Page metadata
246-
pageMetadata(options, 'Register');
246+
pageMetadata(options, 'Login');
247247

248248
// Session
249249
options.authedUser = authedUser = modelParser.parseUser(authedUser);

routes.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ module.exports = function (aApp) {
3131
aApp.route('/auth/:strategy').get(authentication.auth);
3232
aApp.route('/auth/:strategy/callback/:junk?').get(authentication.callback);
3333
aApp.route('/login').get(main.register);
34-
aApp.route('/register').get(main.register);
34+
aApp.route('/register').get(function (aReq, aRes) {
35+
aRes.redirect(301, '/login');
36+
});
3537
aApp.route('/logout').get(main.logout);
3638

3739
// User routes
@@ -45,7 +47,9 @@ module.exports = function (aApp) {
4547
aApp.route('/users/:username/profile/edit').get(authentication.validateUser, user.userEditProfilePage).post(authentication.validateUser, user.update);
4648
aApp.route('/users/:username/update').post(admin.adminUserUpdate);
4749
aApp.route('/user/preferences').get(authentication.validateUser, user.userEditPreferencesPage);
48-
aApp.route('/user').get(function (aReq, aRes) { aRes.redirect('/users'); });
50+
aApp.route('/user').get(function (aReq, aRes) {
51+
aRes.redirect(301, '/users');
52+
});
4953
aApp.route('/api/user/exist/:username').head(user.exist);
5054

5155
// Adding script/library routes
@@ -55,14 +59,16 @@ module.exports = function (aApp) {
5559
aApp.route('/user/add/lib').get(authentication.validateUser, user.newLibraryPage);
5660
aApp.route('/user/add/lib/new').get(script.new(script.lib(user.editScript))).post(authentication.validateUser, script.new(script.lib(user.submitSource)));
5761
aApp.route('/user/add/lib/upload').post(authentication.validateUser, script.lib(user.uploadScript));
58-
aApp.route('/user/add').get(function (aReq, aRes) { aRes.redirect('/user/add/scripts'); });
62+
aApp.route('/user/add').get(function (aReq, aRes) {
63+
aRes.redirect(301, '/user/add/scripts');
64+
});
5965

6066
// Script routes
6167
aApp.route('/scripts/:username/:scriptname').get(script.view);
6268
aApp.route('/scripts/:username/:scriptname/edit').get(authentication.validateUser, script.edit).post(authentication.validateUser, script.edit);
6369
aApp.route('/scripts/:username/:scriptname/source').get(user.editScript);
6470
aApp.route('/scripts/:username').get(function (aReq, aRes) {
65-
aRes.redirect('/users/' + aReq.params.username + '/scripts'); // NOTE: Watchpoint
71+
aRes.redirect(301, '/users/' + aReq.params.username + '/scripts'); // NOTE: Watchpoint
6672
});
6773

6874
aApp.route('/install/:username/:scriptname').get(scriptStorage.unlockScript, scriptStorage.sendScript);
@@ -72,7 +78,6 @@ module.exports = function (aApp) {
7278
// Github hook routes
7379
aApp.route('/github/hook').post(scriptStorage.webhook);
7480
aApp.route('/github/service').post(function (aReq, aRes, aNext) { aNext(); });
75-
aApp.route('/github').get(function (aReq, aRes) { aRes.redirect('/'); });
7681

7782
// Library routes
7883
aApp.route('/libs/:username/:scriptname').get(script.lib(script.view));

views/includes/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<li><a href="/logout" title="Sign Out"><span class="visible-xs-inline">Sign Out</span><i class="fa fa-sign-out"></i></a></li>
2424
{{/authedUser}}
2525
{{^authedUser}}
26-
<li><a href="/register">Sign In / Sign Up <i class="fa fa-sign-in"></i></a></li>
26+
<li><a href="/login">Sign In / Sign Up <i class="fa fa-sign-in"></i></a></li>
2727
{{/authedUser}}
2828
</ul>
2929
</div>

views/pages/loginPage.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
<form action="/auth/" method="post" class="form-register">
1212
<input type="hidden" name="redirectTo" value="{{{redirectTo}}" />
1313
<h3>
14-
Register
14+
Login
1515
<span class="help-block small">Enter your username for our site to use with your preferred <a href="https://www.wikipedia.org/wiki/OAuth">OAuth</a>/<a href="https://www.wikipedia.org/wiki/OpenID">OpenID</a> service.</span>
1616
</h3>
1717
<noscript>
1818
<div class="alert alert-danger small" role="alert">
19-
<i class="fa fa-exclamation-triangle"></i> <strong>WARNING</strong>: The username entered may include additional sanitizing for web friendly URLs and Userscript engine compatibility. If you wish to see the sanitization changes please enable JavaScript and <a href="/register">start over</a>.
19+
<i class="fa fa-exclamation-triangle"></i> <strong>WARNING</strong>: The username entered may include additional sanitizing for web friendly URLs and Userscript engine compatibility. If you wish to see the sanitization changes please enable JavaScript and <a href="/login">start over</a>.
2020
</div>
2121
</noscript>
2222
<div class="input-group">
@@ -32,7 +32,7 @@ <h3>
3232
</span>
3333
</div>
3434
<div class="alert alert-warning small" role="alert">
35-
<i class="fa fa-exclamation-triangle"></i> <strong>CAUTION</strong>: The username that you choose to register will be displayed to everyone. It is strongly recommended to <strong>not</strong> attempt to use an email address.
35+
<i class="fa fa-exclamation-triangle"></i> <strong>CAUTION</strong>: The username that you choose to login with will be displayed to everyone. It is strongly recommended to <strong>not</strong> attempt to use an email address.
3636
</div>
3737
<ul class="nav nav-pills nav-justified">
3838
<li><a href="/about/Privacy-Policy"><i class="fa fa-user-secret"></i> Privacy Policy</a></li>

0 commit comments

Comments
 (0)