Skip to content

Commit

Permalink
WIP: Key export / import
Browse files Browse the repository at this point in the history
Related to #13
  • Loading branch information
bakkdoor committed Mar 17, 2018
1 parent 55b71fe commit 014ac65
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 91 deletions.
20 changes: 20 additions & 0 deletions src/Daemon.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Daemon
, addVaultUser
, attemptDelayed
, deleteVault
, exportUserKey
, exportVault
, getConfig
, getFlyingVault
Expand Down Expand Up @@ -74,6 +75,7 @@ type ApiPath
| Login
| LoginCheck
| Logout
| ExportUserKey


type ApiStreamPath
Expand Down Expand Up @@ -422,6 +424,21 @@ exportVault vaultId path { config } =
|> Cmd.map (ExportedVault vaultId)


exportUserKey : String -> Model -> Cmd Msg
exportUserKey path { config } =
let
json =
Json.Encode.object [ ( "path", Json.Encode.string path ) ]
in
config
|> apiRequest
Post
ExportUserKey
(Json json)
exportStatusResponseDecoder
|> Cmd.map ExportedUserKey


type alias Path =
String

Expand Down Expand Up @@ -507,6 +524,9 @@ apiPath apiPath =
Logout ->
"auth/logout"

ExportUserKey ->
"user_key_export"


{-| Converts `RequestMethod` into `String`.
Expand Down
20 changes: 20 additions & 0 deletions src/MainScreen.elm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ subscriptions model =
, Time.every Time.second (Date.fromTime >> SetTime)
, Time.every model.config.updateInterval (\_ -> UpdateStats)
, Ports.getEmailCompletionList EmailCompletionList
, Ports.selectedUserKeyExportFile SelectedUserKeyExportFile
]

_ ->
Expand Down Expand Up @@ -366,6 +367,25 @@ update msg model =
, Cmd.none
)

OpenUserKeyExportDialog ->
( model
, Ports.openUserKeyExportFileDialog "Export Key to file"
)

SelectedUserKeyExportFile filePath ->
let
_ =
Debug.log "SelectedUserKeyExportFile" filePath
in
( model
, Daemon.exportUserKey filePath model
)

ExportedUserKey _ ->
( model
, Cmd.none
)


setSetupWizardEmail : String -> Model -> Model
setSetupWizardEmail email ({ setupWizard, loginDialog } as model) =
Expand Down
3 changes: 3 additions & 0 deletions src/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ type Msg
| SendPasswordResetLink
| SetupWizardEmail String
| SetupWizardPassword String
| OpenUserKeyExportDialog
| SelectedUserKeyExportFile String
| ExportedUserKey (WebData ExportStatusResponse)



Expand Down
8 changes: 8 additions & 0 deletions src/Ports.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ port module Ports
, focusOn
, getEmailCompletionList
, openPasswordResetInBrowser
, openUserKeyExportFileDialog
, openVaultFolder
, selectedUserKeyExportFile
, updateEmailCompletionList
)

Expand All @@ -25,3 +27,9 @@ port getEmailCompletionList : (List String -> msg) -> Sub msg


port openPasswordResetInBrowser : () -> Cmd msg


port openUserKeyExportFileDialog : String -> Cmd msg


port selectedUserKeyExportFile : (String -> msg) -> Sub msg
12 changes: 12 additions & 0 deletions src/SettingsDialog/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ contents model =
, languageButton German model
, languageButton English model
, separator
, div [ class "InfoLabel" ]
[ text "Key export / import" ]
, keyExportButton model
, separator
, div [ class "InfoLabel" ]
[ text <| dialogText T.AccountOptions model ]
, changePasswordButton model
Expand All @@ -61,6 +65,14 @@ contents model =
]


keyExportButton : HasSettingsDialog a -> Html Model.Msg
keyExportButton model =
button [ class "Button" ]
{ onClick = Model.OpenUserKeyExportDialog
, label = "Export Key"
}


changePasswordButton : HasSettingsDialog a -> Html Model.Msg
changePasswordButton model =
button [ class "Button" ]
Expand Down
42 changes: 6 additions & 36 deletions src/SetupWizard.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import Language exposing (Language(..))
import Model
import Util exposing (ButtonSettings, Position(..), button)
import WizardDialog.Model exposing (..)
import WizardDialog.View
exposing
( infoText
, infoTextWithHeader
, infoTextWithHeaders
)


steps : List (StepConfig Model.Model Model.Msg)
Expand Down Expand Up @@ -41,42 +47,6 @@ viewSettings state model =
WizardDialog.Model.viewSettings steps state model


infoTextLine : String -> Html msg
infoTextLine line =
span []
[ text line ]


infoText : List (Html.Attribute msg) -> List String -> Html msg
infoText attrs lines =
div [ class "InfoText" ]
[ div attrs
(List.map infoTextLine lines)
]


infoTextWithHeader : List (Html.Attribute msg) -> String -> List String -> Html msg
infoTextWithHeader attrs header lines =
div [ class "InfoText" ]
[ div attrs <|
span [ class "Header" ]
[ text header ]
:: List.map infoTextLine lines
]


infoTextWithHeaders : List (Html.Attribute msg) -> String -> String -> List String -> Html msg
infoTextWithHeaders attrs header subHeader lines =
div [ class "InfoText" ]
[ div attrs <|
span [ class "Header" ]
[ text header ]
:: span [ class "SubHeader" ]
[ text subHeader ]
:: List.map infoTextLine lines
]



-- STEPS

Expand Down
45 changes: 45 additions & 0 deletions src/WizardDialog/View.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module WizardDialog.View
exposing
( infoText
, infoTextWithHeader
, infoTextWithHeaders
)

import Html exposing (Html, div, span, text)
import Html.Attributes exposing (class)


infoTextLine : String -> Html msg
infoTextLine line =
span []
[ text line ]


infoText : List (Html.Attribute msg) -> List String -> Html msg
infoText attrs lines =
div [ class "InfoText" ]
[ div attrs
(List.map infoTextLine lines)
]


infoTextWithHeader : List (Html.Attribute msg) -> String -> List String -> Html msg
infoTextWithHeader attrs header lines =
div [ class "InfoText" ]
[ div attrs <|
span [ class "Header" ]
[ text header ]
:: List.map infoTextLine lines
]


infoTextWithHeaders : List (Html.Attribute msg) -> String -> String -> List String -> Html msg
infoTextWithHeaders attrs header subHeader lines =
div [ class "InfoText" ]
[ div attrs <|
span [ class "Header" ]
[ text header ]
:: span [ class "SubHeader" ]
[ text subHeader ]
:: List.map infoTextLine lines
]
62 changes: 7 additions & 55 deletions static/MainScreen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ li {
.MainScreen {
width: 70%;
height: 100%;
-webkit-transition: width 0.5s;
transition: width 0.5s;
}

.MainScreen-Container {
Expand Down Expand Up @@ -167,65 +167,17 @@ li {
height: 300px;
overflow-y: scroll;

.InfoText {
line-height: ($font-size-regular + $padding-tiny);

.TermsOfService {
span {
line-height: ($font-size-regular + $padding-tiny);
display: block;
}

.Header {
font-weight: bold;
font-size: $font-size-header;
margin-bottom: $padding-tiny;
}

.SubHeader {
font-weight: bold;
margin-bottom: $padding-tiny;
}

.TermsOfService {
span {
margin-top: $padding-tiny;
text-align: justify;
}
margin-top: $padding-tiny;
text-align: justify;
}
}

.Options {
display: block;
max-width: 50%;
margin-top: $padding-medium;

.ForgotPasswordButton {
button {
margin-top: $padding-small;
margin-right: $padding-small;
}

.InputLabel {
margin-top: $padding-small;
font-weight: bold;
}

input {
margin-top: $padding-tiny;
font-size: $font-size-regular;
height: $font-size-small;
width: 200px;
padding-top: $padding-tiny;
padding-bottom: $padding-tiny;
padding-left: $padding-small;
padding-right: $padding-small;
border: $border-radius-input solid #3AE2E2 !important;
}

.ForgotPasswordButton {
button {
margin-top: $padding-medium;
margin-bottom: $padding-small;
}
margin-top: $padding-medium;
margin-bottom: $padding-small;
}
}
}
Expand Down
48 changes: 48 additions & 0 deletions static/WizardDialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,52 @@
.Button-Close {
float: right;
}

.InfoText {
line-height: ($font-size-regular + $padding-tiny);

span {
line-height: ($font-size-regular + $padding-tiny);
display: block;
}

.Header {
font-weight: bold;
font-size: $font-size-header;
margin-bottom: $padding-tiny;
}

.SubHeader {
font-weight: bold;
margin-bottom: $padding-tiny;
}
}

.Options {
display: block;
max-width: 50%;
margin-top: $padding-medium;

button {
margin-top: $padding-small;
margin-right: $padding-small;
}

.InputLabel {
margin-top: $padding-small;
font-weight: bold;
}

input {
margin-top: $padding-tiny;
font-size: $font-size-regular;
height: $font-size-small;
width: 200px;
padding-top: $padding-tiny;
padding-bottom: $padding-tiny;
padding-left: $padding-small;
padding-right: $padding-small;
border: $border-radius-input solid #3AE2E2 !important;
}
}
}
11 changes: 11 additions & 0 deletions static/ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ const openPasswordResetInBrowser = () => {
}
}

const openUserKeyExportFileDialog = (buttonLabel) => {
Electron.remote.dialog.showSaveDialog({
title: "Select file to export your key to",
buttonLabel: buttonLabel,
filters: [{ name: "User Key Export Archive", extensions: ["zip"] }]
}, (file) => {
elmApp.ports.selectedUserKeyExportFile.send(file);
});
}

var setupElmApp = function (daemonApiToken) {
elmApp = Elm.Main.embed(mainContainer, {
apiAuthToken: daemonApiToken,
Expand All @@ -155,6 +165,7 @@ var setupElmApp = function (daemonApiToken) {
elmApp.ports.addEmailToCompletionList.subscribe(addEmailToCompletionList)
elmApp.ports.updateEmailCompletionList.subscribe(updateEmailCompletionList)
elmApp.ports.openPasswordResetInBrowser.subscribe(openPasswordResetInBrowser)
elmApp.ports.openUserKeyExportFileDialog.subscribe(openUserKeyExportFileDialog)
}

readAuthToken(setupElmApp)

0 comments on commit 014ac65

Please sign in to comment.