File size: 1,890 Bytes
da46fdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#inside .env file
#service_url="http://euwdsw202em01:4660/service" 
#console_url="http://euwdsw202em01:4660/console"

import requests
from dotenv import load_dotenv
import os

# Load variables from .env file
load_dotenv()

usr_id = os.getenv("usr_id")
password = os.getenv("password")

def login():
    url = "http://euwdsw202em01:4660/ws/auth/login"

    # Query parameters
    params = {
        "usr_id": usr_id,
        "password": password
    }

    headers = {
        #"Accept": "*/*",
        "Cache-Control": "no-cache",
        "Accept": "application/json"
    }

    try:
        session = requests.Session()
        response = session.get(url, params=params, headers=headers,verify=False)
        #print("Content-Type:", response.headers.get("Content-Type"))

        if response.status_code == 200:
            wh_url = f"http://euwdsw202em01:4660/api/user/v1/users/{usr_id}/warehouses"
            wh_response = session.get(wh_url, verify=False)
            
            authorized_wh = "WH1" # Fallback default
            if wh_response.status_code == 200:
                wh_data = wh_response.json().get("data", [])
                if wh_data:
                    # Logic: Take the first warehouse ID they are assigned to
                    # Or find the one marked as 'primary' if the API provides it
                    authorized_wh = wh_data[0].get("wh_id", "WH1")
            
            print(f"Login Success. User {usr_id} assigned to {authorized_wh}")
            
            # Return the session AND the locked warehouse ID
            return session, authorized_wh, True

        else:
            print({"login": "failed", "status_code": response.status_code})
            return None, None, False

    except Exception as e:
        print({"login": "error", "error": str(e)})
        return None, None, False
    
#if __name__ == "__main__":
#    login()