diff --git a/Foundation.hs b/Foundation.hs index bcbe1bf..2a38265 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -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 diff --git a/Handler/YourAccount.hs b/Handler/YourAccount.hs index d7150d7..58ca425 100644 --- a/Handler/YourAccount.hs +++ b/Handler/YourAccount.hs @@ -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) diff --git a/config/models b/config/models index 5536ed4..ec3117c 100644 --- a/config/models +++ b/config/models @@ -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