Skip to content

Commit

Permalink
fix: change labels for upload and download exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
ybizeul committed Sep 19, 2024
1 parent 02c0b7b commit d5c407a
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 31 deletions.
6 changes: 3 additions & 3 deletions html/src/Components/ShareEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ export function ShareEditor(props: ShareEditorProps&BoxComponentProps) {
}

{/* Share exposure */}
<Input.Wrapper label={t("exposure")} description={t("guest_users_can")}>
<Input.Wrapper label={t("exposure")} description={t("you_want_to")}>
<SegmentedControl
className={classes.segmented}
value={options.exposure}
data={[ { label: t("upload"), value: 'upload' },
{ label: t("download"), value: 'download' },
data={[ { label: t("receive"), value: 'upload' },
{ label: t("send"), value: 'download' },
{ label: t("both"), value: 'both' },
]}
onChange={(v) => { notifyChange({...options, exposure:v}); }} transitionDuration={0}
Expand Down
12 changes: 6 additions & 6 deletions html/src/i18n/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ i18n
created: "Created",

exposure: "Exposure",
guest_users_can: "Guest users can :",
upload: "Upload",
download: "Download",
you_want_to: "You want to :",
send: "Send",
receive: "Receive",
both: "Both",

validity: "Validity",
Expand Down Expand Up @@ -104,9 +104,9 @@ i18n
created: "Créé le",

exposure: "Type de partage",
guest_users_can: "Les invités peuvent :",
upload: "Envoyer",
download: "Reçevoir",
you_want_to: "Vous souhaitez :",
send: "Envoyer",
receive: "Reçevoir",
both: "Les deux",

validity: "Expiration",
Expand Down
10 changes: 9 additions & 1 deletion hupload/pkg/apiws/apiws.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ func (a *APIWS) Start() {
if _, ok := a.Authentication.CallbackFunc(nil); ok {
// If there is, define action to redirect to "/shares"
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/shares", http.StatusFound)
s, ok := r.Context().Value(authentication.AuthStatusKey).(authentication.AuthStatus)
if ok && s.Authenticated {
http.Redirect(w, r, "/shares", http.StatusFound)
return
}
if r.URL.Query().Get("error") != "" {
http.Error(w, r.URL.Query().Get("error"), http.StatusUnauthorized)
return
}
})
m := auth.NewJWTAuthMiddleware(os.Getenv("JWT_SECRET"))
f, _ := a.Authentication.CallbackFunc(m.Middleware(handler))
Expand Down
40 changes: 21 additions & 19 deletions hupload/pkg/apiws/authentication/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"crypto/rand"
"encoding/base64"
"encoding/json"
"errors"
"io"
"log/slog"
"net/http"
"time"

Expand Down Expand Up @@ -68,7 +68,7 @@ func NewAuthenticationOIDC(o AuthenticationOIDCConfig) (*AuthenticationOIDC, err
Endpoint: result.Provider.Endpoint(),

// "openid" is a required scope for OpenID Connect flows.
Scopes: []string{oidc.ScopeOpenID, "profile", "email"},
Scopes: []string{oidc.ScopeOpenID, "email", "profile"},
}

return result, nil
Expand Down Expand Up @@ -107,8 +107,7 @@ func (o *AuthenticationOIDC) CallbackFunc(h http.Handler) (func(w http.ResponseW

oauth2Token, err := o.Config.Exchange(r.Context(), r.URL.Query().Get("code"))
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_ = json.NewEncoder(w).Encode(err)
ServeNextError(h, errors.New("code verification failed"), w, r)
return
}

Expand All @@ -123,21 +122,18 @@ func (o *AuthenticationOIDC) CallbackFunc(h http.Handler) (func(w http.ResponseW
// Parse and verify ID Token payload.
idToken, err := verifier.Verify(r.Context(), rawIDToken)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_ = json.NewEncoder(w).Encode(err)
ServeNextError(h, errors.New("token verification failed"), w, r)
return
}

nonce, err := r.Cookie("nonce")
if err != nil {
w.WriteHeader(http.StatusBadRequest)
_ = json.NewEncoder(w).Encode(err)
ServeNextError(h, errors.New("missing nonce"), w, r)
//http.Error(w, "nonce not found", http.StatusBadRequest)
return
}
if idToken.Nonce != nonce.Value {
w.WriteHeader(http.StatusBadRequest)
_ = json.NewEncoder(w).Encode(err)
ServeNextError(h, errors.New("nonce doesn't match"), w, r)
//http.Error(w, "nonce did not match", http.StatusBadRequest)
return
}
Expand All @@ -148,26 +144,32 @@ func (o *AuthenticationOIDC) CallbackFunc(h http.Handler) (func(w http.ResponseW
Username string `json:"preferred_username"`
}
if err := idToken.Claims(&claims); err != nil {
w.WriteHeader(http.StatusInternalServerError)
_ = json.NewEncoder(w).Encode(err)
ServeNextError(h, err, w, r)
return
}

var rmessage json.RawMessage
if err := idToken.Claims(&rmessage); err == nil {
b, _ := json.MarshalIndent(rmessage, "", " ")
slog.Info("ID Token Claims: %s", slog.String("claims", string(b)))
}
// var rmessage json.RawMessage
// if err := idToken.Claims(&rmessage); err == nil {
// b, _ := json.MarshalIndent(rmessage, "", " ")
// slog.Info("ID Token Claims: %s", slog.String("claims", string(b)))
// }

ServeNextAuthenticated(claims.Username, h, w, r)
if claims.Username != "" {
ServeNextAuthenticated(claims.Username, h, w, r)
return
}
h.ServeHTTP(w, r)
}, true
}

func ServeNextAuthenticated(user string, next http.Handler, w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), AuthStatusKey, AuthStatus{Authenticated: true, User: user})
next.ServeHTTP(w, r.WithContext(ctx))
}

func ServeNextError(next http.Handler, err error, w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), AuthStatusKey, AuthStatus{Authenticated: false, User: "", Error: err})
next.ServeHTTP(w, r.WithContext(ctx))
}
func (o *AuthenticationOIDC) ShowLoginForm() bool {
return false
}
Expand Down
Binary file modified readme_images/properties-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified readme_images/properties-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified readme_images/properties-preview-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified readme_images/properties-preview-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified readme_images/shares-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified readme_images/shares-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions robot/Screenshots.robot
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Screenshot Home Page
Sleep 0.5 second
Click css=\#showEditor
Sleep 0.5 second
Take Screenshot ${CURDIR}/../readme_images/properties-${theme}.png crop={'x': 0, 'y': 216, 'width': 800, 'height': 345}
Take Screenshot ${CURDIR}/../readme_images/properties-${theme}.png crop={'x': 0, 'y': 222, 'width': 800, 'height': 346}
Click css=\#preview
Take Screenshot ${CURDIR}/../readme_images/properties-preview-${theme}.png crop={'x': 0, 'y': 216, 'width': 800, 'height': 345}
Take Screenshot ${CURDIR}/../readme_images/properties-preview-${theme}.png crop={'x': 0, 'y': 222, 'width': 800, 'height': 346}


Click css=\#kuva-yibi-bata \#edit
Expand Down

0 comments on commit d5c407a

Please sign in to comment.