refactor for multiple public keys
This commit is contained in:
parent
d69e953c35
commit
5bca45faf3
@ -175,7 +175,6 @@ instance YesodAuth App where
|
|||||||
, userName = Nothing
|
, userName = Nothing
|
||||||
, userIsAdmin = False
|
, userIsAdmin = False
|
||||||
, userLocalId = Nothing
|
, userLocalId = Nothing
|
||||||
, userSshPubKey = Nothing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- You can add other plugins like BrowserID, email or OAuth here
|
-- You can add other plugins like BrowserID, email or OAuth here
|
||||||
|
@ -13,7 +13,9 @@ getYourAccountR :: Handler Html
|
|||||||
getYourAccountR = do
|
getYourAccountR = do
|
||||||
userId <- requireAuthId
|
userId <- requireAuthId
|
||||||
user <- runDB $ get404 userId
|
user <- runDB $ get404 userId
|
||||||
(formWidget, formEnctype) <- generateFormPost (yourAccountForm (userName user) (userLocalId user) (userSshPubKey user))
|
keyS <- runDB $ selectFirst [PublicKeyUser ==. userId] []
|
||||||
|
let key = publicKeyPubkey <$> entityVal <$> keyS
|
||||||
|
(formWidget, formEnctype) <- generateFormPost (yourAccountForm (userName user) (userLocalId user) key)
|
||||||
let submission = Nothing :: Maybe (Import.FileInfo, Text)
|
let submission = Nothing :: Maybe (Import.FileInfo, Text)
|
||||||
handlerName = "getYourAccountR" :: Text
|
handlerName = "getYourAccountR" :: Text
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
@ -75,8 +77,15 @@ updateLocalIdAndPubKey userId (Just localId) maybeSshPubKey = do
|
|||||||
case userLocalId user of
|
case userLocalId user of
|
||||||
Just prevLocalId -> do
|
Just prevLocalId -> do
|
||||||
unless (prevLocalId == localId) $ setMessage $ toHtml ("only the administrator can change your ID" :: Text)
|
unless (prevLocalId == localId) $ setMessage $ toHtml ("only the administrator can change your ID" :: Text)
|
||||||
Nothing -> do
|
Nothing -> return ()
|
||||||
runDB $ update userId [UserLocalId =. (Just localId), UserSshPubKey =. maybeSshPubKey]
|
runDB $ deleteWhere [PublicKeyUser ==. userId]
|
||||||
|
case maybeSshPubKey of
|
||||||
|
Just key -> do
|
||||||
|
runDB $ insert $ PublicKey {
|
||||||
|
publicKeyUser=userId,
|
||||||
|
publicKeyPubkey=key }
|
||||||
|
return ()
|
||||||
|
Nothing -> return ()
|
||||||
else
|
else
|
||||||
setMessage $ toHtml ("unexpected ID (use only lower-case letters, digits and hyphens, start with a letter)" :: Text)
|
setMessage $ toHtml ("unexpected ID (use only lower-case letters, digits and hyphens, start with a letter)" :: Text)
|
||||||
|
|
||||||
|
@ -5,8 +5,10 @@ User
|
|||||||
name Text Maybe
|
name Text Maybe
|
||||||
isAdmin Bool default=True
|
isAdmin Bool default=True
|
||||||
localId Text Maybe
|
localId Text Maybe
|
||||||
sshPubKey Text Maybe
|
|
||||||
deriving Typeable
|
deriving Typeable
|
||||||
|
PublicKey
|
||||||
|
user UserId
|
||||||
|
pubkey Text
|
||||||
Email
|
Email
|
||||||
email Text
|
email Text
|
||||||
user UserId Maybe
|
user UserId Maybe
|
||||||
|
Loading…
Reference in New Issue
Block a user