-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
179 changed files
with
6,471 additions
and
13,832 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets" : ["es2015", "react"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
env: | ||
browser: true | ||
commonjs: true | ||
es6: true | ||
node: true | ||
extends: 'eslint:recommended' | ||
globals: | ||
ga: true | ||
parserOptions: | ||
ecmaFeatures: | ||
experimentalObjectRestSpread: true | ||
jsx: true | ||
sourceType: module | ||
plugins: | ||
- react | ||
rules: | ||
linebreak-style: | ||
- error | ||
- unix | ||
quotes: | ||
- error | ||
- single | ||
semi: | ||
- error | ||
- always | ||
curly: error | ||
eqeqeq: error | ||
no-empty: warn | ||
no-console: off | ||
no-unused-vars: off |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
|
||
const Joi = require('joi'); | ||
const Boom = require('boom'); | ||
const Crypto = require('crypto'); | ||
|
||
exports.postChangePassword = { | ||
description: 'Password change api', | ||
validate: { | ||
payload: { | ||
oldPassword: Joi.string().min(6).max(20).required(), | ||
newPassword: Joi.string().min(6).max(20).required(), | ||
verify: Joi.string().required(), | ||
}, | ||
failAction: function(request, reply, source, error) { | ||
// Boom bad request | ||
return reply(Boom.badRequest(error)); | ||
} | ||
}, | ||
auth: { | ||
mode: 'try', | ||
strategy: 'standard' | ||
}, | ||
plugins: { | ||
'hapi-auth-cookie': { | ||
redirectTo: false | ||
} | ||
}, | ||
handler: function(request, reply) { | ||
|
||
if (!request.auth.isAuthenticated) { | ||
return Boom.forbidden('You are not logged in'); | ||
} | ||
|
||
if (request.payload.newPassword !== request.payload.verify) { | ||
return reply(Boom.badRequest('New password does not match')); | ||
} | ||
var User = request.server.plugins.sequelize.db.User; | ||
|
||
User.findOne({ | ||
where: { | ||
username: request.auth.credentials.username, | ||
password: Crypto.createHash('md5').update(request.payload.oldPassword).digest('hex') | ||
} | ||
}).then(function(user) { | ||
if (user) { | ||
user.update({ | ||
password: Crypto.createHash('md5').update(request.payload.newPassword).digest('hex') | ||
}).then(function() { | ||
request.cookieAuth.clear(); | ||
|
||
var msg = { | ||
'statusCode': 200, | ||
'message': 'Password changed successfully. Please login with new password' | ||
}; | ||
return reply(msg); | ||
}); | ||
} else { | ||
// User not fond in database | ||
return reply(Boom.badRequest('Old password is incorrect')); | ||
} | ||
}); | ||
} | ||
}; |
Oops, something went wrong.