Merge branch 'abp' of https://gitee.com/ccnetcore/Yi into abp
This commit is contained in:
@@ -40,7 +40,7 @@ namespace Yi.Framework.Rbac.Application.Services.Authentication
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
[HttpGet("auth/oauth/login/{scheme}")]
|
||||
public async Task<string> AuthOauthLoginAsync([FromRoute] string scheme, [FromQuery] string code)
|
||||
public async Task<object> AuthOauthLoginAsync([FromRoute] string scheme, [FromQuery] string code)
|
||||
{
|
||||
(var openId, var _) = await GetOpenIdAndNameAsync(scheme);
|
||||
var authEntity = await _repository.GetAsync(x => x.OpenId == openId && x.AuthType == scheme);
|
||||
@@ -50,7 +50,7 @@ namespace Yi.Framework.Rbac.Application.Services.Authentication
|
||||
throw new UserFriendlyException("第三方登录失败,请先注册后,在个人中心进行绑定该第三方后使用");
|
||||
}
|
||||
var accessToken = await _accountManager.GetTokenByUserIdAsync(authEntity.UserId);
|
||||
return accessToken;
|
||||
return new { token= accessToken };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -164,5 +164,6 @@ export default function useAuths(opt) {
|
||||
logoutFun,
|
||||
clearStorage,
|
||||
registerFun,
|
||||
loginSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ const type = ref(route.query.state);
|
||||
const message = ref("");
|
||||
const scheme = ref("");
|
||||
const authData = ref("");
|
||||
const closeWindow = () => {
|
||||
setTimeout(() => {
|
||||
window.close();
|
||||
}, 2000);
|
||||
};
|
||||
watch(
|
||||
() => code.value,
|
||||
async (val) => {
|
||||
@@ -31,19 +36,25 @@ watch(
|
||||
scheme.value = "QQ";
|
||||
break;
|
||||
}
|
||||
if (type.value === "0") {
|
||||
const { data } = await authOtherLogin({ code: val }, scheme.value);
|
||||
authData.value = data;
|
||||
} else if (type.value === "1") {
|
||||
const { data } = await authOtherBind({ code: val }, scheme.value);
|
||||
authData.value = data;
|
||||
try {
|
||||
if (type.value === "0") {
|
||||
const { data } = await authOtherLogin({ code: val }, scheme.value);
|
||||
authData.value = data;
|
||||
} else if (type.value === "1") {
|
||||
const { data } = await authOtherBind({ code: val }, scheme.value);
|
||||
authData.value = data;
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.status === 403) {
|
||||
closeWindow();
|
||||
}
|
||||
}
|
||||
window.opener.postMessage({
|
||||
authData: JSON.stringify(authData.value),
|
||||
type: scheme.value,
|
||||
});
|
||||
console.log(authData.value, "我是打开的窗口页");
|
||||
message.value = "授权成功";
|
||||
closeWindow();
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
|
||||
@@ -166,7 +166,7 @@ import useUserStore from "@/stores/user";
|
||||
import useConfigStore from "@/stores/config";
|
||||
|
||||
const configStore = useConfigStore();
|
||||
const { loginFun, registerFun } = useAuths();
|
||||
const { loginFun, registerFun, loginSuccess } = useAuths();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const loginFormRef = ref();
|
||||
@@ -318,6 +318,15 @@ const handleGiteeLogin = () => {
|
||||
"width=500,height=500,left=50,top=50"
|
||||
);
|
||||
};
|
||||
|
||||
window.addEventListener("message", async (e) => {
|
||||
const { authData, type } = e.data;
|
||||
console.log(authData, "传到登录页的值");
|
||||
if (authData) {
|
||||
await loginSuccess({ data: JSON.parse(authData) });
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
.login {
|
||||
|
||||
@@ -131,10 +131,7 @@ const handleGiteeLogin = () => {
|
||||
};
|
||||
|
||||
window.addEventListener("message", async (e) => {
|
||||
console.log(e, "我是账号设置页");
|
||||
const { authData, type } = e.data;
|
||||
if (e.data) {
|
||||
console.log(authData, type, "2333");
|
||||
await checkList();
|
||||
window.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user