Commit b945f6f1 authored by Steffen Michels's avatar Steffen Michels Committed by Bas Lijnse

improve user admin

parent 52e87624
......@@ -37,7 +37,7 @@ importDemoUsers = allTasks (map mkDemoUser namesRoles)
where
mkDemoUser t
# u = demoUser t
= catchAll (createUser u) (\_ -> return u)
= catchAll (createUser u @ const u) (\_ -> return u)
demoUser (ppname, username, role)
= { UserAccount
| credentials = { Credentials
......
......@@ -3,7 +3,7 @@ implementation module Administration.Tasks
import iTasks
import Text
import Text.HTML
import Data.Either, Data.Maybe
import Data.Either, Data.Maybe, Data.Functor
import Task.Extensions
import System.Directory, System.FilePath
import Cadastre.SDS, ChamberOfCommerce.SDS, Compensation.SDS, CivilAffairs.SDS
......@@ -121,8 +121,8 @@ convertExampleData
>>= \cadastre -> viewInformation "cadastre:" [] cadastre
>>| readLinesFromFile (examplefilepath curDir "officers.txt")
>>- \officers -> importDemoUsersFlow
>>- \demoAccounts ->
set ([{UserAccount | credentials = { username = Username "root", password = Password "root"}
>>- \demoAccounts -> allTasks
(createUser <$> [{UserAccount | credentials = { username = Username "root", password = Password "root"}
, title = Just "root", roles = ["admin","programmer","god"]
}] ++
[{UserAccount | demo & roles = ["admin"]} \\ demo <- demoAccounts] ++
......@@ -139,7 +139,7 @@ convertExampleData
}
\\ cv <- cvs]
) userAccounts
)
>>= viewInformation "accounts" []
>>| viewInformation "Done!" [] ()
where
......
......@@ -12,7 +12,7 @@ main :: Task ()
main = myExample @! ()
multiUserExample
= set (map mkUserAccount players) userAccounts
= allTasks (map (createUser o mkUserAccount) players)
>>| viewInformation "Login under one of the following names (password = login name)" []
(foldl (+++) "" (map (\n -> n +++ ", ") players))
-||-
......@@ -21,7 +21,7 @@ multiUserExample
>>| loginAndManageWork "Chat_4_2 Example"
where
mkUserAccount name
= { credentials = { username = Username name, password = Password name}, title = Nothing, roles = ["manager"] }
= {UserAccount| credentials = {Credentials| username = Username name, password = Password name}, title = Nothing, roles = ["manager"] }
// -------------------------------------------------------------------------
// Simple MultiUser Chat Application for 2 users
......
......@@ -15,7 +15,7 @@ main :: Task ()
main = multiUserExample @! ()
multiUserExample
= set (map mkUserAccount players) userAccounts
= allTasks (map (createUser o mkUserAccount) players)
>>| viewInformation "Login under one of the following names (password = login name)" []
(join ", " players)
-||-
......@@ -24,7 +24,7 @@ multiUserExample
>>| loginAndManageWork "Meeting_4_3 Example"
where
mkUserAccount name
= { credentials = { username = Username name, password = Password name}, title = Nothing, roles = ["manager"] }
= {UserAccount| credentials = {Credentials| username = Username name, password = Password name}, title = Nothing, roles = ["manager"] }
// -------------------------------------------------------------------------
......
......@@ -15,7 +15,7 @@ main :: Task ()
main = multiUserExample @! ()
multiUserExample
= set (map mkUserAccount logins) userAccounts
= allTasks (map (createUser o mkUserAccount) logins)
>>| viewInformation "Login under one of the following names (password = login name)" []
(foldl (+++) "" (map (\n -> n +++ ", ") logins))
-||-
......@@ -24,7 +24,7 @@ multiUserExample
>>| loginAndManageWork "Chat_4_2 Example"
where
mkUserAccount name
= { credentials = { username = Username name, password = Password name}, title = Nothing, roles = ["manager"] }
= {UserAccount| credentials = {Credentials| username = Username name, password = Password name}, title = Nothing, roles = ["manager"] }
// -------------------------------------------------------------------------
......
......@@ -11,12 +11,29 @@ import iTasks.Extensions.User
, roles :: ![Role]
}
derive class iTask UserAccount
/**
* A user account which can safely be stored, as it does not contains the password in cleartext.
*/
:: StoredUserAccount =
{ credentials :: !StoredCredentials
, title :: !Maybe UserTitle
, roles :: ![Role]
}
/**
* Stored user credentials not containing the password in cleartext.
*/
:: StoredCredentials = { username :: !Username //* The username.
, saltedPasswordHash :: !String //* The salted SHA1 password hash.
, salt :: !String //* The 32-byte random salt.
}
derive class iTask UserAccount, StoredUserAccount, StoredCredentials
// Shares
//* All user accounts
userAccounts :: Shared [UserAccount]
userAccounts :: Shared [StoredUserAccount]
//* All users
users :: ReadOnlyShared [User]
......@@ -56,7 +73,7 @@ doAuthenticatedWith :: !(Credentials -> Task (Maybe User)) (Task a) -> Task a |
*
* @gin-icon user_add
*/
createUser :: !UserAccount -> Task UserAccount
createUser :: !UserAccount -> Task StoredUserAccount
/**
* Delete an existing user
*
......
......@@ -123,13 +123,11 @@ newInstanceNo iworld
= (Error e,iworld)
newInstanceKey :: !*IWorld -> (!InstanceKey, !*IWorld)
newInstanceKey iworld=:{IWorld|random}
= (toString (take 32 [toChar (97 + abs (i rem 26)) \\ i <- random]) , {IWorld|iworld & random = drop 32 random})
newInstanceKey iworld = generateRandomString 32 iworld
newDocumentId :: !*IWorld -> (!DocumentId, !*IWorld)
newDocumentId iworld=:{IWorld|random}
= (toString (take 32 [toChar (97 + abs (i rem 26)) \\ i <- random]) , {IWorld|iworld & random = drop 32 random})
newDocumentId iworld = generateRandomString 32 iworld
createClientTaskInstance :: !(Task a) !String !InstanceNo !*IWorld -> *(!MaybeError TaskException TaskId, !*IWorld) | iTask a
createClientTaskInstance task sessionId instanceNo iworld=:{options={appVersion},current={taskTime},clock}
//Create the initial instance data in the store
......
......@@ -28,3 +28,5 @@ liftIWorld :: (*World -> *(.a, *World)) *IWorld -> *(.a, *IWorld)
//Apply an IWorld transformer and transform the result to a taskresult
apIWTransformer :: *env (*env -> *(MaybeError TaskException (TaskResult a), *env)) -> *(TaskResult a, *env)
generateRandomString :: !Int !*IWorld -> (!String, !*IWorld)
......@@ -59,3 +59,7 @@ apIWTransformer :: *env (*env -> *(MaybeError TaskException (TaskResult a), *env
apIWTransformer iw f = case f iw of
(Error e, iw) = (ExceptionResult e, iw)
(Ok tv, iw) = (tv, iw)
generateRandomString :: !Int !*IWorld -> (!String, !*IWorld)
generateRandomString length iworld=:{IWorld|random}
= (toString (take length [toChar (97 + abs (i rem 26)) \\ i <- random]) , {IWorld|iworld & random = drop length random})
......@@ -20,6 +20,9 @@ unitShare :: SDS () () ()
// Random source
randomInt :: SDS () Int ()
// Random string (the parameters determines its length)
randomString :: SDS Int String ()
// world function share
worldShare :: (p *World -> *(MaybeErrorString r,*World)) (p w *World -> *(MaybeErrorString (),*World)) -> SDS p r w
......
......@@ -4,6 +4,7 @@ import iTasks.SDS.Definition
import iTasks.Internal.SDS
import iTasks.Internal.IWorld
import iTasks.Internal.Serialization
import iTasks.Internal.Util
import System.FilePath, System.Directory, System.File
import Text, Text.GenJSON
import StdFile, StdTuple, StdArray, StdBool, StdList, StdString
......@@ -39,6 +40,9 @@ where
randomInt () iworld=:{IWorld|random=[i:is]}
= (i, {IWorld|iworld & random = is})
randomString :: SDS Int String ()
randomString = createReadOnlySDS generateRandomString
memoryShare :: SDS String (Maybe a) (Maybe a) | TC a
memoryShare = createReadWriteSDS "_core_" "memoryShare" read write
where
......
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