mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 19:23:26 +00:00
完善扫码登录
This commit is contained in:
parent
49ac519a5e
commit
f3e41f2ff4
@ -92,7 +92,7 @@ class UsersController extends AbstractController
|
|||||||
};
|
};
|
||||||
//
|
//
|
||||||
$user = User::whereEmail($email)->first();
|
$user = User::whereEmail($email)->first();
|
||||||
$isLdap = true;
|
$usePassword = true;
|
||||||
if (LdapUser::isOpen()) {
|
if (LdapUser::isOpen()) {
|
||||||
if (empty($user) || $user->isLdap()) {
|
if (empty($user) || $user->isLdap()) {
|
||||||
$user = LdapUser::userLogin($email, $password, $user);
|
$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->identity = Base::arrayImplode(array_merge(array_diff($user->identity, ['ldap']), ['ldap']));
|
||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
$isLdap = false;
|
$usePassword = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
return $retError('帐号或密码错误');
|
return $retError('帐号或密码错误');
|
||||||
}
|
}
|
||||||
if ($isLdap) {
|
if ($usePassword && $user->password != Base::md52($password, $user->encrypt)) {
|
||||||
LdapUser::userSync($user, $password);
|
|
||||||
} elseif ($user->password != Base::md52($password, $user->encrypt)) {
|
|
||||||
return $retError('帐号或密码错误');
|
return $retError('帐号或密码错误');
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
@ -132,6 +130,7 @@ class UsersController extends AbstractController
|
|||||||
$user->updateInstance($array);
|
$user->updateInstance($array);
|
||||||
$user->save();
|
$user->save();
|
||||||
User::token($user);
|
User::token($user);
|
||||||
|
LdapUser::userSync($user, $password);
|
||||||
//
|
//
|
||||||
if (!Project::withTrashed()->whereUserid($user->userid)->wherePersonal(1)->exists()) {
|
if (!Project::withTrashed()->whereUserid($user->userid)->wherePersonal(1)->exists()) {
|
||||||
Project::createProject([
|
Project::createProject([
|
||||||
@ -165,16 +164,33 @@ class UsersController extends AbstractController
|
|||||||
{
|
{
|
||||||
$type = trim(Request::input('type'));
|
$type = trim(Request::input('type'));
|
||||||
$code = trim(Request::input('code'));
|
$code = trim(Request::input('code'));
|
||||||
|
$key = "User::qrcode:" . $code;
|
||||||
//
|
//
|
||||||
if (strlen($code) < 32) {
|
if (strlen($code) < 32) {
|
||||||
return Base::retError("参数错误");
|
return Base::retError("参数错误");
|
||||||
}
|
}
|
||||||
|
//
|
||||||
if ($type === 'login') {
|
if ($type === 'login') {
|
||||||
$user = User::auth();
|
$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("扫码成功");
|
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");
|
return Base::retError("No identity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -154,6 +154,10 @@ class LdapUser extends Model
|
|||||||
*/
|
*/
|
||||||
public static function userSync(User $user, $password)
|
public static function userSync(User $user, $password)
|
||||||
{
|
{
|
||||||
|
if ($user->isLdap()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//
|
||||||
self::initConfig();
|
self::initConfig();
|
||||||
//
|
//
|
||||||
if (self::isSyncLocal()) {
|
if (self::isSyncLocal()) {
|
||||||
|
|||||||
@ -31,6 +31,19 @@
|
|||||||
</template>
|
</template>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<Modal
|
||||||
|
v-model="scanLoginShow"
|
||||||
|
:title="$L('扫码登录')"
|
||||||
|
:mask-closable="false">
|
||||||
|
<div class="mobile-scan-login-box">
|
||||||
|
<div class="mobile-scan-login-title">{{$L(`你好,扫码确认登录`)}}</div>
|
||||||
|
<div class="mobile-scan-login-subtitle">「{{$L('为确保帐号安全,请确认是本人操作')}}」</div>
|
||||||
|
</div>
|
||||||
|
<div slot="footer" class="adaption">
|
||||||
|
<Button type="default" @click="scanLoginShow=false">{{$L('取消登录')}}</Button>
|
||||||
|
<Button type="primary" :loading="scanLoginLoad" @click="scanLoginSubmit">{{$L('确认登录')}}</Button>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -66,11 +79,17 @@ export default {
|
|||||||
{icon: '', name: 'joinMeeting', label: '加入会议'},
|
{icon: '', name: 'joinMeeting', label: '加入会议'},
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
|
scanLoginShow: false,
|
||||||
|
scanLoginLoad: false,
|
||||||
|
scanLoginCode: '',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
|
if ($A.isEEUiApp) {
|
||||||
|
this.navMore[0].splice(2, 0, {icon: '', name: 'scan', label: '扫一扫'})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
@ -210,6 +229,10 @@ export default {
|
|||||||
this.isMore = !this.isMore;
|
this.isMore = !this.isMore;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case 'scan':
|
||||||
|
$A.eeuiAppScan(this.scanResult);
|
||||||
|
return;
|
||||||
|
|
||||||
case 'addTask':
|
case 'addTask':
|
||||||
case 'addProject':
|
case 'addProject':
|
||||||
return;
|
return;
|
||||||
@ -245,6 +268,51 @@ export default {
|
|||||||
}
|
}
|
||||||
this.goForward(location);
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
11
resources/assets/js/functions/eeui.js
vendored
11
resources/assets/js/functions/eeui.js
vendored
@ -72,6 +72,17 @@
|
|||||||
if (!$A.isEEUiApp) return;
|
if (!$A.isEEUiApp) return;
|
||||||
requireModuleJs("webview").setUrl(url);
|
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 = $;
|
window.$A = $;
|
||||||
|
|||||||
@ -377,14 +377,20 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
qrcodeStatus() {
|
qrcodeStatus() {
|
||||||
if (this.qrcodeLoad || this.loginMode != 'qrcode') {
|
if (this.$route.name !== 'login' || this.loginMode != 'qrcode') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.qrcodeLoad) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.qrcodeLoad = true
|
this.qrcodeLoad = true
|
||||||
|
//
|
||||||
this.$store.dispatch("call", {
|
this.$store.dispatch("call", {
|
||||||
url: 'users/login/qrcode?code=' + this.qrcodeVal,
|
url: 'users/login/qrcode?code=' + this.qrcodeVal,
|
||||||
}).then(({data}) => {
|
}).then(({data}) => {
|
||||||
this.$store.dispatch("handleClearCache", data).then(this.goNext);
|
this.$store.dispatch("handleClearCache", data).then(this.goNext);
|
||||||
|
}).catch(_ => {
|
||||||
|
//
|
||||||
}).finally(_ => {
|
}).finally(_ => {
|
||||||
this.qrcodeLoad = false
|
this.qrcodeLoad = false
|
||||||
});
|
});
|
||||||
|
|||||||
10
resources/assets/sass/components/mobile.scss
vendored
10
resources/assets/sass/components/mobile.scss
vendored
@ -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 {
|
.mobile-fade-enter-active {
|
||||||
transition: all 0.2s ease;
|
transition: all 0.2s ease;
|
||||||
|
|||||||
2
resources/assets/sass/pages/page-login.scss
vendored
2
resources/assets/sass/pages/page-login.scss
vendored
@ -91,7 +91,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin: 52px auto 49px;
|
margin: 50px auto 51px;
|
||||||
}
|
}
|
||||||
.login-access {
|
.login-access {
|
||||||
margin: 26px 40px 30px;
|
margin: 26px 40px 30px;
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user