-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from X-FRI/dev
[stoream]: pin login support, some bug fixes
- Loading branch information
Showing
11 changed files
with
312 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(* Copyright (c) 2024 The X-Files Research Institute | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* * Neither the name of Stoream nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*) | ||
|
||
module Stoream.Engine.PIN | ||
|
||
open System | ||
open Suave | ||
open Suave.Filters | ||
open Suave.Successful | ||
open Suave.Operators | ||
open Config | ||
open API.Constraint | ||
open API.Response | ||
open Stoream.Engine.Logger.StoreamLogger | ||
|
||
type PIN() = | ||
|
||
(* Get the configuration file loaded at startup by the Stoream.Engine.Config module. | ||
* SEE: Stoream.Engine.Config *) | ||
static member inline public CONFIG = CONFIG.Pin | ||
|
||
(* Implementing the API interface indicates that this type is an API service *) | ||
interface IGetAPI with | ||
static member public App = PIN.App | ||
|
||
static member public App = | ||
path "/pin" >=> GET >=> request PIN.PIN | ||
|
||
static member private PIN (request: HttpRequest) = | ||
StoreamLogger.Info $"request {PIN}" | ||
|
||
request.queryParamOpt("value").Value | ||
|> snd | ||
|> _.Value | ||
|> fun pin -> | ||
if pin = PIN.CONFIG.ToString() then | ||
Response.OK () | ||
else | ||
Response.ERROR (ArgumentException $"Invalid PIN {pin}") |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"PIN": "294538", | ||
"Account": { | ||
"Username": "admin", | ||
"Password": "21232f297a57a5a743894a0e4a801fc3" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/// Copyright (c) 2024 The X-Files Research Institute | ||
/// | ||
/// All rights reserved. | ||
/// | ||
/// Redistribution and use in source and binary forms, with or without modification, | ||
/// are permitted provided that the following conditions are met: | ||
/// | ||
/// * Redistributions of source code must retain the above copyright notice, | ||
/// this list of conditions and the following disclaimer. | ||
/// * Redistributions in binary form must reproduce the above copyright notice, | ||
/// this list of conditions and the following disclaimer in the documentation | ||
/// and/or other materials provided with the distribution. | ||
/// * Neither the name of Stoream nor the names of its contributors | ||
/// may be used to endorse or promote products derived from this software | ||
/// without specific prior written permission. | ||
/// | ||
/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
/// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
/// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
/// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
/// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
/// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
/// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
/// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
/// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
/// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
/// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
import React from "react" | ||
|
||
interface PreviwFileProps { | ||
|
||
} | ||
|
||
const PreviewFile: React.FC<PreviwFileProps> = () => { | ||
return ( | ||
<> | ||
</> | ||
) | ||
} | ||
|
||
export default PreviewFile |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// Copyright (c) 2024 The X-Files Research Institute | ||
/// | ||
/// All rights reserved. | ||
/// | ||
/// Redistribution and use in source and binary forms, with or without modification, | ||
/// are permitted provided that the following conditions are met: | ||
/// | ||
/// * Redistributions of source code must retain the above copyright notice, | ||
/// this list of conditions and the following disclaimer. | ||
/// * Redistributions in binary form must reproduce the above copyright notice, | ||
/// this list of conditions and the following disclaimer in the documentation | ||
/// and/or other materials provided with the distribution. | ||
/// * Neither the name of Stoream nor the names of its contributors | ||
/// may be used to endorse or promote products derived from this software | ||
/// without specific prior written permission. | ||
/// | ||
/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
/// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
/// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
/// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
/// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
/// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
/// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
/// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
/// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
/// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
/// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
@genType.as("Pin") | ||
type t = string |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/// Copyright (c) 2024 The X-Files Research Institute | ||
/// | ||
/// All rights reserved. | ||
/// | ||
/// Redistribution and use in source and binary forms, with or without modification, | ||
/// are permitted provided that the following conditions are met: | ||
/// | ||
/// * Redistributions of source code must retain the above copyright notice, | ||
/// this list of conditions and the following disclaimer. | ||
/// * Redistributions in binary form must reproduce the above copyright notice, | ||
/// this list of conditions and the following disclaimer in the documentation | ||
/// and/or other materials provided with the distribution. | ||
/// * Neither the name of Stoream nor the names of its contributors | ||
/// may be used to endorse or promote products derived from this software | ||
/// without specific prior written permission. | ||
/// | ||
/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
/// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
/// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
/// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
/// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
/// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
/// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
/// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
/// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
/// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
/// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
import * as Request from "../model/Request.res.mjs" | ||
import React from "react"; | ||
import { Stack, Input, Button, Title, Card, Space } from '@mantine/core'; | ||
import { notifications } from '@mantine/notifications'; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
const Account = () => { | ||
const navigate = useNavigate() | ||
|
||
const [username, setUsername] = React.useState(""); | ||
const [password, setPassword] = React.useState(""); | ||
|
||
const login = async (): Promise<void> => { | ||
return await Request.User.request({ username, password }).then(() => { | ||
localStorage.setItem("isLogin", "true") | ||
|
||
notifications.show({ | ||
title: "login successful", | ||
message: "Successfully logged in to user " + username, | ||
color: "green" | ||
}) | ||
|
||
navigate("/files") | ||
}).catch(reason => { | ||
console.log(reason.stack) | ||
notifications.show({ | ||
title: "An error occurred during login", | ||
message: String(reason), | ||
color: "red" | ||
}) | ||
}) | ||
}; | ||
|
||
return ( | ||
<Stack align="center" justify="center" gap="xl" onLoad={() => (localStorage.getItem("isLogin") === "true") ? navigate("/files") : null}> | ||
<Space h="xl" /> | ||
<Space h="xl" /> | ||
<Space h="xl" /> | ||
|
||
<Card shadow="lg" padding="lg" radius="md" style={{ width: "20em", border: "1px solid orange" }} c="blue"> | ||
<Stack style={{ margin: "10% 10% 10% 10%" }} align="center" justify="center" gap="xl"> | ||
<Title order={2}>Login to Stoream</Title> | ||
|
||
<Input | ||
error={username === ""} | ||
placeholder="Username" | ||
style={{ width: "15em" }} | ||
onChange={(value) => setUsername(value.target.value)} | ||
/> | ||
|
||
<Input | ||
error={password === ""} | ||
placeholder="Password" type="password" | ||
style={{ width: "15em" }} | ||
onChange={(value) => setPassword(value.target.value)} | ||
/> | ||
|
||
<Button onClick={async () => await login()} bg="orange" c="dark"> Login </Button> | ||
</Stack> | ||
</Card> | ||
|
||
</Stack> | ||
); | ||
}; | ||
|
||
export default Account; |
Oops, something went wrong.