Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User service #5

Merged
merged 4 commits into from
May 1, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
moved user cmds into a class
sungly committed May 1, 2020
commit 876317df09dbd140bb85be788f0ac8d61af99623
11 changes: 10 additions & 1 deletion src/cmds/index.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@ import minimist from 'minimist';

import init from './init';
import login from './login';
import userCmd from './user';
import UserCmd from './user';

const userCmd = new UserCmd();

const cli = () => {
const args = minimist(process.argv.slice(2));
@@ -43,6 +45,13 @@ const cli = () => {

userCmd.forgotPassword();
break;
case 'set-user-password':
console.log('Setting user password');
console.log('*** Requires admin permission ***');

userCmd.setUserPassword();
break;

case 'get-user-profile':
console.log('Getting user profile');
console.log('*** Requires admin permission ***');
29 changes: 0 additions & 29 deletions src/cmds/user/confirmUserSignup.js

This file was deleted.

39 changes: 0 additions & 39 deletions src/cmds/user/createUser.js

This file was deleted.

25 changes: 0 additions & 25 deletions src/cmds/user/disableUser.js

This file was deleted.

25 changes: 0 additions & 25 deletions src/cmds/user/enableUser.js

This file was deleted.

24 changes: 0 additions & 24 deletions src/cmds/user/forgotPassword.js

This file was deleted.

24 changes: 0 additions & 24 deletions src/cmds/user/getUserProfile.js

This file was deleted.

226 changes: 205 additions & 21 deletions src/cmds/user/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,205 @@
import createUser from './createUser';
import confirmUserSignup from './confirmUserSignup';
import resendConfirmationCode from './resendConfirmationCode';
import forgotPassword from './forgotPassword';
import setUserPassword from './setUserPassword';
import getUserProfile from './getUserProfile';
import verifyUserEmail from './verifyUserEmail';
import disableUser from './disableUser';
import enableUser from './enableUser';

export default {
createUser,
confirmUserSignup,
resendConfirmationCode,
forgotPassword,
setUserPassword,
getUserProfile,
verifyUserEmail,
disableUser,
enableUser,
};
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;
24 changes: 0 additions & 24 deletions src/cmds/user/resendConfirmationCode.js

This file was deleted.

32 changes: 0 additions & 32 deletions src/cmds/user/setUserPassword.js

This file was deleted.

Empty file removed src/cmds/user/updateUserProfile.js
Empty file.
24 changes: 0 additions & 24 deletions src/cmds/user/verifyUserEmail.js

This file was deleted.