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