dcc61c8e by Jonille Arreglo

Merge branch '27190_loggedin' of https://gitlab.baytech.ph/baytech/chatgpt.ai-pro.org into 1DEVT

# Conflicts:
#	client/src/App.js
2 parents b804a97b 68aee7cc
1 let aiUser = btutil_getCookie('aiwp_logged_in');
2 let objBody = { aiwp_logged_in: aiUser };
3
4 let params = [];
5 params['objBody'] = objBody;
6 params['strUrl'] = 'https://test.api.ai-pro.org/e/v1/authenticate/'; //use envvar for https://test.api.ai-pro.org/ only
7
8 btutil_checkAuthentication(params, cbCheckAuthentication, cbErrCheckAuthentication);
9 function cbCheckAuthentication(res) {
10 // console.log(res);
11 if (!res.success) {
12 window.location.href = "https://ai-pro.org/redirect-account-required/"; //use envvar
13 } else {
14 document.getElementById("root").classList.add("active");
15 }
16 }
17
18 function cbErrCheckAuthentication(res) {
19 console.log(res);
20 }
...\ No newline at end of file ...\ No newline at end of file
...@@ -26,6 +26,33 @@ ...@@ -26,6 +26,33 @@
26 Learn how to configure a non-root public URL by running `npm run build`. 26 Learn how to configure a non-root public URL by running `npm run build`.
27 --> 27 -->
28 <title>AI-Pro ChatGPT</title> 28 <title>AI-Pro ChatGPT</title>
29 <script src='%REACT_APP_BTCOMPONENT_S3_URL%/common/btutil-authenticate.min.js'></script>
30 <script>
31 let aiUser = btutil_getCookie('aiwp_logged_in');
32 if(!aiUser) {
33 window.location.href = '%REACT_APP_AUTH_FAILED_REDIRECTION_URL%';
34 } else {
35 let objBody = { aiwp_logged_in: aiUser };
36
37 let params = [];
38 params['objBody'] = objBody;
39 params['strUrl'] = '%REACT_APP_EXTERNAL_API_URL%/e/v1/authenticate/';
40
41 btutil_checkAuthentication(params, cbCheckAuthentication, cbErrCheckAuthentication);
42 function cbCheckAuthentication(res) {
43 // console.log(res);
44 if (!res.success) {
45 window.location.href = '%REACT_APP_AUTH_FAILED_REDIRECTION_URL%';
46 } else {
47 document.getElementById("root").classList.add("active");
48 }
49 }
50
51 function cbErrCheckAuthentication(res) {
52 console.log(res);
53 }
54 }
55 </script>
29 </head> 56 </head>
30 <body> 57 <body>
31 <noscript>You need to enable JavaScript to run this app.</noscript> 58 <noscript>You need to enable JavaScript to run this app.</noscript>
......
...@@ -47,7 +47,9 @@ function App() { ...@@ -47,7 +47,9 @@ function App() {
47 let model_list = []; 47 let model_list = [];
48 for( var i = 1; i < data.models.data.length; i++ ) { 48 for( var i = 1; i < data.models.data.length; i++ ) {
49 let model = data.models.data[i]; 49 let model = data.models.data[i];
50 if(model.id != "whisper-1") model_list.push(model); 50 if( !(model.id == "whisper-1"
51 || model.id == "gpt-4"
52 || model.id == "gpt-4-0314") ) model_list.push(model);
51 } 53 }
52 setModels(model_list) 54 setModels(model_list)
53 }) 55 })
...@@ -55,6 +57,28 @@ function App() { ...@@ -55,6 +57,28 @@ function App() {
55 57
56 async function handleSubmit(e){ 58 async function handleSubmit(e){
57 e.preventDefault(); 59 e.preventDefault();
60 let aiUser = window.btutil_getCookie('aiwp_logged_in');
61 if(!aiUser) {
62 window.location.href = process.env.REACT_APP_AUTH_FAILED_REDIRECTION_URL;
63 return;
64 } else {
65 let objBody = { aiwp_logged_in: aiUser };
66
67 let params = [];
68 params['objBody'] = objBody;
69 params['strUrl'] = process.env.REACT_APP_EXTERNAL_API_URL + '/e/v1/authenticate/';
70
71 window.btutil_checkAuthentication(params, function(res) {
72 if (!res.success) {
73 window.location.href = process.env.REACT_APP_AUTH_FAILED_REDIRECTION_URL;
74 } else {
75 submitPrompt();
76 }
77 }, function(res) {});
78 }
79 }
80
81 async function submitPrompt() {
58 const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who']; 82 const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who'];
59 const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi'); 83 const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi');
60 const inputMatches = chatInput.match(userInputRegex); 84 const inputMatches = chatInput.match(userInputRegex);
...@@ -88,7 +112,6 @@ function App() { ...@@ -88,7 +112,6 @@ function App() {
88 messages = JSON.stringify(chatLogTurboNew); 112 messages = JSON.stringify(chatLogTurboNew);
89 } 113 }
90 let intervalId = startInterval(); 114 let intervalId = startInterval();
91
92 try { 115 try {
93 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { 116 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", {
94 method: "POST", 117 method: "POST",
......
1 const appendScript = (scriptToAppend, callback = null) => {
2 const script = document.createElement("script");
3 script.src = scriptToAppend;
4 script.async = false;
5 document.body.appendChild(script);
6
7 if(!callback) return;
8 if(script.readyState) { // only required for IE <9
9 script.onreadystatechange = function() {
10 if ( script.readyState === "loaded" || script.readyState === "complete" ) {
11 script.onreadystatechange = null;
12 callback();
13 }
14 };
15 } else { //Others
16 script.onload = function() {
17 callback();
18 };
19 }
20 }
21
22 export default appendScript;
...\ No newline at end of file ...\ No newline at end of file
...@@ -2,7 +2,6 @@ import React from 'react'; ...@@ -2,7 +2,6 @@ import React from 'react';
2 import ReactDOM from 'react-dom/client'; 2 import ReactDOM from 'react-dom/client';
3 import './index.css'; 3 import './index.css';
4 import App from './App'; 4 import App from './App';
5 import appendScript from './handlers/appendScript';
6 import reportWebVitals from './reportWebVitals'; 5 import reportWebVitals from './reportWebVitals';
7 6
8 const root = ReactDOM.createRoot(document.getElementById('root')); 7 const root = ReactDOM.createRoot(document.getElementById('root'));
...@@ -16,6 +15,3 @@ root.render( ...@@ -16,6 +15,3 @@ root.render(
16 // to log results (for example: reportWebVitals(console.log)) 15 // to log results (for example: reportWebVitals(console.log))
17 // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 16 // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
18 reportWebVitals(); 17 reportWebVitals();
19
20 appendScript("https://btcomponent-1devt.s3.us-east-1.amazonaws.com/common/btutil-authenticate.min.js");
21 appendScript("http://localhost:3000/assets/js/auth.js");
...\ No newline at end of file ...\ No newline at end of file
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!