Is there a similar way to validate login like we validate for signup in Gramex?

34 Views Asked by At

In Gramex, for signup we have a validate method which will validate for a certain condition. Like in this example like we are validating the signup using validate() function.:

signup:
  key: signup                     # ?signup= is used as the signup parameter
  template: $YAMLPATH/signup.html # Use this signup template
  columns:                        # Mapping of URL query parameters to database columns
    name: user_name               # ?name= is saved in the user_name column
    gender: user_gender           # ?gender= is saved in the user_gender column
                                  # Other than email, all other columns are ignored
  validate: app.validate(args)

Similarly, is there a way to validate a condition in login mechanism? I can check manually but looking for a more feasible solution.

1

There are 1 best solutions below

0
On

You can use condition kwarg in auth
Ref: https://gramener.com/gramex/guide/auth/#api-key

For example:

url:
  example-home:
    pattern: /$YAMLURL/
    handler: FileHandler
    kwargs:
      path: $YAMLPATH/index.html
      auth:
        login_url: /$YAMLURL/login/
        condition: // Using condition and passing the following function for backend validation
          function: app.validate_login
      template: ["index.html", "template*.html"]