diff --git a/front/package-lock.json b/front/package-lock.json index e20278781b..87affcee8f 100644 --- a/front/package-lock.json +++ b/front/package-lock.json @@ -2995,9 +2995,9 @@ "dev": true }, "@gladysassistant/gladys-gateway-js": { - "version": "3.9.0", - "resolved": "https://registry.npmjs.org/@gladysassistant/gladys-gateway-js/-/gladys-gateway-js-3.9.0.tgz", - "integrity": "sha512-zAIrc48rAS32Yqf1jkaVGZaXWy5EpUzDP/dPRusoOyIYJ9j2Wm1nwlotqq/m9nf4uINqzfLhiYJ5PH3cTPF3kg==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@gladysassistant/gladys-gateway-js/-/gladys-gateway-js-4.2.0.tgz", + "integrity": "sha512-ATkDhUnFzNpE39o/CqTvR8TzfxSn52AxiJAXXCvDJS6cp1DBQ8G1wqCjKxrV2Ef+rnYMV4Ir+YIohimnH46oJg==", "requires": { "@ctrlpanel/pbkdf2": "^1.0.0", "array-buffer-to-hex": "^1.0.0", @@ -4338,7 +4338,7 @@ "after": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz", - "integrity": "sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=" + "integrity": "sha512-QbJ0NTQ/I9DI3uSJA4cbexiwQeRAfjPScqIbSjUDd9TOrcg6pTkdgziesOqxBMBzit8vFCTwrP27t13vFOORRA==" }, "aggregate-error": { "version": "3.1.0", @@ -5902,7 +5902,7 @@ "backo2": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", - "integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc=" + "integrity": "sha512-zj6Z6M7Eq+PBZ7PQxl5NT665MvJdAkzp0f60nAJ+sLaSCBPMwVak5ZegFbgVCzFcCJTKFoMizvM5Ld7+JrRJHA==" }, "balanced-match": { "version": "1.0.0", @@ -5974,7 +5974,7 @@ "base64-arraybuffer": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.4.tgz", - "integrity": "sha1-mBjHngWbE1X5fgQooBfIOOkLqBI=" + "integrity": "sha512-a1eIFi4R9ySrbiMuyTGx5e92uRH5tQY6kArNcFaKBUleIoLjdjBg7Zxm3Mqm3Kmkf27HLR/1fnxX9q8GQ7Iavg==" }, "base64-js": { "version": "1.3.1", diff --git a/front/package.json b/front/package.json index f1a04161a1..1c4c3a12cf 100644 --- a/front/package.json +++ b/front/package.json @@ -43,7 +43,7 @@ "prettier": "^1.17.1" }, "dependencies": { - "@gladysassistant/gladys-gateway-js": "^3.9.0", + "@gladysassistant/gladys-gateway-js": "^4.2.0", "@gladysassistant/theme-optimized": "^1.0.3", "@jaames/iro": "^5.5.2", "@yaireo/tagify": "^4.5.0", diff --git a/front/src/components/app.jsx b/front/src/components/app.jsx index 90b46113a3..0ab4944604 100644 --- a/front/src/components/app.jsx +++ b/front/src/components/app.jsx @@ -27,6 +27,7 @@ import GatewayForgotPassword from '../routes/gateway-forgot-password'; import GatewayResetPassword from '../routes/gateway-reset-password'; import GatewayConfirmEmail from '../routes/gateway-confirm-email'; import GoogleHomeGateway from '../routes/integration/all/google-home-gateway'; +import AlexaGateway from '../routes/integration/all/alexa-gateway'; import SignupWelcomePage from '../routes/signup/1-welcome'; import SignupCreateAccountLocal from '../routes/signup/2-create-account-local'; @@ -234,6 +235,7 @@ const AppRouter = connect( + diff --git a/front/src/components/header/index.jsx b/front/src/components/header/index.jsx index 9426c17525..1a6d438f5d 100644 --- a/front/src/components/header/index.jsx +++ b/front/src/components/header/index.jsx @@ -19,7 +19,8 @@ const PAGES_WITHOUT_HEADER = [ '/subscribe-gateway', '/gateway-configure-two-factor', '/confirm-email', - '/dashboard/integration/device/google-home/authorize' + '/dashboard/integration/device/google-home/authorize', + '/dashboard/integration/device/alexa/authorize' ]; const Header = ({ ...props }) => { diff --git a/front/src/config/i18n/en.json b/front/src/config/i18n/en.json index e68729a140..93755029b8 100644 --- a/front/src/config/i18n/en.json +++ b/front/src/config/i18n/en.json @@ -542,6 +542,20 @@ "cancelButton": "Cancel", "connectButton": "Link" }, + "alexa": { + "title": "Gladys Assistant", + "cardTitle": "Do you want to connect Gladys Assistant to Amazon Alexa?", + "description": "By signin in, you are authorizing Alexa to access your devices.", + "error": "An error occured. Please retry !", + "connectedAs": "Connected as", + "googleWillBeAble": "Alexa will be able:", + "seeDevices": "List all your devices", + "controlDevices": "Control all your devices", + "getNewDeviceValues": "Periodically refresh your device states", + "privacyPolicy": "Read Alexa's privacy policy.", + "cancelButton": "Cancel", + "connectButton": "Link" + }, "zwave": { "title": "Z-Wave", "description": "Control your Z-Wave devices.", diff --git a/front/src/config/i18n/fr.json b/front/src/config/i18n/fr.json index 0044a21e78..230b664075 100644 --- a/front/src/config/i18n/fr.json +++ b/front/src/config/i18n/fr.json @@ -669,6 +669,20 @@ "cancelButton": "Annuler", "connectButton": "Lier" }, + "alexa": { + "title": "Gladys Assistant", + "cardTitle": "Voulez-vous connecter Gladys Assistant à Amazon Alexa ?", + "description": "En vous connectant, vous authorizez Alexa à accéder à vos appareils.", + "error": "Une erreur est survenue. Merci de réessayer.", + "connectedAs": "Connecté en tant que", + "googleWillBeAble": "Amazon Alexa pourra :", + "seeDevices": "Lister les appareils présents chez vous", + "controlDevices": "Contrôler vos appareils", + "getNewDeviceValues": "Récupérer périodiquement les états de vos appareils", + "privacyPolicy": "Lire la politique de confidentialité d'Alexa.", + "cancelButton": "Annuler", + "connectButton": "Lier" + }, "zwave": { "title": "Z-Wave", "description": "Contrôlez vos appareils Z-Wave.", diff --git a/front/src/routes/integration/all/alexa-gateway/Layout.jsx b/front/src/routes/integration/all/alexa-gateway/Layout.jsx new file mode 100644 index 0000000000..844823c0d3 --- /dev/null +++ b/front/src/routes/integration/all/alexa-gateway/Layout.jsx @@ -0,0 +1,15 @@ +const Layout = ({ children }) => ( +
+
+
+
+
+
{children}
+
+
+
+
+
+); + +export default Layout; diff --git a/front/src/routes/integration/all/alexa-gateway/index.js b/front/src/routes/integration/all/alexa-gateway/index.js new file mode 100644 index 0000000000..7ecf81d5f7 --- /dev/null +++ b/front/src/routes/integration/all/alexa-gateway/index.js @@ -0,0 +1,135 @@ +import { Component } from 'preact'; +import { connect } from 'unistore/preact'; +import cx from 'classnames'; +import { Text, Localizer, MarkupText } from 'preact-i18n'; +import Layout from './Layout'; +import style from './style.css'; + +class AlexaGateway extends Component { + cancel = async e => { + e.preventDefault(); + await this.setState({ loading: true }); + if (this.props.redirect_uri && this.props.state) { + const redirectUrl = `${this.props.redirect_uri}?state=${this.props.state}&error=cancelled`; + window.location.replace(redirectUrl); + } else { + this.setState({ loading: false, error: true }); + } + }; + link = async e => { + e.preventDefault(); + try { + await this.setState({ loading: true, error: false }); + const responseAuthorize = await this.props.session.gatewayClient.alexaAuthorize({ + client_id: this.props.client_id, + redirect_uri: this.props.redirect_uri, + state: this.props.state + }); + window.location.replace(responseAuthorize.redirectUrl); + } catch (e) { + await this.setState({ loading: false, error: true }); + console.error(e); + if (this.props.redirect_uri && this.props.state) { + const redirectUrl = `${this.props.redirect_uri}?state=${this.props.state}&error=errored`; + window.location.replace(redirectUrl); + } + } + }; + + render(props, { loading, error }) { + return ( + +
+
+
+
+

+ + {<Text} + /> + + +

+
+
+
+
+

+ +

+
+ +
+
+
+ {error && ( +

+ +

+ )} +

+ +

+ +

+ {props.user && props.user.email} +

+ +
+

+ +

+
    +
  • +