Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom fields on the login page #297

Merged
merged 1 commit into from
Mar 30, 2022
Merged

Conversation

Badgerati
Copy link
Owner

Description of the Change

This adds a new -Content parameter to Set-PodeWebLoginPage which allows for the overriding of fields displayed on the login page.

By default, the fields will still be Username and Password, but if -Content is supplied then these fields will be used instead. The content can be any Layout or Element, and will be place within a Form between the "Please sign in" message and the "Sign in" button.

A new -SignInMessage parameter has also been added to Set-PodeWebLoginPage, which allows the "Please sign in" message to be customised.

Further, there are 2 new switches for New-PodeWebTextbox: -AutoFocus and -DynamicLabel. If AutoFocus is supplied then the textbox will be automatically focused on page load. DynamicLabel enables the feature that the textboxes on the login page have, whereby the placeholder/label for the textbox will seemingly "float" and "shrink" to the top of the textbox when input is given.

Examples

# setup sessions
Enable-PodeSessionMiddleware -Duration 120 -Extend
# define a new custom authentication scheme, which needs a client, username, and password
$custom_scheme = New-PodeAuthScheme -Custom -ScriptBlock {
    param($opts)
    # get the client/user/password from the request's post data
    $client = $WebEvent.Data.client
    $username = $WebEvent.Data.username
    $password = $WebEvent.Data.password
    # return the data in a array, which will be passed to the validator script
    return @($client, $username, $password)
}
# now, add a new custom authentication validator using the scheme you created above
$custom_scheme | Add-PodeAuth -Name Example -ScriptBlock {
    param($client, $username, $password)
    # check if the client is valid in some database
    return @{
        User = @{
            ID ='M0R7Y302'
            Name = 'Morty'
            Type = 'Human'
        }
    }
    # return a user object (return $null if validation failed)
    return  @{ User = $user }
}
# set the login page to use the custom auth, and also custom login fields
Set-PodeWebLoginPage -Authentication Example -Content @(
    New-PodeWebTextbox -Type Text -Name 'client' -Id 'client' -Placeholder 'Client' -Required -AutoFocus -DynamicLabel
    New-PodeWebTextbox -Type Text -Name 'username' -Id 'username' -Placeholder 'Username' -Required -DynamicLabel
    New-PodeWebTextbox -Type Password -Name 'password' -Id 'password' -Placeholder 'Password' -Required -DynamicLabel
)

@Badgerati Badgerati added the enhancement ⬆️ New feature or request label Mar 29, 2022
@Badgerati Badgerati added this to the 0.8.0 milestone Mar 29, 2022
@Badgerati Badgerati self-assigned this Mar 29, 2022
@Badgerati Badgerati merged commit 1a2300c into develop Mar 30, 2022
@Badgerati Badgerati deleted the custom_login branch March 30, 2022 18:18
@Badgerati Badgerati mentioned this pull request Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ⬆️ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant