Pārlūkot izejas kodu

login form update

Honza 5 gadi atpakaļ
vecāks
revīzija
a692742d74
3 mainītis faili ar 91 papildinājumiem un 21 dzēšanām
  1. 20 8
      Atlas.py
  2. BIN
      __pycache__/Atlas.cpython-37.pyc
  3. 71 13
      dlg_ConnectionManager.ui

+ 20 - 8
Atlas.py

@@ -122,6 +122,8 @@ class Atlas:
         self.code_challenge = None
         self.Agrimail = None
         self.loadedInMemory = False
+        self.liferayServer = None
+        self.laymanServer = None
         self.uri = 'http://layman.lesprojekt.cz/rest/'
      #   global dlgGetLayers 
         self.dlgGetLayers= GetLayersDialog()
@@ -537,8 +539,13 @@ class Atlas:
             if len(config['DEFAULT']['login']) > 0:
                 self.Agrimail = config['DEFAULT']['login']
                 self.dlg.pushButton_Connect.setEnabled(True) 
-            self.dlg.lineEdit_userName.setText(config['DEFAULT']['login'] + "@lesprojekt.cz")            
-            self.dlg.lineEdit_AgriID.setText(config['DEFAULT']['id']) 
+            self.dlg.lineEdit_userName.setText(config['DEFAULT']['login'] + "@lesprojekt.cz")  
+            try:
+                self.dlg.lineEdit_AgriID.setText(config['DEFAULT']['id']) 
+                self.dlg.lineEdit_server.setText(config['DEFAULT']['server']) 
+                self.dlg.lineEdit_serverLayman.setText(config['DEFAULT']['layman']) 
+            except:
+                print("udaj v ini nenalezen")
         else:
             try:
                 os.makedirs(os.getenv("HOME") + os.sep + ".layman")
@@ -2077,7 +2084,7 @@ class Atlas:
         #self.expires_in = 60
         path = tempfile.gettempdir() + os.sep + "atlas" + os.sep + "tsts.txt" 
         i = 0
-        tokenEndpoint = "https://www.agrihub.cz/o/oauth2/token"
+        tokenEndpoint = "https://www."+self.liferayServer+"/o/oauth2/token"
         while (i < self.expires_in):        
             f = open(path, "a")
             f.write(str(i))
@@ -2157,7 +2164,7 @@ class Atlas:
     def getToken(self):
         self.saveIni()
 
-        tokenEndpoint = "https://www.agrihub.cz/o/oauth2/token"
+        tokenEndpoint = "https://www."+self.liferayServer+"/o/oauth2/token"
         # data to be sent to api 
         data = {'grant_type':'authorization_code', 
                 'client_id': self.client_id, 
@@ -2195,7 +2202,7 @@ class Atlas:
     def setAuthHeader(self):
         self.authHeader ={
           "Authorization": "Bearer " + self.access_token, 
-          "AuthorizationIssUrl" : 'https://www.agrihub.cz/o/oauth2/authorize'
+          "AuthorizationIssUrl" : 'https://www.'+self.liferayServer+'/o/oauth2/authorize'
         } 
         
     def registerUserIfNotExists(self):
@@ -2227,12 +2234,13 @@ class Atlas:
         #API_ENDPOINT = "http://layman.lesprojekt.cz/rest/current-user"
         #headers ={
         #  "Authorization": "Bearer "+ self.access_token, 
-        #  "AuthorizationIssUrl" : 'https://www.agrihub.cz/o/oauth2/authorize'
+        #  "AuthorizationIssUrl" : 'https://www.'+self.liferayServer+'/o/oauth2/authorize'
         #} 
 
 
     def openAuthLiferayUrl(self):
-        
+        self.liferayServer = self.dlg.lineEdit_server.text()
+        self.URI = self.dlg.lineEdit_serverLayman.text()
         self.getCodeChallenge(self.getCodeVerifier()) ##generování kódů
         self.client_id = self.dlg.lineEdit_AgriID.text()
         path = tempfile.gettempdir() + os.sep + "atlas" + os.sep + "auth.txt" 
@@ -2247,7 +2255,7 @@ class Atlas:
         thread = StartFlaskDaemon()
         thread.daemon = True
         thread.start()       
-        url = 'https://www.agrihub.cz/o/oauth2/authorize?response_type=code&client_id='+self.client_id+'&redirect_uri=http%3A%2F%2Flocalhost:3000%2Fclient%2Fauthn%2Foauth2-liferay%2Fcallback&code_challenge='+self.code_challenge ##n4bQgYhMfWWaL-qgxVrQFaO_TxsrC4Is0V1sFbDwCgg'
+        url = 'https://www.'+self.liferayServer+'/o/oauth2/authorize?response_type=code&client_id='+self.client_id+'&redirect_uri=http%3A%2F%2Flocalhost:3000%2Fclient%2Fauthn%2Foauth2-liferay%2Fcallback&code_challenge='+self.code_challenge ##n4bQgYhMfWWaL-qgxVrQFaO_TxsrC4Is0V1sFbDwCgg'
         webbrowser.open(url, new=2)
 
     def saveIni(self):
@@ -2259,8 +2267,12 @@ class Atlas:
             except OSError:  
                 print ("vytváření adresáře selhalo")
         config = configparser.ConfigParser()
+
         config['DEFAULT']['login'] = self.Agrimail
         config['DEFAULT']['id'] = self.client_id
+        print("saveliferay" + self.liferayServer)
+        config['DEFAULT']['server'] = self.liferayServer
+        config['DEFAULT']['layman'] = self.URI
         
 
         with open(file, 'w') as configfile:

BIN
__pycache__/Atlas.cpython-37.pyc


+ 71 - 13
dlg_ConnectionManager.ui

@@ -10,7 +10,7 @@
     <x>0</x>
     <y>0</y>
     <width>635</width>
-    <height>186</height>
+    <height>200</height>
    </rect>
   </property>
   <property name="sizePolicy">
@@ -22,13 +22,13 @@
   <property name="minimumSize">
    <size>
     <width>635</width>
-    <height>186</height>
+    <height>200</height>
    </size>
   </property>
   <property name="maximumSize">
    <size>
     <width>635</width>
-    <height>186</height>
+    <height>200</height>
    </size>
   </property>
   <property name="windowTitle">
@@ -41,7 +41,7 @@
    <property name="geometry">
     <rect>
      <x>155</x>
-     <y>57</y>
+     <y>120</y>
      <width>351</width>
      <height>27</height>
     </rect>
@@ -54,20 +54,20 @@
    <property name="geometry">
     <rect>
      <x>20</x>
-     <y>57</y>
+     <y>120</y>
      <width>111</width>
      <height>19</height>
     </rect>
    </property>
    <property name="text">
-    <string>Agrihub ID:</string>
+    <string>Liferay ID:</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_Connect">
    <property name="geometry">
     <rect>
      <x>155</x>
-     <y>97</y>
+     <y>160</y>
      <width>111</width>
      <height>27</height>
     </rect>
@@ -80,7 +80,7 @@
    <property name="geometry">
     <rect>
      <x>394</x>
-     <y>97</y>
+     <y>160</y>
      <width>111</width>
      <height>28</height>
     </rect>
@@ -93,7 +93,7 @@
    <property name="geometry">
     <rect>
      <x>279</x>
-     <y>97</y>
+     <y>160</y>
      <width>101</width>
      <height>27</height>
     </rect>
@@ -106,7 +106,7 @@
    <property name="geometry">
     <rect>
      <x>154</x>
-     <y>137</y>
+     <y>180</y>
      <width>88</width>
      <height>27</height>
     </rect>
@@ -119,13 +119,13 @@
    <property name="geometry">
     <rect>
      <x>20</x>
-     <y>22</y>
+     <y>85</y>
      <width>121</width>
      <height>19</height>
     </rect>
    </property>
    <property name="text">
-    <string>Agrihub login:</string>
+    <string>Liferay login:</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="lineEdit_userName">
@@ -135,7 +135,7 @@
    <property name="geometry">
     <rect>
      <x>155</x>
-     <y>20</y>
+     <y>83</y>
      <width>351</width>
      <height>27</height>
     </rect>
@@ -144,6 +144,64 @@
     <string>@lesprojekt.cz</string>
    </property>
   </widget>
+  <widget class="QLineEdit" name="lineEdit_server">
+   <property name="enabled">
+    <bool>true</bool>
+   </property>
+   <property name="geometry">
+    <rect>
+     <x>156</x>
+     <y>45</y>
+     <width>351</width>
+     <height>27</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>agrihub.cz</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_APIKey_3">
+   <property name="geometry">
+    <rect>
+     <x>20</x>
+     <y>50</y>
+     <width>121</width>
+     <height>19</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Liferay server:</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_serverLayman">
+   <property name="enabled">
+    <bool>true</bool>
+   </property>
+   <property name="geometry">
+    <rect>
+     <x>157</x>
+     <y>7</y>
+     <width>350</width>
+     <height>27</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>http://layman.lesprojekt.cz</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_APIKey_4">
+   <property name="geometry">
+    <rect>
+     <x>20</x>
+     <y>10</y>
+     <width>121</width>
+     <height>19</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Layman server:</string>
+   </property>
+  </widget>
  </widget>
  <resources/>
  <connections/>