Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
141
Issues
141
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
692e71f7
Commit
692e71f7
authored
May 24, 2022
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/397-dev-lost-password' into dev-merge
parents
362ca6e2
4b57ade3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
130 additions
and
19 deletions
+130
-19
Login.purs
src/Gargantext/Components/Login.purs
+7
-3
ForgotPassword.purs
src/Gargantext/Components/Login/ForgotPassword.purs
+77
-0
Form.purs
src/Gargantext/Components/Login/Form.purs
+32
-14
Types.purs
src/Gargantext/Components/Login/Types.purs
+4
-0
Sessions.purs
src/Gargantext/Sessions.purs
+10
-2
No files found.
src/Gargantext/Components/Login.purs
View file @
692e71f7
...
...
@@ -12,6 +12,8 @@ import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Login.Form (form)
import Gargantext.Components.Login.ForgotPassword (forgotPassword)
import Gargantext.Components.Login.Types (FormType(..))
import Gargantext.Components.NgramsTable.Loader as NTL
import Gargantext.Ends (Backend(..))
import Gargantext.Hooks.Loader as GHL
...
...
@@ -39,12 +41,13 @@ type Props =
login :: R2.Leaf Props
login = R2.leaf loginCpt
loginCpt :: R.Component Props
loginCpt = here.component "login" cpt where
cpt props@{ sessions, visible } _ = do
-- States
mBackend <- R2.useLive' props.backend
formType <- T.useBox Login
formType' <- T.useLive T.unequal formType
-- Render
pure $
...
...
@@ -55,12 +58,13 @@ loginCpt = here.component "login" cpt where
[
case mBackend of
Nothing -> chooser props
Just backend -> form { backend, sessions, visible }
Just backend -> case formType' of
Login -> form { backend, formType, sessions, visible }
ForgotPassword -> forgotPassword { backend, sessions }
]
chooser :: R2.Leaf Props
chooser = R2.leafComponent chooserCpt
chooserCpt :: R.Component Props
chooserCpt = here.component "chooser" cpt where
cpt { backend, backends, sessions } _ = do
...
...
src/Gargantext/Components/Login/ForgotPassword.purs
0 → 100644
View file @
692e71f7
module Gargantext.Components.Login.ForgotPassword where
import DOM.Simple.Event as DE
import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.Forms (formGroup)
import Gargantext.Ends (Backend)
import Gargantext.Prelude
import Gargantext.Sessions (Sessions, postForgotPasswordRequest)
import Gargantext.Utils.Reactix as R2
import Formula as F
import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.SyntheticEvent as E
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Login.ForgotPassword"
type Email = String
type Props =
( backend :: Backend
, sessions :: T.Box Sessions )
forgotPassword :: R2.Leaf Props
forgotPassword = R2.leaf forgotPasswordCpt
forgotPasswordCpt :: R.Component Props
forgotPasswordCpt = here.component "forgotPassword" cpt where
cpt { backend, sessions } _ = do
email <- T.useBox ""
pure $ H.div { className: "row" }
[ H.form { className: "col-md-12" }
[ H.h4 {} [ H.text "Forgot password" ]
, formGroup
[ emailInput email ]
, submitButton { backend, email, sessions }
]
]
emailInput :: forall cell. T.ReadWrite cell Email => cell -> R.Element
emailInput value = F.bindInput { value
, type: "email"
, className: "form-control"
, id: "id_email"
, placeholder: "email"
, name: "email"
, maxLength: "254" }
type SubmitButtonProps =
( email :: T.Box Email
| Props )
submitButton :: R2.Leaf SubmitButtonProps
submitButton = R2.leafComponent submitButtonCpt
submitButtonCpt :: R.Component SubmitButtonProps
submitButtonCpt = here.component "submitButton" cpt where
cpt { backend, email, sessions } _ = do
email' <- T.useLive T.unequal email
pure $ formGroup
[ H.button { className: "btn btn-primary"
, on: { click: click email' }}
[ H.text "Submit" ]
]
where
click :: Email -> R.SyntheticEvent DE.MouseEvent -> Effect Unit
click email' e = do
E.preventDefault e
here.log2 "email" email'
here.log2 "backend" backend
here.log2 "sessions" sessions
launchAff_ $ do
res <- postForgotPasswordRequest backend email'
liftEffect $ here.log2 "res" res
src/Gargantext/Components/Login/Form.purs
View file @
692e71f7
module Gargantext.Components.Login.Form where
import Prelude (Unit, bind, discard, notEq, pure, show, ($), (&&), (*>), (<>))
import Prelude (Unit, bind, discard, not
, not
Eq, pure, show, ($), (&&), (*>), (<>))
import Data.Either (Either(..))
import DOM.Simple.Event as DE
import Effect (Effect)
...
...
@@ -13,8 +13,8 @@ import Reactix.DOM.HTML as H
import Toestand as T
import Toestand (useFocusedFields)
import Gargantext.Components.Login.Types (AuthRequest(..))
import Gargantext.Components.Forms (clearfix, formGroup)
import Gargantext.Components.Login.Types (AuthRequest(..), FormType(..))
import Gargantext.Ends (Backend)
import Gargantext.Sessions as Sessions
import Gargantext.Sessions (Sessions, postAuthRequest)
...
...
@@ -45,6 +45,7 @@ formBoxes box = useFocusedFields box {}
type Props s v =
( backend :: Backend
, formType :: T.Box FormType
, sessions :: s
, visible :: v
)
...
...
@@ -55,7 +56,7 @@ form props = R.createElement formCpt props []
formCpt :: forall s v. T.ReadWrite s Sessions => T.ReadWrite v Boolean
=> R.Component (Props s v)
formCpt = here.component "form" cpt where
cpt { backend, sessions, visible } _ = do
cpt { backend,
formType,
sessions, visible } _ = do
cell <- T.useBox emptyForm
cursors <- useFocusedFields cell {}
pure $ R2.row
...
...
@@ -70,7 +71,8 @@ formCpt = here.component "form" cpt where
[ passwordInput cursors.password
, clearfix ]
, termsCheckbox cursors.agreed
, submitButton { backend, sessions, visible, cell }
, forgotPassword { formType }
, submitButton { backend, formType, sessions, visible, cell }
]]
-- might be wrong, all we care about is preventDefault
...
...
@@ -87,18 +89,15 @@ submitButton
:: forall s v. T.ReadWrite s Sessions => T.Write v Boolean
=> R2.Leaf (SubmitButtonProps s v)
submitButton = R2.leafComponent submitButtonCpt
submitButtonCpt
:: forall s v. T.ReadWrite s Sessions => T.Write v Boolean
=> R.Component (SubmitButtonProps s v)
submitButtonCpt = here.component "submitButton" cpt where
cpt { backend, sessions, visible, cell } _ = do
cpt { backend,
formType,
sessions, visible, cell } _ = do
{ agreed, username, password } <- T.useLive T.unequal cell
pure $
if agreed && (username `notEq` "") && (password `notEq` "")
then H.div { className: "text-center" }
[ loginSubmit $ submitForm { backend, sessions, visible } cell ]
else H.div {} []
let isValid = agreed && (username `notEq` "") && (password `notEq` "")
pure $ H.div { className: "text-center" }
[ loginSubmit isValid $ submitForm { backend, formType, sessions, visible } cell ]
-- Attempts to submit the form
submitForm :: forall s v. T.ReadWrite s Sessions => T.Write v Boolean
...
...
@@ -157,9 +156,28 @@ passwordInput value =
, id: "id_password"
}
loginSubmit :: (ChangeEvent -> Effect Unit) -> R.Element
loginSubmit click =
H.button { id, className, type: "submit", on: { click } }
loginSubmit :: Boolean -> (ChangeEvent -> Effect Unit) -> R.Element
loginSubmit isEnabled click =
H.button { id
, className
, disabled: not isEnabled
, type: "submit"
, on: { click } }
[ H.text "Login" ] where
id = "login-button"
className = "btn btn-primary btn-rounded"
type ForgotPasswordProps =
( formType :: T.Box FormType )
forgotPassword :: R2.Leaf ForgotPasswordProps
forgotPassword = R2.leaf forgotPasswordCpt
forgotPasswordCpt :: R.Component ForgotPasswordProps
forgotPasswordCpt = here.component "forgotPassword" cpt where
cpt { formType } _ = do
pure $ H.div { className: "form-group text-center" }
[ H.button { className: "btn btn-danger"
, on: { click } } [ H.text "Forgot password" ]
]
where
click _ = T.write_ ForgotPassword formType
src/Gargantext/Components/Login/Types.purs
View file @
692e71f7
...
...
@@ -54,3 +54,7 @@ instance Eq AuthData where
_AuthData :: Iso' AuthData { token :: Token, tree_id :: TreeId, user_id :: UserId }
_AuthData = iso (\(AuthData v) -> v) AuthData
data FormType = Login | ForgotPassword
derive instance Generic FormType _
derive instance Eq FormType
src/Gargantext/Sessions.purs
View file @
692e71f7
...
...
@@ -4,7 +4,8 @@ module Gargantext.Sessions
, WithSession, WithSessionContext
, load, change
, Action(..), act, delete, get, post, put, put_
, postAuthRequest, deleteWithBody, postWwwUrlencoded
, postAuthRequest, postForgotPasswordRequest
, deleteWithBody, postWwwUrlencoded
, getCacheState, setCacheState
) where
...
...
@@ -114,13 +115,20 @@ postAuthRequest :: Backend -> AuthRequest -> Aff (Either String Session)
postAuthRequest backend ar@(AuthRequest {username}) =
decode <$> REST.post Nothing (toUrl backend "auth") ar
where
decode (Left
_err) = Left "Error when sending REST.post"
decode (Left
err) = Left $ "Error when sending REST.post: " <> show err
decode (Right (AuthResponse ar2))
| {inval: Just (AuthInvalid {message})} <- ar2 = Left message
| {valid: Just (AuthData {token, tree_id, user_id})} <- ar2 =
Right $ Session { backend, caches: Map.empty, token, treeId: tree_id, username, userId: user_id }
| otherwise = Left "Invalid response from server"
postForgotPasswordRequest :: Backend -> String -> Aff (Either String { status :: String })
postForgotPasswordRequest backend email =
decode <$> REST.post Nothing (toUrl backend "async/forgot-password") { email }
where
decode (Left err) = Left $ "Error when sending REST.post: " <> show err
decode (Right s) = Right s
get :: forall a p. JSON.ReadForeign a => ToUrl Session p =>
Session -> p -> REST.AffRESTError a
get session@(Session {token}) p = REST.get (Just token) (toUrl session p)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment