From 08e7ed8f86cdd590d165ab2ee9a6510450b30846 Mon Sep 17 00:00:00 2001 From: su Date: Sun, 10 May 2020 14:37:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E9=BB=98=E8=AE=A4=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 40 ++++++++++++++++++-- src/views/login/PhoneLogin.vue | 69 +++++++++++++++++++++++++--------- 2 files changed, 88 insertions(+), 21 deletions(-) diff --git a/src/main.js b/src/main.js index 38814f4d4..86c5d0eed 100644 --- a/src/main.js +++ b/src/main.js @@ -19,6 +19,31 @@ Vue.directive("focus", { } }); // Vue.config.devtools = true + +// 检查登录成功后的状态 +const onAuthenticated = userinfo => { + if (userinfo.signedUp === userinfo.lastLogin) { + // 初次登录 + // 检查是否手机号注册 + if (userinfo.registerMethod !== "phone:message") { + if (location.host === "localhost") { + location.href = "http://localhost:3000/bind-phone"; + } else { + location.href = "https//authing.co/bind-phone"; + } + } + } else { + // 老用户,需要检查是否绑定了手机号 + if (!userinfo.phone) { + if (location.host === "localhost") { + location.href = "http://localhost:3000/bind-phone"; + } else { + location.href = "https//authing.co/bind-phone"; + } + } + } +}; + var AuthingGuard = function(clientId, opts) { window.Authing = Authing; @@ -84,16 +109,18 @@ var AuthingGuard = function(clientId, opts) { $authing.opts.forceLogin = opts.forceLogin || false; $authing.opts.title = opts.title || null; $authing.opts.logo = opts.logo || null; - $authing.opts.defaultLoginMethod = opts.defaultLoginMethod || "PASSWORD" - opts.defaultLoginMethod = opts.defaultLoginMethod || "PASSWORD" + $authing.opts.defaultLoginMethod = opts.defaultLoginMethod || "PASSWORD"; + opts.defaultLoginMethod = opts.defaultLoginMethod || "PASSWORD"; // this.initLinks($authing.opts.SSOHost); - $authing.opts.passwordEncPublicKey = opts.passwordEncPublicKey || `-----BEGIN PUBLIC KEY----- + $authing.opts.passwordEncPublicKey = + opts.passwordEncPublicKey || + `-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC4xKeUgQ+Aoz7TLfAfs9+paePb 5KIofVthEopwrXFkp8OCeocaTHt9ICjTT2QeJh6cZaDaArfZ873GPUn00eOIZ7Ae +TiA2BKHbCvloW3w5Lnqm70iSsUi5Fmu9/2+68GZRH9L7Mlh8cFksCicW2Y2W2uM GKl64GDcIq3au+aqJQIDAQAB - -----END PUBLIC KEY-----` + -----END PUBLIC KEY-----`; $authing.opts.mountId = opts.mountId || null; // 初始化小程序扫码登录配置 @@ -187,6 +214,11 @@ var AuthingGuard = function(clientId, opts) { opts: opts } }); + + // 添加事件回调 + if (opts.appId === "5e3ce9dadf5382920a69a76a") { + this.on("authenticated", onAuthenticated); + } }; AuthingGuard.prototype = { diff --git a/src/views/login/PhoneLogin.vue b/src/views/login/PhoneLogin.vue index 7022c4fe0..1d41c616f 100644 --- a/src/views/login/PhoneLogin.vue +++ b/src/views/login/PhoneLogin.vue @@ -1,5 +1,19 @@