参考steemsnippets
//用发贴私钥或密码登录
login(){
//用私钥或密码登录
this.isLoading = true
let account = this.username
this.steem.api.getAccounts([account], (err, result) => {
if(result.length === 0){
this.isLoading = false
alert("用户不存在!")
}else{
//用户存在
let pubWif = result[0].posting.key_auths[0][0]
let privWif = this.password
let isvalid
//判断是私钥还是密码
let res = this.steem.auth.isWif(privWif)
if(res === true){
//是私钥
console.log(456, res, '是私钥!')
try{
isvalid = this.steem.auth.wifIsValid(privWif, pubWif)
}
catch(e){
isvalid = 'false'
}
if(isvalid === true){
this.isLoading = false
console.log(' Welcome.', account)
this.$store.commit('saveUser', {username: account, password: privWif})
this.$router.push({path:'/'})
}else{
this.isLoading = false
alert(`错误!请检查用户名和发贴密钥!`)
}
}else{
//是密码
console.log(458, res, '是密码')
//获取发贴私钥
let role = ["posting"]
let Wif = this.steem.auth.toWif(account, privWif, role)
try{
isvalid = this.steem.auth.wifIsValid(Wif, pubWif)
}
catch(e){
isvalid = 'false'
}
if(isvalid === true){
this.isLoading = false
console.log(' Welcome.', account)
this.$store.commit('saveUser', {username: account, password: Wif})
this.$router.push({path:'/'})
}else{
this.isLoading = false
alert(`错误!请检查用户名和密码!`)
}
}
}
})
}
RE: SteemJS中文手册