Permission error when executing login singleton class with gest privilege

Following the doc Creating a login page for public access | Qodly Developer Center, I’ve been unable to configure a public access login page and I get “Error: No permission to execute the login function in the loginCheck singleton class”.

Roles/Privileges settings :

{
  "permissions": {
    "allowed": [
      {
        "applyTo": "loginCheck.login",
        "type": "singletonMethod",
        "execute": [
          "guest"
        ],
        "promote": [
          "utilisateurAccess"
        ]
      },
      {
        "applyTo": "utilisateur",
        "type": "dataclass",
        "read": [
          "utilisateurAccess"
        ]
      },
      {
        "applyTo": "ds",
        "type": "datastore",
        "read": [
          "opportuniteAccess",
          "none"
        ],
        "create": [
          "opportuniteAccess",
          "none"
        ],
        "update": [
          "opportuniteAccess",
          "none"
        ],
        "execute": [
          "opportuniteAccess",
          "none"
        ],
        "drop": [
          "none"
        ],
        "describe": [
          "none"
        ]
      }
    ]
  },
  "privileges": [
    {
      "id": "g289KeZ1diTadeR6tTZAzq",
      "privilege": "utilisateurAccess",
      "includes": []
    },
    {
      "id": "tZoFFut695aTEYYZmkhuEo",
      "privilege": "opportuniteAccess",
      "includes": []
    },
    {
      "id": "qfifEifQJ2YFUMw5FBd8mE",
      "privilege": "none",
      "includes": []
    }
  ],
  "roles": [
    {
      "id": "r1yDEEfH6xvN6t9d3eFCA2",
      "role": "Admin",
      "privileges": [
        "guest",
        "opportuniteAccess",
        "utilisateurAccess"
      ]
    },
    {
      "id": "rVpaixWeQDwpBRmcWemEdY",
      "role": "publicAuth",
      "privileges": [
        "utilisateurAccess",
        "opportuniteAccess",
        "guest"
      ]
    }
  ]
}

Singleton :

//loginCheck Class
shared singleton constructor()
	
exposed function login(login : string, password : string)
	var utilisateur : cs.utilisateurEntity
	var privileges : object
	var userObj : object
	
	utilisateur = ds.utilisateur.query("login == :1", string(login)).first()
	switch 
		: (utilisateur == null)
			throw(9, "L'identification a échouée, merci de vérifier l'identifiant et le mot de passe")
		: (utilisateur && not(verifyPasswordHash(string(password), utilisateur.passwordHash)))
			throw(9, "L'identification a échouée, merci de vérifier l'identifiant et le mot de passe")
		else 
			session.setPrivileges({roles: "PublicAuth"})
			
			// userObj = newSharedObject("roles", utilisateur.profile, "userName", utilisateur.login, "userId", utilisateur.ID)
			// use (session.storage)
			// 	session.storage.currentUser = userObj
			// end 
						
			webForm.setMessage("Identification réussie")
	end 

Hi,

Can you share your app with me? I send you a MP.

Mathieu

Hello Jean, thanks for you feedback,

Did you restart the server after creating the privileges and retesting the public access URL?

Yes, I restart the server

1 Like

Here is Mathieu Ferry’s response :

We think there’s a problem with privileges on singleton in the current version.
To fix the problem quickly, you can use a function on dataclass instead of a singleton function.
The problem is already fixed in Qodly’s future 1.1 and we’re looking into fixing it earlier.

I can confirm that using a function on the dataclass instead of a singleton solves the problem with version 1.0.0.

1 Like