Commit 37d418f2 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] Username could be email

parent 87420e23
Pipeline #3838 failed with stage
in 31 minutes and 26 seconds
......@@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack
name: gargantext
version: 0.0.6.9.8.2.2
version: 0.0.6.9.8.3
synopsis: Search, map, share
description: Please see README.md
category: Data
......@@ -45,8 +45,8 @@ library
Gargantext.API.Node.Share
Gargantext.API.Prelude
Gargantext.Core
Gargantext.Core.Methods.Similarities
Gargantext.Core.NLP
Gargantext.Core.Methods.Similarities
Gargantext.Core.NodeStory
Gargantext.Core.Text
Gargantext.Core.Text.Context
......
......@@ -60,6 +60,7 @@ import Gargantext.Database.Prelude (Cmd', CmdM, CmdCommon)
import Gargantext.Database.Query.Table.User
import Gargantext.Database.Query.Tree (isDescendantOf, isIn)
import Gargantext.Database.Query.Tree.Root (getRoot)
import Gargantext.Database.Action.User.New (guessUserName)
import Gargantext.Database.Schema.Node (NodePoly(_node_id))
import Gargantext.Prelude hiding (reverse)
import Gargantext.Prelude.Crypto.Pass.User (gargPass)
......@@ -87,15 +88,21 @@ checkAuthRequest :: ( HasSettings env, CmdCommon env, HasJoseError err)
=> Username
-> GargPassword
-> Cmd' env err CheckAuth
checkAuthRequest u (GargPassword p) = do
candidate <- head <$> getUsersWith u
checkAuthRequest couldBeEmail (GargPassword p) = do
-- Sometimes user put email instead of username
-- hence we have to check before
let usrname = case guessUserName couldBeEmail of
Nothing -> couldBeEmail -- we are sure this is not an email
Just (u,_) -> u -- this was an email in fact
candidate <- head <$> getUsersWith usrname
case candidate of
Nothing -> pure InvalidUser
Just (UserLight { userLight_password = GargPassword h, .. }) ->
case Auth.checkPassword (Auth.mkPassword p) (Auth.PasswordHash h) of
Auth.PasswordCheckFail -> pure InvalidPassword
Auth.PasswordCheckSuccess -> do
muId <- head <$> getRoot (UserName u)
muId <- head <$> getRoot (UserName usrname)
case _node_id <$> muId of
Nothing -> pure InvalidUser
Just uid -> do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment