Skip to content
This repository was archived by the owner on Feb 25, 2019. It is now read-only.

Commit 4f70d9c

Browse files
committed
scan to login
1 parent 36667b3 commit 4f70d9c

File tree

3 files changed

+180
-0
lines changed

3 files changed

+180
-0
lines changed

src/pages/Login.vue

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
//扫描二维码登陆
2+
/**
3+
* 导入钱包界面
4+
*/
5+
<template>
6+
<div class="page" v-bind:class="{hidebackground: showScanner}">
7+
<toolbar :title="$t(title)" :showbackicon="showbackicon">
8+
<v-btn icon style="visibility: hidden;" slot="left-tool">
9+
<v-icon class="back-icon"/>
10+
</v-btn>
11+
<div class="right" slot="right-tool">
12+
<span class="toolbar-ico" @click="scan">
13+
<v-icon class="font28" v-if="showScanner">&#xE5CD;</v-icon>
14+
<i v-else class="iconfont icon-erweima1 font28"></i>
15+
</span>
16+
</div>
17+
</toolbar>
18+
19+
<q-r-scan
20+
@finish="qrfinish"
21+
@close="qrclose"
22+
:validator="qrvalidator"
23+
v-if="showScanner"></q-r-scan>
24+
25+
<div class="content" v-if="!showScanner">
26+
27+
<div>是否登陆网站:{{domain}}?</div>
28+
<v-btn block @click="logon">{{$t('OK')}}</v-btn>
29+
</div>
30+
</div>
31+
</template>
32+
33+
<script>
34+
import Toolbar from '@/components/Toolbar'
35+
import QRScan from '@/components/QRScan'
36+
import SecretKeyInput from '@/components/SecretKeyInput'
37+
import {importAccount,isValidSeed,fromMnemonic, validateMnemonic} from '@/api/account'
38+
import { getMnemonicFromData } from '@/api/qr'
39+
import { mapState, mapActions} from 'vuex'
40+
import { isEnglishMnemonic, isChineseMnemonic } from '../api/account';
41+
42+
const axios = require('axios');
43+
import { signToBase64, verifyByBase64 } from '@/api/keypair'
44+
45+
export default {
46+
data(){
47+
return {
48+
title: 'Login',
49+
showbackicon: false,
50+
showScanner: true,
51+
url: null,
52+
53+
}
54+
},
55+
computed:{
56+
...mapState({
57+
account: state => state.accounts.selectedAccount,
58+
accountData: state => state.accounts.accountData,
59+
}),
60+
domain(){
61+
if(!this.url)return;
62+
let key = '&origin_domain='
63+
let index = this.url.indexOf(key) + key.length
64+
key = '&signature='
65+
return decodeURIComponent(this.url.substring(index, this.url.indexOf(key)))
66+
}
67+
68+
},
69+
mounted () {
70+
},
71+
methods: {
72+
...mapActions({
73+
}),
74+
75+
goback(){
76+
this.$router.back()
77+
},
78+
// inputSeed(value){
79+
// this.setNewSeed({seed:value})
80+
// },
81+
scan(){
82+
//只能识别stargazer类似的格式数据
83+
if(this.showScanner){
84+
this.showScanner = false
85+
this.title = 'Login'
86+
}else{
87+
this.showScanner = true
88+
this.title = 'Title.Scan'
89+
this.scanSuccess = false
90+
}
91+
},
92+
qrvalidator(text){
93+
if(text.startsWith('web+stellar:login')){
94+
this.$toasted.show('---qrcode is right--')
95+
this.url = text;
96+
return true;
97+
}
98+
this.$toasted.error('-----qrtext valid false----')
99+
return false;
100+
},
101+
qrfinish(result){
102+
this.showScanner = false
103+
this.title = 'Login'
104+
//校验签名是否正确
105+
let key = '&signature='
106+
let text = this.url;
107+
let index = text.indexOf(key)
108+
let plainText = text.substring(0,index)
109+
let signature = text.substring(index+key.length, text.length)
110+
let accountid = 'GDFETGX4ZOZUDOGMYHW2IN2WXWQLJ5V7VRJIDW5GCYMZ4X5O6ULV5GZI'//后续从stellar.toml中获取
111+
let chk = verifyByBase64(accountid, plainText, signature)
112+
if(chk){
113+
this.$toasted.show(`checked true`)
114+
}
115+
this.$toasted.error(`checked fail.`)
116+
117+
},
118+
qrclose(){
119+
//this.showScanner = false
120+
//this.title = 'Login'
121+
},
122+
logon(){
123+
//生成签名
124+
let cbkey = '&callback='
125+
let cbindex = this.url.indexOf(cbkey)
126+
let cb = this.url.substring(cbindex+cbkey.length, this.url.indexOf('&origin_domain='))
127+
cb = decodeURIComponent(cb)
128+
let path = this.url.substring(0, cbindex)
129+
path += '&accountid='+this.account.address
130+
let signature = signToBase64(this.accountData.seed, path)
131+
// path += '&signature' + encodeURIComponent(signature)
132+
this.$toasted.show('cb='+cb)
133+
try{
134+
axios.post(cb, {
135+
r: this.url.substring(this.url.indexOf('?r=')+3, cbindex),
136+
accountid: this.account.address,
137+
signature: encodeURIComponent(signature)
138+
})
139+
.then(response=>{
140+
this.$toasted.show('logon success')
141+
142+
})
143+
.catch(err=>{
144+
console.error(err)
145+
this.$toasted.error('logon failed!'+err.message + ',' + err.response.data.error)
146+
})
147+
148+
}catch(err){
149+
alert('发生错误:'+err.message)
150+
}
151+
152+
153+
}
154+
155+
},
156+
components: {
157+
Toolbar,
158+
QRScan,
159+
}
160+
}
161+
</script>
162+
163+
<style lang="stylus" scoped>
164+
@require '../stylus/color.styl'
165+
166+
</style>

src/pages/settings/About.vue

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
<i class="material-icons vcenter f-right">keyboard_arrow_right</i>
6666
</div>
6767
</div>
68+
<div class="row" v-if="isDebug" @click="toScanLogin">
69+
<div class="label">Scan to Login</div>
70+
<div class="value">
71+
<i class="material-icons vcenter f-right">keyboard_arrow_right</i>
72+
</div>
73+
</div>
6874

6975
<div class="field_btn">
7076
<v-btn :loading="working" class="error btn_ok" @click.stop="checkForUpdates">{{$t('CheckForUpdates')}}</v-btn>
@@ -181,6 +187,9 @@ export default {
181187
toDebug(){
182188
//window.location.href = 'http://192.168.2.253:3000'
183189
window.open('http://192.168.2.253:3000', "_self");
190+
},
191+
toScanLogin(){
192+
this.$router.push({name: 'Login'})
184193
}
185194
},
186195
components: {

src/router/mysettings.js

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export default {
6666
name: 'Tickets',
6767
component: resolve => require(['../pages/settings/Tickets'], resolve)
6868
},
69+
{
70+
path: 'login',
71+
name: 'Login',
72+
component: resolve => require(['../pages/Login'], resolve)
73+
},
6974

7075
]
7176
}

0 commit comments

Comments
 (0)