feat(lms): random ident pw generation without db
This commit is contained in:
parent
efcc9526ac
commit
21b74a5d7f
@ -14,6 +14,7 @@ module Handler.Utils.LMS
|
|||||||
, csvFilenameLmsResult
|
, csvFilenameLmsResult
|
||||||
, lmsUserToDelete, _lmsUserToDelete
|
, lmsUserToDelete, _lmsUserToDelete
|
||||||
, lmsUserToDeleteExpr
|
, lmsUserToDeleteExpr
|
||||||
|
, randomLMSIdent, randomLMSpw
|
||||||
) where
|
) where
|
||||||
|
|
||||||
-- general utils for LMS Interface Handlers
|
-- general utils for LMS Interface Handlers
|
||||||
@ -22,6 +23,10 @@ import Import
|
|||||||
import Handler.Utils
|
import Handler.Utils
|
||||||
import qualified Database.Esqueleto.Legacy as E
|
import qualified Database.Esqueleto.Legacy as E
|
||||||
|
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.UUID as UUID (toText)
|
||||||
|
import qualified Data.UUID.V4 as UUID (nextRandom)
|
||||||
|
|
||||||
-- generic Column names
|
-- generic Column names
|
||||||
csvLmsIdent :: IsString a => a
|
csvLmsIdent :: IsString a => a
|
||||||
csvLmsIdent = fromString "user" -- "Benutzerkennung"
|
csvLmsIdent = fromString "user" -- "Benutzerkennung"
|
||||||
@ -83,3 +88,24 @@ lmsUserToDelete LmsUser{lmsUserEnded, lmsUserStatus} = isNothing lmsUserEnded &&
|
|||||||
_lmsUserToDelete :: Getter LmsUser Bool
|
_lmsUserToDelete :: Getter LmsUser Bool
|
||||||
_lmsUserToDelete = to lmsUserToDelete
|
_lmsUserToDelete = to lmsUserToDelete
|
||||||
|
|
||||||
|
|
||||||
|
-- random generation of LmsIdentifiers, maybe this should be in Model.Types.Lms since length specifications are type-y?
|
||||||
|
|
||||||
|
lengthIdent :: Int
|
||||||
|
lengthIdent = 8
|
||||||
|
|
||||||
|
lengthPassword :: Int
|
||||||
|
lengthPassword = 8
|
||||||
|
|
||||||
|
randomText :: MonadIO m => Int -> m Text
|
||||||
|
randomText n
|
||||||
|
| n <= 8 = T.take n . UUID.toText <$> liftIO UUID.nextRandom
|
||||||
|
| n <= 32 = T.take n . T.filter ('-' ==) . UUID.toText <$> liftIO UUID.nextRandom
|
||||||
|
| otherwise = (<>) <$> randomText 32 <*> randomText (n - 32)
|
||||||
|
|
||||||
|
randomLMSIdent :: MonadIO m => m LmsIdent
|
||||||
|
randomLMSIdent = LmsIdent <$> randomText lengthIdent
|
||||||
|
|
||||||
|
randomLMSpw :: MonadIO m => m Text
|
||||||
|
randomLMSpw = randomText lengthPassword
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user