-
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.
- Loading branch information
Showing
5 changed files
with
79 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const fetch = require('node-fetch') | ||
const FormData = require('form-data') | ||
const inquirer = require('inquirer') | ||
const chalk = require('chalk') | ||
const { LOGIN_URL } = require('../utils/globalConfig') | ||
|
||
const login = async () => { | ||
// 输入友互通账号密码 | ||
const ans = await inquirer.prompt([ | ||
{ | ||
type: 'input', | ||
name: 'username', | ||
message: 'username:', | ||
validate: function (val) { | ||
if (checkPhone(val) || checkEmail(val)) { // 校验位数 | ||
return true | ||
} | ||
return 'Please input the correct mobile number or email' | ||
} | ||
}, | ||
{ | ||
type: 'password', | ||
name: 'password', | ||
message: 'password:' | ||
} | ||
]) | ||
await setUserInfo(ans) | ||
} | ||
|
||
function checkPhone (str) { | ||
const reg = /^1[3456789]\d{9}$/ | ||
if (reg.test(str)) { | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
|
||
function checkEmail (str) { | ||
const reg = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/ | ||
if (reg.test(str)) { | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
|
||
const setUserInfo = async (ans) => { | ||
const form = new FormData() | ||
form.append('username', ans.username) | ||
form.append('password', ans.password) | ||
fetch(LOGIN_URL, { | ||
method: 'post', | ||
body: form | ||
}) | ||
.then(async function (response) { | ||
const res = await response.json() | ||
if (res.status === 200) { | ||
console.log(chalk.green(`${res.data}`)) | ||
} | ||
}).catch(function (error) { | ||
console.error(error.message) | ||
}) | ||
} | ||
|
||
module.exports = login |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const CONFIG_FILE_NAME = 'yonui-cli' | ||
const YNPM_PUBLISH_URL = 'http://libraui-backend.test.app.yyuap.com/package/cliPublish' | ||
const LOGIN_URL = 'http://libraui-backend.test.app.yyuap.com/package/cliLogin' | ||
|
||
module.exports = { | ||
CONFIG_FILE_NAME, | ||
YNPM_PUBLISH_URL | ||
YNPM_PUBLISH_URL, | ||
LOGIN_URL | ||
} |
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