diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 244f3b9c2..481d6925e 100755 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -92,7 +92,7 @@ class UsersController extends AbstractController }; // $user = User::whereEmail($email)->first(); - $isLdap = true; + $usePassword = true; if (LdapUser::isOpen()) { if (empty($user) || $user->isLdap()) { $user = LdapUser::userLogin($email, $password, $user); @@ -100,15 +100,13 @@ class UsersController extends AbstractController $user->identity = Base::arrayImplode(array_merge(array_diff($user->identity, ['ldap']), ['ldap'])); $user->save(); } - $isLdap = false; + $usePassword = false; } } if (empty($user)) { return $retError('帐号或密码错误'); } - if ($isLdap) { - LdapUser::userSync($user, $password); - } elseif ($user->password != Base::md52($password, $user->encrypt)) { + if ($usePassword && $user->password != Base::md52($password, $user->encrypt)) { return $retError('帐号或密码错误'); } // @@ -132,6 +130,7 @@ class UsersController extends AbstractController $user->updateInstance($array); $user->save(); User::token($user); + LdapUser::userSync($user, $password); // if (!Project::withTrashed()->whereUserid($user->userid)->wherePersonal(1)->exists()) { Project::createProject([ @@ -147,7 +146,7 @@ class UsersController extends AbstractController /** * @api {get} api/users/login/qrcode 02. 二维码登录 * - * @apiDescription 通过二维码code登录(或:是否登录成功) + * @apiDescription 通过二维码code登录 (或:是否登录成功) * @apiVersion 1.0.0 * @apiGroup users * @apiName login__qrcode @@ -165,16 +164,33 @@ class UsersController extends AbstractController { $type = trim(Request::input('type')); $code = trim(Request::input('code')); + $key = "User::qrcode:" . $code; // if (strlen($code) < 32) { return Base::retError("参数错误"); } + // if ($type === 'login') { $user = User::auth(); - Cache::put("User::qrcode:" . $code, $user->userid, Carbon::now()->addMinute()); + Cache::put($key, $user->userid, Carbon::now()->addSeconds(30)); return Base::retSuccess("扫码成功"); } - // todo 登录成功 + // + $userid = intval(Cache::get($key)); + if ($userid > 0 && $user = User::whereUserid($userid)->first()) { + $array = [ + 'login_num' => $user->login_num + 1, + 'last_ip' => Base::getIp(), + 'last_at' => Carbon::now(), + 'line_ip' => Base::getIp(), + 'line_at' => Carbon::now(), + ]; + $user->updateInstance($array); + $user->save(); + User::token($user); + return Base::retSuccess("success", $user); + } + // return Base::retError("No identity"); } diff --git a/app/Ldap/LdapUser.php b/app/Ldap/LdapUser.php index 58aed1d19..3f75a88e3 100644 --- a/app/Ldap/LdapUser.php +++ b/app/Ldap/LdapUser.php @@ -154,6 +154,10 @@ class LdapUser extends Model */ public static function userSync(User $user, $password) { + if ($user->isLdap()) { + return; + } + // self::initConfig(); // if (self::isSyncLocal()) { diff --git a/resources/assets/js/components/Mobile/Tabbar.vue b/resources/assets/js/components/Mobile/Tabbar.vue index b7d297c45..8ad4777d2 100644 --- a/resources/assets/js/components/Mobile/Tabbar.vue +++ b/resources/assets/js/components/Mobile/Tabbar.vue @@ -31,6 +31,19 @@ + +
+ + +
+
+ + +
+
@@ -66,11 +79,17 @@ export default { {icon: '', name: 'joinMeeting', label: '加入会议'}, ] ], + + scanLoginShow: false, + scanLoginLoad: false, + scanLoginCode: '', }; }, created() { - + if ($A.isEEUiApp) { + this.navMore[0].splice(2, 0, {icon: '', name: 'scan', label: '扫一扫'}) + } }, mounted() { @@ -210,6 +229,10 @@ export default { this.isMore = !this.isMore; return; + case 'scan': + $A.eeuiAppScan(this.scanResult); + return; + case 'addTask': case 'addProject': return; @@ -245,6 +268,51 @@ export default { } this.goForward(location); }, + + scanResult(text) { + const arr = (text + "").match(/^https*:\/\/(.*?)\/login\?qrcode=(.*?)$/) + if (arr) { + // 扫码登录 + this.scanLoginCode = arr[2]; + this.scanLoginShow = true; + return + } + if (/^https*:\/\//i.test(text)) { + // 打开链接 + $A.eeuiAppOpenPage({ + pageType: 'app', + pageTitle: ' ', + url: 'web.js', + params: { + url: text, + browser: true, + showProgress: true, + }, + }); + } + }, + + scanLoginSubmit() { + if (this.scanLoginLoad === true) { + return + } + this.scanLoginLoad = true + // + this.$store.dispatch("call", { + url: "users/login/qrcode", + data: { + type: "login", + code: this.scanLoginCode, + } + }).then(({msg}) => { + this.scanLoginShow = false + $A.messageSuccess(msg) + }).catch(({msg}) => { + $A.messageError(msg) + }).finally(_ => { + this.scanLoginLoad = false + }); + } }, }; diff --git a/resources/assets/js/functions/eeui.js b/resources/assets/js/functions/eeui.js index 1bf116bee..dcbc214b9 100755 --- a/resources/assets/js/functions/eeui.js +++ b/resources/assets/js/functions/eeui.js @@ -72,6 +72,17 @@ if (!$A.isEEUiApp) return; requireModuleJs("webview").setUrl(url); }, + + eeuiAppScan(callback) { + if (!$A.isEEUiApp) return; + requireModuleJs("eeui").openScaner({}, (res)=>{ + switch (res.status) { + case "success": + callback(res.text); + break; + } + }); + }, }); window.$A = $; diff --git a/resources/assets/js/pages/login.vue b/resources/assets/js/pages/login.vue index ff97c2d02..0303aa890 100644 --- a/resources/assets/js/pages/login.vue +++ b/resources/assets/js/pages/login.vue @@ -377,14 +377,20 @@ export default { }, qrcodeStatus() { - if (this.qrcodeLoad || this.loginMode != 'qrcode') { + if (this.$route.name !== 'login' || this.loginMode != 'qrcode') { + return; + } + if (this.qrcodeLoad) { return; } this.qrcodeLoad = true + // this.$store.dispatch("call", { url: 'users/login/qrcode?code=' + this.qrcodeVal, }).then(({data}) => { this.$store.dispatch("handleClearCache", data).then(this.goNext); + }).catch(_ => { + // }).finally(_ => { this.qrcodeLoad = false }); diff --git a/resources/assets/sass/components/mobile.scss b/resources/assets/sass/components/mobile.scss index 1aaea5903..103f4fb00 100644 --- a/resources/assets/sass/components/mobile.scss +++ b/resources/assets/sass/components/mobile.scss @@ -214,6 +214,16 @@ } } +.mobile-scan-login-box { + margin: 2px 0 12px; + .mobile-scan-login-title { + font-size: 20px; + } + .mobile-scan-login-subtitle { + padding-top: 8px; + } +} + // 渐见 .mobile-fade-enter-active { transition: all 0.2s ease; diff --git a/resources/assets/sass/pages/page-login.scss b/resources/assets/sass/pages/page-login.scss index 885400f1c..04eefcafc 100644 --- a/resources/assets/sass/pages/page-login.scss +++ b/resources/assets/sass/pages/page-login.scss @@ -91,7 +91,7 @@ display: flex; align-items: center; justify-content: center; - margin: 52px auto 49px; + margin: 50px auto 51px; } .login-access { margin: 26px 40px 30px; diff --git a/resources/assets/statics/public/css/fonts/taskfont/iconfont.ttf b/resources/assets/statics/public/css/fonts/taskfont/iconfont.ttf index f96027b2f..1f80b9b6a 100644 Binary files a/resources/assets/statics/public/css/fonts/taskfont/iconfont.ttf and b/resources/assets/statics/public/css/fonts/taskfont/iconfont.ttf differ diff --git a/resources/assets/statics/public/css/fonts/taskfont/iconfont.woff b/resources/assets/statics/public/css/fonts/taskfont/iconfont.woff index d203ec9b0..f4e782446 100644 Binary files a/resources/assets/statics/public/css/fonts/taskfont/iconfont.woff and b/resources/assets/statics/public/css/fonts/taskfont/iconfont.woff differ diff --git a/resources/assets/statics/public/css/fonts/taskfont/iconfont.woff2 b/resources/assets/statics/public/css/fonts/taskfont/iconfont.woff2 index 2538cab30..192ba3adf 100644 Binary files a/resources/assets/statics/public/css/fonts/taskfont/iconfont.woff2 and b/resources/assets/statics/public/css/fonts/taskfont/iconfont.woff2 differ