add foreign key and error check on no user
This commit is contained in:
parent
4599e2a7e9
commit
e75dc37fe3
1 changed files with 11 additions and 6 deletions
|
@ -36,7 +36,7 @@ import Data.ByteString.Random
|
||||||
|
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
|
|
||||||
import Opaleye
|
import Opaleye hiding (null)
|
||||||
import qualified Opaleye.Constant as C
|
import qualified Opaleye.Constant as C
|
||||||
|
|
||||||
-- internal imports
|
-- internal imports
|
||||||
|
@ -47,7 +47,7 @@ import Types.Reader
|
||||||
import Model.User
|
import Model.User
|
||||||
|
|
||||||
initToken :: PGS.Query
|
initToken :: PGS.Query
|
||||||
initToken = "create table if not exists \"token\" (token_string bytea not null primary key, token_user integer not null, token_expiry timestamptz not null)"
|
initToken = "create table if not exists \"token\" (token_string bytea not null primary key, token_user integer references \"user\"(user_id) not null, token_expiry timestamptz not null)"
|
||||||
|
|
||||||
tokenTable :: Table
|
tokenTable :: Table
|
||||||
( Field SqlBytea
|
( Field SqlBytea
|
||||||
|
@ -88,10 +88,15 @@ getUserAuthInfo ident = do
|
||||||
, Maybe Int
|
, Maybe Int
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
head <$> mapM (\(i1, i2, i3, i4, i5, i6, i7, i8, i9) ->
|
if null users
|
||||||
AuthInfo (AuthSalt i7) (toEnum $ fromMaybe 0 i9) <$> newTicket ident
|
then throwError $ err404
|
||||||
)
|
{ errBody = "No such user"
|
||||||
users
|
}
|
||||||
|
else
|
||||||
|
head <$> mapM (\(i1, i2, i3, i4, i5, i6, i7, i8, i9) ->
|
||||||
|
AuthInfo (AuthSalt i7) (toEnum $ fromMaybe 0 i9) <$> newTicket ident
|
||||||
|
)
|
||||||
|
users
|
||||||
|
|
||||||
validateToken
|
validateToken
|
||||||
:: PGS.Connection
|
:: PGS.Connection
|
||||||
|
|
Loading…
Reference in a new issue