mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-29 22:20:42 +00:00
rewrite: facebook auth bug fixes. still not ideal solution, but it works
for now
This commit is contained in:
parent
ceae8bf768
commit
466c727d4e
6 changed files with 18 additions and 11 deletions
|
|
@ -21,7 +21,7 @@ window.habitrpg = angular.module('habitrpg',
|
|||
if (settings && settings.auth) {
|
||||
$httpProvider.defaults.headers.common['Content-Type'] = 'application/json;charset=utf-8';
|
||||
$httpProvider.defaults.headers.common['x-api-user'] = settings.auth.apiId;
|
||||
$httpProvider.defaults.headers.common['x-api-key'] = settings.auth.apiId;
|
||||
$httpProvider.defaults.headers.common['x-api-key'] = settings.auth.apiToken;
|
||||
}
|
||||
|
||||
// Handle errors
|
||||
|
|
|
|||
|
|
@ -82,6 +82,11 @@ habitrpg.controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$loca
|
|||
}).error(errorAlert);
|
||||
}
|
||||
|
||||
if ($location.path() == '/facebook-callback') {
|
||||
var search = $location.search();
|
||||
runAuth(search._id, search.apiToken);
|
||||
}
|
||||
|
||||
$scope.playButtonClick = function(){
|
||||
if (User.authenticated()) {
|
||||
window.location.href = '/#/tasks';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
var passport = require('passport');
|
||||
var _ = require('lodash');
|
||||
var async = require('async');
|
||||
var derbyAuthUtil = require('derby-auth/utils');
|
||||
var User = require('../models/user').model;
|
||||
|
||||
var api = module.exports;
|
||||
|
|
@ -77,7 +79,7 @@ api.registerUser = function(req, res, next) {
|
|||
return cb("Username already taken");
|
||||
}
|
||||
newUser = helpers.newUser(true);
|
||||
salt = utils.makeSalt();
|
||||
salt = derbyAuthUtil.makeSalt();
|
||||
newUser.auth = {
|
||||
local: {
|
||||
username: username,
|
||||
|
|
@ -116,7 +118,7 @@ api.loginLocal = function(req, res, next) {
|
|||
// We needed the whole user object first so we can get his salt to encrypt password comparison
|
||||
User.findOne({
|
||||
'auth.local.username': username,
|
||||
'auth.local.hashed_password': utils.encryptPassword(password, user.auth.local.salt)
|
||||
'auth.local.hashed_password': derbyAuthUtil.encryptPassword(password, user.auth.local.salt)
|
||||
}, cb);
|
||||
}
|
||||
], function(err, user) {
|
||||
|
|
@ -200,9 +202,11 @@ api.setupPassport = function(router) {
|
|||
//res.redirect('/');
|
||||
|
||||
User.findOne({'auth.facebook.id':req.user.id}, function(err, user){
|
||||
if (err) return res.json(500, {err:err});
|
||||
if (!user) return res.json(401, {err: "New Facebook registrations aren't yet supported, only existing Facebook users. Help us code this!"});
|
||||
res.json({id: user._id, token: user.apiToken});
|
||||
if (err || !user) {
|
||||
if (!err) err = "New Facebook registrations aren't yet supported, only existing Facebook users. Help us code this!";
|
||||
return res.redirect('/#/facebook-callback?err=' + err);
|
||||
}
|
||||
res.redirect('/#/facebook-callback?_id='+user._id+'&apiToken='+user.apiToken);
|
||||
})
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ var items = require('habitrpg-shared/script/items');
|
|||
var validator = require('derby-auth/node_modules/validator');
|
||||
var check = validator.check;
|
||||
var sanitize = validator.sanitize;
|
||||
var utils = require('derby-auth/utils');
|
||||
var derbyAuthUtil = require('derby-auth/utils');
|
||||
var User = require('./../models/user').model;
|
||||
var Group = require('./../models/group').model;
|
||||
var api = module.exports;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ var router = new express.Router();
|
|||
auth.setupPassport(router); //FIXME make this consistent with the others
|
||||
router.post('/register', auth.registerUser);
|
||||
router.post('/user/auth/local', auth.loginLocal);
|
||||
router.post('/user/auth/facebook', auth.loginFacebook);
|
||||
//router.post('/user/auth/facebook', auth.loginFacebook);
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -25,9 +25,9 @@ block content
|
|||
button.close(type='button', data-dismiss='modal', aria-hidden='true') ×
|
||||
h4.modal-title Login / Register
|
||||
.modal-body
|
||||
//-a(ng-click='facebookAuth()')
|
||||
a(href='/auth/facebook')
|
||||
img(src='/bower_components/habitrpg-shared/img/facebook-login-register.jpeg', alt='Login / Register With Facebook')
|
||||
//h3 Or
|
||||
h3 Or
|
||||
ul.nav.nav-tabs
|
||||
li.active
|
||||
a(data-toggle='tab',data-target='#login-tab') Login
|
||||
|
|
|
|||
Loading…
Reference in a new issue