]> Repos - mime-chat/commitdiff
remove auth from sesssion
authorriqo <hernandeze2@xavier.edu>
Sat, 22 May 2021 20:02:49 +0000 (15:02 -0500)
committerriqo <hernandeze2@xavier.edu>
Sat, 22 May 2021 20:02:49 +0000 (15:02 -0500)
src/App.vue
src/background/init.ts
src/background/session.ts
src/components/messenger.vue

index 320b62f88aa83aca9f6ad41690a534386e7a0df5..86d1007a06c84b4ee1be576803403cc3b79a3f0b 100644 (file)
@@ -41,6 +41,7 @@ import Messenger from "@/components/messenger.vue";
 import Login from "@/components/login.vue";
 
 export default defineComponent({
+
   components: {
     Splash,
     Messenger,
@@ -72,7 +73,8 @@ export default defineComponent({
       }
 
       // Set profile and newMessages.
-      profile.value = payload.message.profile;
+      // profile.value = payload.message.profile;
+      profile.value = true;
       newMessages.value = payload.message.newMessages;
 
       ready.value = true;
index a17716c75f1e1ebbe63be414e5adaa3447bd3a42..5150d9f1299e6fd7a54be7b99c975ac2cd6da377 100644 (file)
@@ -3,7 +3,7 @@
 
 import { app, dialog } from "electron";
 import { createWindow } from './window';
-import { initSession } from './session';
+import { initSession, updateState } from './session';
 import { initAudioIO, stopStream } from './audio';
 import { backgroundMitt } from '@/modules/emitter';
 
@@ -15,7 +15,7 @@ backgroundMitt.on('window-active', (state: boolean) => {
 });
 
 // Auto updating.
-const { autoUpdater } = require('electron-updater')
+const { autoUpdater } = require('electron-updater');
 autoUpdater.requestHeaders = { 'PRIVATE-TOKEN': 'mvvgWYwWnot4bisiQMh_' }
 
 autoUpdater.on('update-available', (info: any) => {
@@ -38,6 +38,13 @@ autoUpdater.on('update-downloaded', (info: any) => {
 
 })
 
+
+interface Profile {
+    crimataId: string;
+    alias: string;
+    initials: string;
+}
+
 // Run when electron app is initialized.
 async function main() {
     console.log("MAIN:Initializing Electron App.")
@@ -45,6 +52,17 @@ async function main() {
     // Must wait til window is created.
     await createWindow();
 
+    // authenticate against business backend
+    const auth = async (crimataId: string): Promise<Profile | null> => {
+        updateState({key: "", profile: {
+            crimataId: "",
+            alias: "",
+            initials: ""
+        }});
+        return null
+    };
+    auth('');
+
     // Instantiate socket session with crimata-platorm.
     initSession();
 
index 35773c8e92cbc2f8e6a489954d4c9d70fe8e8841..0a8b91d681b20267a3d30faad84cd20af5b62e02 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Creates a websocket session with Crimata Servers.
- * 
- * Connects to Servers and attempts key authentication. Server will respond 
- * with key and user profile. We send the profile to the browser. We also 
- * resend this information on new broser window. We then serve as a 
- * communication interface between the window and the servers. It will 
+ *
+ * Connects to Servers and attempts key authentication. Server will respond
+ * with key and user profile. We send the profile to the browser. We also
+ * resend this information on new broser window. We then serve as a
+ * communication interface between the window and the servers. It will
  * automatically try to reconnect on websocket disconnect.
  */
 
@@ -16,7 +16,7 @@ import useWebSockets from "@/modules/websockets";
 
 import { play } from "./audio";
 import { renderMessage } from "@/modules/message";
-import { AuthProtocol, SessionState, Profile } from "@/types"; 
+import { AuthProtocol, SessionState, Profile } from "@/types";
 
 let win = true;
 
@@ -27,7 +27,7 @@ let state: SessionState;
 let profile: Profile | boolean;
 
 // Called when server sends auth message.
-const updateState = (res: AuthProtocol) => {
+export const updateState = (res: AuthProtocol) => {
     console.log("SESS:Auth message received: \n" +
                 `    key: ${res.key}\n` +
                 `    alias: ${res.profile}`)
@@ -71,12 +71,10 @@ const onMessage = (data: string) => {
     let message = JSON.parse(data)
 
     // AuthProtocol message.
-    if (message.hasOwnProperty("key")) {
-        updateState(message)
-    }
+    updateState(message)
 
     // Standard message.
-    else if (message.content) {
+    if (message.content) {
 
         // Convert to render message
         message = renderMessage(
@@ -93,7 +91,7 @@ const onMessage = (data: string) => {
             }
             ipcEmit("render-message", message)
         }
-        
+
         else {
             console.log("SESS:No window: saving message.")
             state.newMessages.push(message);
@@ -110,14 +108,14 @@ const onMessage = (data: string) => {
 
 // When socket connects, we update state.
 const onOpen = () => {
-    console.log(`SESS:Sending key: ${state.key}`)
+    // console.log(`SESS:Sending key: ${state.key}`)
 
     if (state) {
-        sendMessage({
-            "key": state.key,
-            "usr": false,
-            "pwd": false
-        })
+        // sendMessage({
+        //     "key": state.key,
+        //     "usr": false,
+        //     "pwd": false
+        // })
     }
 }
 
@@ -128,12 +126,15 @@ const { createSocket, sendMessage } = useWebSockets(onMessage, onOpen);
 const onClientMessage = (_event: IpcMainEvent, payload: any) => {
     console.log("New client message")
 
-    const success = sendMessage(payload)
+    if (payload.hasOwnProperty("key")) {
+        return
+    }
+    const success = sendMessage(payload);
 
     if (!success) {
-        console.log("Unable to send message: ", payload)
+        console.log("Unable to send message: ", payload);
     }
-    
+
 }
 
 // Call this to initialize session with Crimata servers.
index edc50a1954d78bba3bdeaf93390d41e1fdc4829b..f5512a918f64a22d1c21a95a4bd008cc63da9603 100644 (file)
@@ -6,9 +6,9 @@
 
   <!-- List of message bubbles. -->
   <div id="messenger">
-    <Message 
-      v-for="message in messages" 
-      :message="message[1]" 
+    <Message
+      v-for="message in messages"
+      :message="message[1]"
       :key="message[0]"
     />
   </div>
@@ -48,25 +48,24 @@ export default defineComponent({
 
       // Load the message history.
       if (crimataId === window.localStorage.getItem("last_usr")) {
-        prepMessageView(props.newMessages)
+        prepMessageView(props.newMessages);
       } else {
-        messages.value.clear()
+        messages.value.clear();
       }
 
       // New content listeners.
       emitter.on('self-message', (message) => updateMessageView(message));
       window.ipcRenderer.on("render-message", (_e: any, payload: any) => {
-        updateMessageView(payload.message)
+        updateMessageView(payload.message);
       });
 
       // Save the usr for next time.
-      window.localStorage.setItem("last_usr", crimataId)
+      window.localStorage.setItem("last_usr", crimataId);
 
     });
 
     onUnmounted(() => {
       window.ipcRenderer.removeAllListeners("render-message");
-      window.ipcRenderer.removeAllListeners("annotate-message");
       emitter.all.clear();
     });