mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-01 07:21:15 +00:00
rewrite: uhoh, controller scoping issues due to
angular-bootstrap#0.4.0. We can't use 0.5.0 bacause it can't handle nested tabs. we may have to scrap it altogether
This commit is contained in:
parent
17a9469370
commit
488c5b3e64
3 changed files with 49 additions and 62 deletions
|
|
@ -53,9 +53,10 @@ habitrpg.controller("AuthCtrl", ['$scope', '$rootScope', 'Facebook', 'LocalAuth'
|
|||
if ($scope.useUUID) {
|
||||
runAuth($scope.loginUsername, $scope.loginPassword);
|
||||
} else {
|
||||
$http.post(API_URL + "/api/v1/user/auth/local", data).success(function(data, status, headers, config) {
|
||||
runAuth(data.id, data.token);
|
||||
}).error(function(data, status, headers, config) {
|
||||
$http.post(API_URL + "/api/v1/user/auth/local", data)
|
||||
.success(function(data, status, headers, config) {
|
||||
runAuth(data.id, data.token);
|
||||
}).error(function(data, status, headers, config) {
|
||||
if (status === 0) {
|
||||
alert("Server not currently reachable, try again later");
|
||||
} else if (!!data && !!data.err) {
|
||||
|
|
|
|||
|
|
@ -524,37 +524,24 @@ api.getUser = function(req, res, next) {
|
|||
|
||||
|
||||
api.loginLocal = function(req, res, next) {
|
||||
var password, username, _ref;
|
||||
_ref = req.body, username = _ref.username, password = _ref.password;
|
||||
return async.waterfall([
|
||||
var username = req.body.username;
|
||||
var password = req.body.password;
|
||||
async.waterfall([
|
||||
function(cb) {
|
||||
if (!(username && password)) {
|
||||
return cb('No username or password');
|
||||
}
|
||||
return User.findOne({
|
||||
'auth.local.username': username
|
||||
}, cb);
|
||||
if (!(username && password)) return cb('No username or password');
|
||||
User.findOne({'auth.local.username': username}, cb);
|
||||
}, function(user, cb) {
|
||||
if (!user) {
|
||||
return cb('Username not found');
|
||||
}
|
||||
/* We needed the whole user object first so we can get his salt to encrypt password comparison*/
|
||||
|
||||
return User.findOne({
|
||||
if (!user) return cb('Username not found');
|
||||
// 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)
|
||||
}, cb);
|
||||
}
|
||||
], function(err, user) {
|
||||
if (!user) {
|
||||
err = 'Incorrect password';
|
||||
}
|
||||
if (err) {
|
||||
return res.json(401, {
|
||||
err: err
|
||||
});
|
||||
}
|
||||
return res.json(200, {
|
||||
if (!user) err = 'Incorrect password';
|
||||
if (err) return res.json(401, {err: err});
|
||||
res.json(200, {
|
||||
id: user._id,
|
||||
token: user.apiToken
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,40 +1,39 @@
|
|||
div(ng-controller='AuthCtrl')
|
||||
div(modal='modals.login', close='')
|
||||
.modal-header
|
||||
h3 Login / Register
|
||||
.modal-body
|
||||
//a(href='/auth/facebook')
|
||||
img(src='/img/facebook-login-register.jpeg', alt='Login / Register With Facebook')
|
||||
//h3 Or
|
||||
tabset
|
||||
tab(heading='Login')
|
||||
form(ng-submit='auth()')
|
||||
.control-group
|
||||
input(type='text', ng-model='loginUsername', placeholder='{{useUUID ? \'UUID\' : \'Username\'}}')
|
||||
.control-group
|
||||
input(type='{{useUUID ? \'text\' : \'password\'}}', ng-model='loginPassword', placeholder='{{useUUID ? \'API Token\' : \'Password\'}}')
|
||||
.control-group
|
||||
label.checkbox
|
||||
input(type='checkbox', ng-click='useUUID = !useUUID')
|
||||
| Use UUID / API Token (For Facebook Users)
|
||||
.control-group
|
||||
input.btn.btn-primary(type='submit', value='Login')
|
||||
div(modal='modals.login')
|
||||
.modal-header
|
||||
h3 Login / Register
|
||||
.modal-body
|
||||
//a(href='/auth/facebook')
|
||||
img(src='/img/facebook-login-register.jpeg', alt='Login / Register With Facebook')
|
||||
//h3 Or
|
||||
tabset
|
||||
tab(heading='Login')
|
||||
form(ng-controller='AuthCtrl', ng-submit='auth()')
|
||||
.control-group
|
||||
input(type='text', ng-model='loginUsername', placeholder='{{useUUID ? \'UUID\' : \'Username\'}}')
|
||||
.control-group
|
||||
input(type='{{useUUID ? "text" : "password"}}', ng-model='loginPassword', placeholder='{{useUUID ? \'API Token\' : \'Password\'}}')
|
||||
.control-group
|
||||
label.checkbox
|
||||
input(type='checkbox', ng-click='useUUID = !useUUID')
|
||||
| Use UUID / API Token (For Facebook Users)
|
||||
.control-group
|
||||
input.btn.btn-primary(type='submit', value='Login')
|
||||
|
||||
tab(heading='Register')
|
||||
form(ng-submit='register()', name='registrationForm')
|
||||
.control-group
|
||||
input(type='text', ng-model='registerVals.username', placeholder='Username', required)
|
||||
.control-group
|
||||
input(type='email', ng-model='registerVals.email', placeholder='Email', required)
|
||||
.control-group
|
||||
input(type='password', ng-model='registerVals.password', placeholder='Password', required)
|
||||
.control-group
|
||||
input(type='password', ng-model='registerVals.confirmPassword', placeholder='Password Confirm', required)
|
||||
.control-group
|
||||
input.btn.btn-primary(type='submit', value='Register')
|
||||
tab(heading='Register')
|
||||
form(ng-controller='AuthCtrl', ng-submit='register()', name='registrationForm')
|
||||
.control-group
|
||||
input(type='text', ng-model='registerVals.username', placeholder='Username', required)
|
||||
.control-group
|
||||
input(type='email', ng-model='registerVals.email', placeholder='Email', required)
|
||||
.control-group
|
||||
input(type='password', ng-model='registerVals.password', placeholder='Password', required)
|
||||
.control-group
|
||||
input(type='password', ng-model='registerVals.confirmPassword', placeholder='Password Confirm', required)
|
||||
.control-group
|
||||
input.btn.btn-primary(type='submit', value='Register')
|
||||
|
||||
|
||||
.modal-footer
|
||||
button.btn.btn-warning.cancel(ng-click='modals.login = false') Cancel
|
||||
.modal-footer
|
||||
button.btn.btn-warning.cancel(ng-click='modals.login = false') Cancel
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue