Skip to content

Instantly share code, notes, and snippets.

@cake955214 cake955214/email.vue Secret
Last active Oct 29, 2018

Embed
What would you like to do?
<template>
<div class="phone">
<br><br><br><br>
<br><br><br><br>
<h2 class="phone">當前的電話號碼為 {{ phone }}</h2>
<br><br>
<template v-if="modify_phone_button === false">
<div class="ts focus input">
<input v-model="verify_number" type="text" placeholder="輸入新的手機號碼 ...">
</div>
<div id="test"></div>
<br><br>
<button @click="modify_phone(verify_number)" class="ts negative button">發送簡訊</button>
</template>
<br><br><br>
<template v-if="modify_phone_button === false">
<div class="ts focus input">
<input v-model="verify_number_credential" type="text" placeholder="驗證碼">
</div>
<br><br>
<button @click="check_modefy_phone" class="ts negative button">確認</button>
</template>
</div>
</template>
<script>
export default {
name: "phone",
data() {
return {
phone: '',
modify_phone_button: false,
verify_number: '',
verify_number_credential: '',
user: '',
phone_confirm: ''
}
},
created() {
this.user = firebase.auth().currentUser;
if (this.user) {
let temp;
temp = "0" + this.user.phoneNumber * 1 - 886000000000;
this.phone = "0" + temp
}
},
methods: {
modify_phone: function(phone){ // 寄簡訊
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('test', {
'size': 'invisible',
'callback': function(response) {}
});
var phoneNumber = "+886" + phone;
firebase.auth().languageCode = 'zh-TW';
var appVerifier = window.recaptchaVerifier;
this.user.reauthenticateWithPhoneNumber(phoneNumber,appVerifier)
.then(function (confirmationResult) {
console.log("message success");
})
.catch(function (error) {
console.log(error);
alert("簡訊發送失敗,請重新整理再試");
});
},
check_modefy_phone: function () { // 打驗證碼
confirm(this.verify_number_credential)
.then(function (result) {
this.user.updatePhoneNumber(result)
.then(function (answer) {
alert("更改成功");
console.log(answer);
})
.catch(function (error) {
console.log(error);
})
})
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.