Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stage #1908

Merged
merged 3 commits into from
Mar 7, 2023
Merged

Stage #1908

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"vue-sidebar-menu": "^4.7.4",
"vue-stepper": "^1.4.2",
"vue-sweetalert2": "^5.0.2",
"vuedraggable": "^2.24.3",
"vue-vanilla-datetime-picker": "^1.2.0",
"vuedraggable": "^2.24.3",
"vuejs-paginate": "^2.1.0",
"vuex": "^3.0.0",
"watchify": "^4.0.0",
Expand All @@ -69,6 +69,7 @@
"@vue/cli-plugin-unit-mocha": "^3.0.0-rc.10",
"@vue/cli-service": "^3.0.0-rc.10",
"@vue/test-utils": "^1.0.0-beta.20",
"babel-eslint": "^10.1.0",
"babel-preset-es2015": "^6.24.1",
"babelify": "^7.2.0",
"chai": "^4.1.2",
Expand Down
53 changes: 53 additions & 0 deletions src/components/login/Auth.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template></template>

<script>

import config from '../../config';
export default {
name: 'Auth',
components: {},

async mounted() {
const routeHash = this.$route.hash;
const accessToken = routeHash.split("&")[0].split("=")[1];
const authToken = routeHash.split("&")[5].split("=")[1];
const payload = {
provider: 'Google',
accessToken,
authToken
}

const resp = await fetch(config.studioServer.BASE_URL + 'api/v1/login', {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",

}
, body: JSON.stringify(payload),
method: 'POST'
})

const data = await resp.json()
if (data.authToken) {
localStorage.setItem('authToken', data.authToken)
const path = localStorage.getItem('path')
if (path) {
return this.$router.push(path)
} else {
return this.$router.push('/admin/dashboard')

}

}


this.$router.push({ path: "/" })

}

};


</script>

<style></style>
117 changes: 61 additions & 56 deletions src/components/participant/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Session expired. <a href="#" class="ml-2 alert-link" @click="reloadQR">Click to reload.</a>
</div>
</template>
<template v-else-if="value && value != ''">
<template >
<b-button class="btn-login button-theme" :style="buttonThemeCss" @click.prevent="openWalletAfterRecaptcha()">Click To Login
<!--<vue-recaptcha
ref="recaptcha"
Expand All @@ -30,6 +30,7 @@
<script>
import config from "../../config";
import Messages from "../../utils/messages/participants/en";
import loginWithGoogle from '../../mixins/loginWithGoogle'
import url from "url";
export default {
components: { },
Expand Down Expand Up @@ -60,63 +61,65 @@ export default {
};
},
async created() {
let baseUrl = this.$config.studioServer.BASE_URL;
let websocketUrl = "ws://localhost:3003";
localStorage.setItem('path',this.$route.fullPath)
// let baseUrl = this.$config.studioServer.BASE_URL;
// let websocketUrl = "ws://localhost:3003";

let parsedUrl = {};
try {
parsedUrl = url.parse(baseUrl);
// let parsedUrl = {};
// try {
// parsedUrl = url.parse(baseUrl);

websocketUrl =
parsedUrl.protocol === "https:" ?
`wss://${parsedUrl.host}` :
`ws://${parsedUrl.host}`;
} catch (e) {
websocketUrl = "ws://localhost:3003";
}
if (websocketUrl[websocketUrl.length - 1] == "/") {
websocketUrl = websocketUrl.substring(0, websocketUrl.length - 1);
}
// websocketUrl =
// parsedUrl.protocol === "https:" ?
// `wss://${parsedUrl.host}` :
// `ws://${parsedUrl.host}`;
// } catch (e) {
// websocketUrl = "ws://localhost:3003";
// }
// if (websocketUrl[websocketUrl.length - 1] == "/") {
// websocketUrl = websocketUrl.substring(0, websocketUrl.length - 1);
// }

this.isLoading = true;
var _this = this;
// this.isLoading = true;
// var _this = this;

// take it in the env
_this.socketMessage = Messages.EVENT.LOGIN.SOCKET_INIT;
this.connection = new WebSocket(this.$config.websocketUrl);
this.connection.onopen = function() {
_this.socketMessage = Messages.EVENT.LOGIN.SOCKET_OPEN;
};
// // take it in the env
// _this.socketMessage = Messages.EVENT.LOGIN.SOCKET_INIT;
// this.connection = new WebSocket(this.$config.websocketUrl);
// this.connection.onopen = function() {
// _this.socketMessage = Messages.EVENT.LOGIN.SOCKET_OPEN;
// };

this.connection.onmessage = ({ data }) => {
let messageData = JSON.parse(data);
if (messageData.op == "init") {
_this.isLoading = false;
messageData.data['provider'] = 'google';
_this.value = JSON.stringify(messageData.data);
_this.socketMessage = null;
} else if (messageData.op == "end") {
_this.connection.close();
const authorizationToken = messageData.data.hypersign ? messageData.data.hypersign.data.accessToken : messageData.data.token;
// this.connection.onmessage = ({ data }) => {
// let messageData = JSON.parse(data);
// if (messageData.op == "init") {
// _this.isLoading = false;
// messageData.data['provider'] = 'google';
// _this.value = JSON.stringify(messageData.data);
// _this.socketMessage = null;
// } else if (messageData.op == "end") {
// _this.connection.close();
// const authorizationToken = messageData.data.hypersign ? messageData.data.hypersign.data.accessToken : messageData.data.token;

// console.log("Emitting authentoken event")
// // console.log("Emitting authentoken event")

localStorage.setItem("authToken", authorizationToken);
this.$emit("AuthTokenUpdateEvent", authorizationToken);
// localStorage.setItem("authToken", authorizationToken);
// this.$emit("AuthTokenUpdateEvent", authorizationToken);


} else if (messageData.op == "reload") {
_this.QRRefresh = true;
_this.connection.close(4001, messageData.data.clientId);
}
};
// } else if (messageData.op == "reload") {
// _this.QRRefresh = true;
// _this.connection.close(4001, messageData.data.clientId);
// }
// };

this.connection.onerror = function(error) {
console.log(error);
_this.error = true;
_this.socketMessage = Messages.EVENT.LOGIN.SOCKET_ERROR;
};
// this.connection.onerror = function(error) {
// console.log(error);
// _this.error = true;
// _this.socketMessage = Messages.EVENT.LOGIN.SOCKET_ERROR;
// };
},
mixins:[loginWithGoogle],
methods: {
reloadQR() {
window.location.reload();
Expand All @@ -125,15 +128,17 @@ export default {
this.$refs.recaptcha.execute()
},
openWalletAfterRecaptcha(){
if (this.value != "") {
this.walletWindow = window.open(
`${this.$config.webWalletAddress}/deeplink?url=${this.value}`,
"popUpWindow",
`height=800,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes`
);
} else {
// console.log("this value is not")
}
this.loginWithGoogle()

// if (this.value != "") {
// this.walletWindow = window.open(
// `${this.$config.webWalletAddress}/deeplink?url=${this.value}`,
// "popUpWindow",
// `height=800,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes`
// );
// } else {
// // console.log("this value is not")
// }
},
onCaptchaExpired: function() {
// console.log("Captcha expired");
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const config = {
mobileWalletAddress: urlSanitizer(process.env.VUE_APP_MOBILEWALLET_URL, false),
websocketUrl: urlSanitizer(process.env.VUE_APP_SERVER_WEBSOCKET_URL, true),
auth0Domain: urlSanitizer(process.env.VUE_APP_AUTH0_DOMAIN, false),
auth0LOGINCLIENTID:process.env.VUE_APP_AUTH0_LOGIN_CLIENT_ID,
auth0ClinetId: process.env.VUE_APP_AUTH0_CLIENT_ID,
telegramBotId: process.env.VUE_APP_TELEGRAM_BOT_ID,
kommunicateAppId: process.env.VUE_APP_KOMMINICATE_APP_ID,
Expand Down
17 changes: 17 additions & 0 deletions src/mixins/loginWithGoogle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import webAuth from '../utils/auth0Connection';

export default{
methods: {
loginWithGoogle(){
webAuth.authorize(
{
connection: "google-oauth2",
redirectUri: window.location.origin + "/auth/google?",


});
}
},


}
6 changes: 5 additions & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Router from "vue-router";
import config from "./config";
import fetch from "node-fetch";
import eventBus from "./eventBus";

import Auth from './components/login/Auth'
Vue.use(Router);

const router = new Router({
Expand Down Expand Up @@ -50,6 +50,10 @@ const router = new Router({
component: () =>
import ( /* webpackChunkName: "adminLogin" */ "./views/Invitation.vue"),
},
{
path:'/auth/google',
component:Auth
},
{
path: "/admin/login",
name: "AdminLogin",
Expand Down
10 changes: 10 additions & 0 deletions src/utils/auth0Connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import auth0 from "auth0-js";
import config from '../config'
const newWebAuth = new auth0.WebAuth({
domain: config.auth0Domain,
clientID: config.auth0LOGINCLIENTID,
responseType: "token id_token",
scope: "openid profile email",
})

export default newWebAuth
Loading