#๐Ÿ”’ can i get help how i will be able to make this code

10 messages ยท Page 1 of 1 (latest)

paper wyvern
#

I just made a employee login and inside that for the eployee it includers the boolean for what can be acceswed by that employee now how will i make a code where it will be able to see that employee and be able to hide that p[art in the front if it false

@csrf_exempt
@api_view(['POST'])
def employee_login(request):
    try:
        data = json.loads(request.body)  # Changed to json.loads(request.body)
        print("Request Data:", data)  # Print the request data for debugging
        
        branch_name = data.get('branch_name')
        username = data.get('username')
        password = data.get('password')

        if not branch_name:
            return JsonResponse({'message': 'Branch name not provided'}, status=400)

        if not username or not password:
            return JsonResponse({'message': 'Username and password are required'}, status=400)

        # Determine the database to use
        db_name = f'branch_{branch_name.lower()}'
        print(f"Database being used: {db_name}")  # Print the database being used for debugging

        if db_name not in settings.DATABASES:
            print(f"Branch database not found: {db_name}")  # Print if the branch database is not found
            return JsonResponse({'message': 'Branch database not found'}, status=404)

        # Fetch the employee user from the branch-specific database
        try:
            employee = Employee.objects.using(db_name).get(username=username)
            print(f"Employee found: {employee.username}")  # Print the found employee's username
        except Employee.DoesNotExist:
            print(f"User not found: {username}")  # Print if the user is not found
            return JsonResponse({'message': 'User not found'}, status=404)


           
       
pliant oakBOT
#

@paper wyvern

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

paper wyvern
#
# Check if the provided password matches the stored password
        if check_password(password, employee.password):
            print("Password is valid")  # Print confirmation of a valid password

            # Set session data manually
            request.session['branch_name'] = branch_name  # Save branch name in session
            request.session['username'] = username  # Save username in session

            # Print session data for debugging
            print(f"Branch stored in session: {request.session.get('branch_name')}")
            print(f"Username stored in session: {request.session.get('username')}")

            # Generate tokens (optional: if you want to continue using JWTs)
            try:
                refresh = RefreshToken.for_user(employee)
                access = refresh.access_token

                return JsonResponse({
                    'refresh': str(refresh),
                    'access': str(access),
                }, status=200)
            except Exception as e:
                print(f"Token generation error: {str(e)}")  # Print any token generation errors
                return JsonResponse({'message': 'Token generation error'}, status=500)
        else:
            print("Invalid password")  # Print if the password is invalid
            return JsonResponse({'message': 'Invalid password'}, status=401)
    except json.JSONDecodeError:
        print("Invalid JSON format")  # Print if JSON format is invalid
        return JsonResponse({'message': 'Invalid JSON format'}, status=400)
    except Exception as e:
        print(f"Error: {str(e)}")  # Print any other exceptions
        return JsonResponse({'message': str(e)}, status=500)
#

heres the jsx
that contains the permissions of the employee

const permissions = [
    { name: "Allow To See Sales", field: "allow_see_sales" },
    { name: "Allow To See Sales AI Recommendations", field: "allow_see_sales_ai_recommendations" },
    { name: "Allow To Input Product Sales For Today", field: "allow_input_product_sales" },
    { name: "Allow To See Inventory", field: "allow_see_inventory" },
    { name: "Allow To Edit Inventory", field: "allow_edit_inventory" },
    { name: "Allow To See AI Recommendations", field: "allow_see_ai_recommendations" }
];

const Createuser = () => {
  const [passwordVisible, setPasswordVisible] = useState(false);
  const [showPermissions, setShowPermissions] = useState(false);
  const [employeePermissions, setEmployeePermissions] = useState({
    allow_see_sales: false,
    allow_see_sales_ai_recommendations: false,
    allow_input_product_sales: false,
    allow_see_inventory: false,
    allow_edit_inventory: false,
    allow_see_ai_recommendations: false,
  });
  const [username, setUsername] = useState('');
  const [password, setPassword] = useState('');
  const [branchName, setBranchName] = useState('');
  const [employeeId, setEmployeeId] = useState(''); // Added state for employee ID
#

heres one of the content im trtying to hide

import React, { useState } from 'react';
import axios from 'axios';

const Body = () => {
    const [permissions, setPermissions] = useState({});
    const [loading, setLoading] = useState(false);

    // Define these variables based on your authentication or context management
    const branchName = 'branch_name_from_session';  // Replace with actual session or context value
    const username = 'username_from_session';       // Replace with actual session or context value

    const fetchPermissions = async () => {
        setLoading(true);
        try {
            const response = await axios.post('http://127.0.0.1:8000/branchapp/employee_permissions/', {});
            setPermissions(response.data.permissions);
        } catch (error) {
            console.error('Error fetching permissions:', error);
        } finally {
            setLoading(false);
        }
    };

    return (
        <div className="font-poppins p-4 pt-10 relative mt-[-20px] md:mt-[-80px]">
            <div className="flex flex-col items-start mb-4 mr-10">
                <label id="main-title" className="text-black font-bold text-5xl md:text-7xl mb-2">Branch Name</label>
                <label id="sub-title" className="text-black font-semibold text-2xl md:text-4xl ml-5">Predictive Analytics</label>
            </div>
            <div className="flex items-center justify-center mt-16 md:mt-20">
                <div className="flex flex-col md:flex-row space-y-8 md:space-y-0 md:space-x-4 relative">
                    {/* Button to trigger permissions fetch */}
                    <button 
                        className="bg-blue-500 text-white px-4 py-2 rounded-lg mb-4"
                        onClick={fetchPermissions}
                        disabled={loading}
                    >
                        {loading ? 'Loading...' : 'Fetch Permissions'}
                    </button>

                    

#
 {permissions.allow_see_sales && (
                        <div className="flex flex-col items-center relative">
                            <label className="absolute top-[-2.5rem] text-black font-medium text-18 md:text-2xl mb-2">PREDICTED SALES FOR THE DAY FOR THE PRODUCT</label>
                            <div className="w-[400px] md:w-[649px] h-[300px] md:h-[381px] bg-white rounded-[24px] shadow-lg border-2 border-solid border-black p-6">
                                {/* Placeholder for future image */}
                            </div>
                        </div>
                    )}
                    {permissions.allow_see_sales && (
                        <div className="flex flex-col items-center relative">
                            <label className="absolute top-[-2.5rem] text-black font-medium text-18 md:text-2xl mt-[10px] md:mt-[0px] mb-2">PREDICTED SALES FOR THE MONTH</label>
                            <div className="w-[400px] md:w-[649px] h-[300px] md:h-[381px] bg-white rounded-[24px] shadow-lg border-2 border-solid border-black p-6">
                                {/* Placeholder for future image */}
                            </div>
                        </div>
                    )}
                </div>
            </div>
        </div>
    );
};

export default Body;
sage inlet
#

!paste

pliant oakBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

pliant oakBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.