-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user-cmds): Added more user service commands (#5)
* added more user service commands * updated authors * moved user cmds into a class
- Loading branch information
Showing
6 changed files
with
310 additions
and
88 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 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,205 @@ | ||
import prompt from 'prompt'; | ||
|
||
import config from '../../config'; | ||
import util from '../../util'; | ||
|
||
class UserCmd { | ||
createUser() { | ||
config.requiredAttributeList.push('password'); | ||
|
||
const requiredAttributes = config.requiredAttributeList.map((attr) => { | ||
return { | ||
name: attr, | ||
required: true, | ||
}; | ||
}); | ||
|
||
prompt.get(requiredAttributes, async (err, result) => { | ||
let username = result.username ? result.username : result.email; | ||
const password = result.password; | ||
|
||
delete result.password; | ||
|
||
const attributes = Object.keys(result).map((key) => { | ||
return { | ||
Name: key, | ||
Value: result[key], | ||
}; | ||
}); | ||
|
||
const res = await util.cognitoService.createUser({ | ||
username, | ||
password, | ||
attributes, | ||
}); | ||
|
||
console.log(res); | ||
}); | ||
} | ||
|
||
confirmUserSignup() { | ||
const requiredAttributes = [ | ||
{ | ||
name: 'username', | ||
required: true, | ||
}, | ||
{ | ||
name: 'code', | ||
required: true, | ||
}, | ||
]; | ||
|
||
prompt.get(requiredAttributes, async (err, result) => { | ||
const { username, code } = result; | ||
|
||
const res = await util.cognitoService.confirmSignUp({ | ||
username, | ||
code, | ||
}); | ||
|
||
console.log(res); | ||
}); | ||
} | ||
|
||
resendConfirmationCode() { | ||
const requiredAttributes = [ | ||
{ | ||
name: 'username', | ||
required: true, | ||
}, | ||
]; | ||
|
||
prompt.get(requiredAttributes, async (err, result) => { | ||
const { username } = result; | ||
|
||
const res = await util.cognitoService.resendConfirmationCode({ | ||
username, | ||
}); | ||
|
||
console.log(res); | ||
}); | ||
} | ||
|
||
forgotPassword() { | ||
const requiredAttributes = [ | ||
{ | ||
name: 'username', | ||
required: true, | ||
}, | ||
]; | ||
|
||
prompt.get(requiredAttributes, async (err, result) => { | ||
const { username } = result; | ||
|
||
const res = await util.cognitoService.forgotPassword({ | ||
username, | ||
}); | ||
|
||
console.log(res); | ||
}); | ||
} | ||
|
||
setUserPassword() { | ||
const requiredAttributes = [ | ||
{ | ||
name: 'username', | ||
required: true, | ||
}, | ||
{ | ||
name: 'password', | ||
required: true, | ||
}, | ||
]; | ||
|
||
prompt.get(requiredAttributes, async (err, result) => { | ||
const { username, password } = result; | ||
|
||
const res = await util.cognitoService.setUserPassword({ | ||
username, | ||
newPassword: password, | ||
}); | ||
|
||
console.log(res); | ||
}); | ||
} | ||
|
||
getUserProfile() { | ||
const requiredAttributes = [ | ||
{ | ||
name: 'username', | ||
required: true, | ||
}, | ||
]; | ||
|
||
prompt.get(requiredAttributes, async (err, result) => { | ||
const { username } = result; | ||
|
||
const res = await util.cognitoService.getUserProfile({ | ||
username, | ||
}); | ||
|
||
console.log(res); | ||
}); | ||
} | ||
|
||
verifyUserEmail() { | ||
const requiredAttributes = [ | ||
{ | ||
name: 'email', | ||
required: true, | ||
}, | ||
]; | ||
|
||
prompt.get(requiredAttributes, async (err, result) => { | ||
const { email } = result; | ||
|
||
const res = await util.cognitoService.verifyUserEmail({ | ||
username: email, | ||
}); | ||
|
||
console.log(res); | ||
}); | ||
} | ||
|
||
disableUser() { | ||
const requiredAttributes = [ | ||
{ | ||
name: 'username', | ||
required: true, | ||
}, | ||
]; | ||
|
||
prompt.get(requiredAttributes, async (err, result) => { | ||
const { username } = result; | ||
|
||
const res = await util.cognitoService.disableUser({ | ||
username, | ||
}); | ||
|
||
if (!res) console.log(`User is disabled.`); | ||
else console.log(res); | ||
}); | ||
} | ||
|
||
enableUser() { | ||
const requiredAttributes = [ | ||
{ | ||
name: 'username', | ||
required: true, | ||
}, | ||
]; | ||
|
||
prompt.get(requiredAttributes, async (err, result) => { | ||
const { username } = result; | ||
|
||
const res = await util.cognitoService.enableUser({ | ||
username, | ||
}); | ||
|
||
if (!res) console.log(`User is enabled.`); | ||
else console.log(res); | ||
}); | ||
} | ||
} | ||
|
||
export default UserCmd; |
Oops, something went wrong.