From b0a40c66fbefef7b5c54bc30eb546daca081bce5 Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Sat, 23 Apr 2016 00:50:57 +0900 Subject: [PATCH] Add the dialog to login --- gulpfile.js | 2 +- src/browser/components/loginModal.jsx | 59 +++++++++++++++++++++++++++ src/browser/index.jsx | 56 ++++++++++++++++++++----- 3 files changed, 105 insertions(+), 12 deletions(-) create mode 100644 src/browser/components/loginModal.jsx diff --git a/gulpfile.js b/gulpfile.js index 61ed0d27..0d5d496c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -85,7 +85,7 @@ gulp.task('build', ['sync-meta', 'webpack', 'copy'], function() { gulp.task('webpack', ['webpack:main', 'webpack:browser', 'webpack:webview']); gulp.task('webpack:browser', function() { - return gulp.src('src/browser/**/*.jsx') + return gulp.src('src/browser/*.jsx') .pipe(named()) .pipe(webpack({ module: { diff --git a/src/browser/components/loginModal.jsx b/src/browser/components/loginModal.jsx new file mode 100644 index 00000000..14a3176e --- /dev/null +++ b/src/browser/components/loginModal.jsx @@ -0,0 +1,59 @@ +const React = require('react'); +const ReactDOM = require('react-dom'); +const ReactBootstrap = require('react-bootstrap'); +const Modal = ReactBootstrap.Modal; +const Form = ReactBootstrap.Form; +const FormGroup = ReactBootstrap.FormGroup; +const FormControl = ReactBootstrap.FormControl; +const ControlLabel = ReactBootstrap.ControlLabel; +const Col = ReactBootstrap.Col; + +const Button = ReactBootstrap.Button; + +const LoginModal = React.createClass({ + handleLogin: function() { + if (this.props.onLogin) { + const username = ReactDOM.findDOMNode(this.refs.username).value; + const password = ReactDOM.findDOMNode(this.refs.password).value; + this.props.onLogin(this.props.request, username, password); + } + }, + render: function() { + return ( + + + Authentication Required + + +

The server + { ' ' + this.props.authServerURL } requires a username and password.

+
+ + User Name + + + + + + Password + + + + + + +
+ + { ' ' } + +
+ +
+
+
+
+ ); + } +}); + +module.exports = LoginModal; diff --git a/src/browser/index.jsx b/src/browser/index.jsx index cd3661e4..17ea3072 100644 --- a/src/browser/index.jsx +++ b/src/browser/index.jsx @@ -13,6 +13,8 @@ const Badge = ReactBootstrap.Badge; const ListGroup = ReactBootstrap.ListGroup; const ListGroupItem = ReactBootstrap.ListGroupItem; +const LoginModal = require('./components/loginModal.jsx'); + const electron = require('electron'); const remote = electron.remote; const ipcRenderer = electron.ipcRenderer; @@ -26,12 +28,6 @@ const settings = require('../common/settings'); remote.getCurrentWindow().removeAllListeners('focus'); -ipcRenderer.on('login-request', function(event, request, authInfo) { - setTimeout(() => { - ipcRenderer.send('login-credentials', request, 'user', 'password'); - }, 10000); -}); - // New window should disable nodeIntergration. const originalWindowOpen = window.open; window.open = function(url, name, features) { @@ -49,11 +45,26 @@ var MainPage = React.createClass({ unreadCounts: new Array(this.props.teams.length), mentionCounts: new Array(this.props.teams.length), unreadAtActive: new Array(this.props.teams.length), - mentionAtActiveCounts: new Array(this.props.teams.length) + mentionAtActiveCounts: new Array(this.props.teams.length), + loginQueue: [] }; }, componentDidMount: function() { var thisObj = this; + ipcRenderer.on('login-request', function(event, request, authInfo) { + thisObj.setState({ + loginRequired: true + }); + const loginQueue = thisObj.state.loginQueue; + loginQueue.push({ + request: request, + authInfo: authInfo + }); + thisObj.setState({ + loginQueue: loginQueue + }); + }); + var focusListener = function() { var webview = document.getElementById('mattermostView' + thisObj.state.key); webview.focus(); @@ -141,6 +152,18 @@ var MainPage = React.createClass({ visibility: visibility }; }, + + handleLogin: function(request, username, password) { + ipcRenderer.send('login-credentials', request, username, password); + const loginQueue = this.state.loginQueue; + loginQueue.shift(); + this.setState(loginQueue); + }, + handleLoginCancel: function() { + const loginQueue = this.state.loginQueue; + loginQueue.shift(); + this.setState(loginQueue); + }, render: function() { var thisObj = this; @@ -168,11 +191,22 @@ var MainPage = React.createClass({ var views_row = ( { views } ); + + var request = null; + var authServerURL = null; + if (this.state.loginQueue.length !== 0) { + request = this.state.loginQueue[0].request; + const tmp_url = url.parse(this.state.loginQueue[0].request.url); + authServerURL = `${tmp_url.protocol}//${tmp_url.host}`; + } return ( - - { tabs_row } - { views_row } - +
+ + + { tabs_row } + { views_row } + +
); } });