Genie Discord forum

Author Avatarwhiskers
10/14/2023, 3:59:37 PM

I am trying to figure out on how to make a widget take an input (For an instance, I want the text fields to take input for the backend code) Code is shown below:

#Handler Code
@appname StudLogin

@app begin
    @in granted = false
    @onchange granted begin
        user_in=readline()
        pass_in=readline()
        users = CSV.File("Admin_Keys.txt")
        found = false
        for i in users
            if user_in = i.user
                found = true
                if pass_in = i.pass
                    println("Logged in")
                else
                    println("Invalid or Expired Credentials")
                end
            end
        end
        if found == false
            println("Invalid or Expired Credentials")  
        end
    end 
end

#GUI widgets
function loginUI()
    row(cell(class = "st-module", [
        textfield(class = "q-my-md", "Username", :input, @on("keyup.enter", "process = true"))
        textfield(class = "q-my-md", "Password", :input, hint = "Your DP Credentials", @on("keyup.enter", "process = true"))
        btn(class="q-my-md", "Proceed", color = "primary", @click("granted =! granted"))
    ]))   
end

@page("/", loginUI()) 

up()
Author AvatarPere
10/15/2023, 9:00:48 PM

you need to define the appropriate reactive variables for each component. That is

@in input = ""
@in process = false
@in granted = false

https://learn.genieframework.com/docs/reference/reactive-ui/reactivity#reactivity

Author Avatarwhiskers
10/16/2023, 4:54:47 PM

Can you show one example of how you use this @in process = false?

Updated code is shown below:

@app begin
    @in userinput = ""
    @in passinput = ""
    @in process = false
    @in granted = false
    @onchange granted begin
        user_in=userinput
        pass_in=passinput
        users = CSV.File("C:\\Users\\aayus\\Desktop\\GenieBuild\\GradeMasterGenie\\GradeMasterGenie\\Data\\Admin_Keys.csv")
        found = false
        for i in users  #Beginning of linear search for username and password
            if user_in == i.user #if username is in the text file then initiate another conditional check (Found = True)
                found = true
                if pass_in == i.pass #if password is found in the text file then redirect to admin student data entry 
                    @in notifyme = false 
                    @onchange notifyme begin 
                        notify(model, msg)
                    println("Login Success")
                    end
                else
                    @in notifypass = false
                    @onchange notifypass begin
                        notify(model, incpassmess)
                    end
                    println("Invalid or Expired Credentials") #Show message that credentials are either Invalid or Expired
                end
            end
        end
        if found == false
            @in notifywruser = false
            @onchange notifywruser begin
                notify(model, incusermess)
            end
            println("Invalid or Expired Credentials")  
        end
    end 
end
#part 1 of code ```