Created
November 17, 2018 03:12
-
-
Save ChendrayanV/0d02e780e970578177ef28b2fb295059 to your computer and use it in GitHub Desktop.
Simple Login Page Demo Using PSHTML and Polaris (PowerShell Modules)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module Polaris -Verbose | |
Import-Module PSHTML -Verbose | |
Add-Type -AssemblyName System.Web | |
New-PolarisGetRoute -Path "/Login" -Scriptblock { | |
$HTML = html { | |
head { | |
Title "Login Page" | |
} | |
body { | |
h1 -Content "Connect to Office365 Securely..." | |
Form -action "/authenticate" -method 'post' -target '_blank' -Content { | |
input -type text -name 'uSite' | |
input -type text -name 'uName' | |
input -type password -name 'uPassword' | |
button -Content "Click" | |
} | |
} | |
} | |
$Response.SetContentType('text/html') | |
$Response.Send($HTML) | |
} | |
New-PolarisPostRoute -Path "/authenticate" -Scriptblock { | |
$Response.SetContentType('application/json') | |
$Body = [System.Web.HttpUtility]::UrlDecode($Request.BodyString) | |
$Data = @{} | |
$Body.split('&') | ForEach-Object { | |
$part = $_.split('=') | |
$Data.add($part[0] , $part[1]) | |
} | |
Import-Module C:\projects\iPolaris\assemblies\Microsoft.SharePoint.Client.dll | |
$UserName = $Data.uName | |
$Pasword = $Data.uPassword | ConvertTo-SecureString -AsPlainText -Force | |
$ClientContext = [Microsoft.SharePoint.Client.ClientContext]::new($Data.uSite) | |
$ClientContext.Credentials = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($UserName, $Pasword) | |
$ListCollection = $ClientContext.Web.Lists | |
$ClientContext.Load($ListCollection) | |
$ClientContext.ExecuteQuery() | |
$ClientContext.Dispose() | |
$Collection = @() | |
foreach ($List in $ListCollection | Select-Object -First 10) { | |
$Result = [pscustomobject]@{ | |
Title = $List.Title | |
ItemCount = $List.ItemCount | |
} | |
$Collection += $Result | |
} | |
$Response.Send(($Collection | ConvertTo-Json)) | |
} | |
Start-Polaris -Port 8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment