-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from dasmeta/fix
Fix
- Loading branch information
Showing
51 changed files
with
527 additions
and
206 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
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
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,32 @@ | ||
# examples | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_auth0"></a> [auth0](#requirement\_auth0) | ~> 1.0.0 | | ||
|
||
## Providers | ||
|
||
No providers. | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_auth0"></a> [auth0](#module\_auth0) | ../ | n/a | | ||
| <a name="module_auth0_configs"></a> [auth0\_configs](#module\_auth0\_configs) | Invicton-Labs/deepmerge/null | 0.1.5 | | ||
|
||
## Resources | ||
|
||
No resources. | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
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,51 @@ | ||
function changePassword(email, newPassword, callback) { | ||
const { Pool } = require('pg'); | ||
const aws = require('aws-sdk'); | ||
|
||
const pool = new Pool({ | ||
connectionString: configuration.conString | ||
}); | ||
|
||
async function encrypt(buffer) { | ||
const kms = new aws.KMS({ | ||
accessKeyId: configuration.accessKeyId, | ||
secretAccessKey: configuration.secretAccessKey, | ||
region: configuration.region | ||
}); | ||
try { | ||
const params = { | ||
KeyId: configuration.kmsKeyId, | ||
Plaintext: buffer// The data to encrypt. | ||
}; | ||
|
||
const encryptResult = await kms.encrypt(params).promise(); | ||
|
||
if (encryptResult && encryptResult.CiphertextBlob) { | ||
const encryptedData = encryptResult.CiphertextBlob.toString('base64'); | ||
|
||
pool.connect(function (err, client, done) { | ||
if (err) return callback(err); | ||
|
||
const query = 'UPDATE users SET password = $1 WHERE email = $2'; | ||
client.query(query, [encryptedData, email], function (err, result) { | ||
done(); // Release the client back to the pool | ||
if (err) { | ||
return callback(err, false); | ||
} | ||
// Check if any rows were updated | ||
const rowsUpdated = result ? result.rowCount : 0; | ||
return callback(null, rowsUpdated > 0); | ||
}); | ||
}); | ||
return encryptedData; | ||
} else { | ||
console.error('Encryption result is missing CiphertextBlob:', encryptResult); | ||
throw new Error('Encryption result is missing CiphertextBlob'); | ||
} | ||
} catch (error) { | ||
console.error('Error encrypting data:', error); | ||
throw error; | ||
} | ||
} | ||
encrypt(newPassword); | ||
} |
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,46 @@ | ||
function create(user, callback) { | ||
const aws = require('aws-sdk'); | ||
const { Pool } = require('pg'); | ||
|
||
const pool = new Pool({ | ||
connectionString: configuration.conString | ||
}); | ||
|
||
async function encrypt(buffer) { | ||
const kms = new aws.KMS({ | ||
accessKeyId: configuration.accessKeyId, | ||
secretAccessKey: configuration.secretAccessKey, | ||
region: configuration.region | ||
}); | ||
try { | ||
const params = { | ||
KeyId: configuration.kmsKeyId, | ||
Plaintext: buffer// The data to encrypt. | ||
}; | ||
|
||
const encryptResult = await kms.encrypt(params).promise(); | ||
|
||
if (encryptResult && encryptResult.CiphertextBlob) { | ||
const encryptedData = encryptResult.CiphertextBlob.toString('base64'); | ||
|
||
pool.connect(function (err, client, done) { | ||
if (err) return callback(err); | ||
|
||
const query = 'INSERT INTO users(email, password) VALUES ($1, $2)'; | ||
client.query(query, [user.email, encryptedData], function (err, result) { | ||
done(); // Release the client back to the pool | ||
return callback(err); | ||
}); | ||
}); | ||
return encryptedData; | ||
} else { | ||
console.error('Encryption result is missing CiphertextBlob:', encryptResult); | ||
throw new Error('Encryption result is missing CiphertextBlob'); | ||
} | ||
} catch (error) { | ||
console.error('Error encrypting data:', error); | ||
throw error; | ||
} | ||
} | ||
encrypt(user.password); | ||
} |
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,18 @@ | ||
function remove(id, callback) { | ||
const { Pool } = require('pg'); | ||
|
||
const pool = new Pool({ | ||
connectionString: configuration.conString | ||
}); | ||
|
||
pool.connect(function (err, client, done) { | ||
if (err) return callback(err); | ||
|
||
const query = 'DELETE FROM users WHERE id = $1'; | ||
client.query(query, [id], function (err) { | ||
done(); // Release the client back to the pool | ||
|
||
return callback(err); | ||
}); | ||
}); | ||
} |
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,22 @@ | ||
function getByEmail(email, callback) { | ||
const { Pool } = require('pg'); | ||
|
||
const pool = new Pool({ | ||
connectionString: configuration.conString | ||
}); | ||
|
||
const query = 'SELECT id, nickname, email FROM users WHERE email = $1'; | ||
|
||
pool.query(query, [email], function (err, result) { | ||
if (err || result.rows.length === 0) { | ||
return callback(err || null); | ||
} | ||
|
||
const user = result.rows[0]; | ||
callback(null, { | ||
user_id: user.id.toString(), | ||
nickname: user.nickname, | ||
email: user.email, | ||
}); | ||
}); | ||
} |
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,53 @@ | ||
function login(email, password, callback) { | ||
const aws = require('aws-sdk'); | ||
const postgres = require('pg'); | ||
|
||
const pool = new Pool({ | ||
connectionString: configuration.conString | ||
}); | ||
|
||
pool.connect(function (err, client, done) { | ||
if (err) return callback(err); | ||
|
||
const query = 'SELECT id, nickname, email, password FROM users WHERE email = $1'; | ||
client.query(query, [email], function (err, result) { | ||
// Release the client back to the pool | ||
done(); | ||
|
||
if (err || result.rows.length === 0) { | ||
return callback(err || new WrongUsernameOrPasswordError(email)); | ||
} | ||
|
||
const user = result.rows[0]; | ||
decrypt(user,password); | ||
}); | ||
}); | ||
|
||
async function decrypt(user,i_password) { | ||
const kms = new aws.KMS({ | ||
accessKeyId: configuration.accessKeyId, | ||
secretAccessKey: configuration.secretAccessKey, | ||
region: configuration.region | ||
}); | ||
try { | ||
const params = { | ||
CiphertextBlob: Buffer.from(user.password, 'base64'), | ||
}; | ||
const { Plaintext } = await kms.decrypt(params).promise(); | ||
openedData = Plaintext.toString(); | ||
|
||
if (openedData !== i_password) { | ||
return callback(new WrongUsernameOrPasswordError(email)); | ||
} else { | ||
return callback(null, { | ||
user_id: user.id, | ||
nickname: user.nickname, | ||
email: user.email | ||
}); | ||
} | ||
} catch (error) { | ||
console.error('Error decrypting data:', error); | ||
throw error; | ||
} | ||
} | ||
} |
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,24 @@ | ||
function verify(email, callback) { | ||
const { Pool } = require('pg'); | ||
|
||
const pool = new Pool({ | ||
connectionString: configuration.conString | ||
}); | ||
|
||
pool.connect(function (err, client, done) { | ||
if (err) return callback(err); | ||
|
||
const query = 'UPDATE users SET email_verified = true WHERE email_verified = false AND email = $1'; | ||
client.query(query, [email], function (err, result) { | ||
done(); // Release the client back to the pool | ||
|
||
if (err) { | ||
return callback(err, false); | ||
} | ||
|
||
// Check if any rows were updated | ||
const rowsUpdated = result ? result.rowCount : 0; | ||
return callback(null, rowsUpdated > 0); | ||
}); | ||
}); | ||
} |
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
Oops, something went wrong.