aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/basicAuth
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2018-12-21 11:35:00 +0100
committerLibravatar Stefan Malzner <stefan@adlk.io>2018-12-21 11:35:00 +0100
commit2fc67d1c9bc2038179771238a0cb5d58995e05c3 (patch)
tree93aaaee39bf0ace0b53566ca4b5c2189ace2525c /src/features/basicAuth
parentbump version to b22 (diff)
downloadferdium-app-2fc67d1c9bc2038179771238a0cb5d58995e05c3.tar.gz
ferdium-app-2fc67d1c9bc2038179771238a0cb5d58995e05c3.tar.zst
ferdium-app-2fc67d1c9bc2038179771238a0cb5d58995e05c3.zip
BasicAuth first draft
Diffstat (limited to 'src/features/basicAuth')
-rw-r--r--src/features/basicAuth/Component.js102
-rw-r--r--src/features/basicAuth/Form.js17
-rw-r--r--src/features/basicAuth/index.js68
-rw-r--r--src/features/basicAuth/mainIpcHandler.js9
-rw-r--r--src/features/basicAuth/styles.js12
5 files changed, 208 insertions, 0 deletions
diff --git a/src/features/basicAuth/Component.js b/src/features/basicAuth/Component.js
new file mode 100644
index 000000000..13395fb40
--- /dev/null
+++ b/src/features/basicAuth/Component.js
@@ -0,0 +1,102 @@
1import React, { Component } from 'react';
2import PropTypes from 'prop-types';
3import injectSheet from 'react-jss';
4import { observer } from 'mobx-react';
5import classnames from 'classnames';
6
7import Modal from '../../components/ui/Modal';
8import Input from '../../components/ui/Input';
9import Button from '../../components/ui/Button';
10
11import {
12 state,
13 resetState,
14 sendCredentials,
15 cancelLogin,
16} from '.';
17import Form from './Form';
18
19import styles from './styles';
20
21export default @injectSheet(styles) @observer class BasicAuthModal extends Component {
22 static propTypes = {
23 classes: PropTypes.object.isRequired,
24 }
25
26 submit(e) {
27 e.preventDefault();
28
29 const values = Form.values();
30 console.log('form submit', values);
31
32 sendCredentials(values.user, values.password);
33 resetState();
34 }
35
36 cancel() {
37 cancelLogin();
38 this.close();
39 }
40
41 close() {
42 resetState();
43 state.isModalVisible = false;
44 }
45
46 render() {
47 const {
48 classes,
49 } = this.props;
50
51 const {
52 isModalVisible,
53 authInfo,
54 } = state;
55
56 if (!authInfo) {
57 return null;
58 }
59
60 return (
61 <Modal
62 isOpen={isModalVisible}
63 className={classes.modal}
64 close={this.cancel.bind(this)}
65 >
66 <h1>Sign in</h1>
67 <p>
68 http
69 {authInfo.port === 443 && 's'}
70 ://
71 {authInfo.host}
72 </p>
73 <form
74 onSubmit={this.submit.bind(this)}
75 className={classnames('franz-form', classes.form)}
76 >
77 <Input
78 field={Form.$('user')}
79 showLabel={false}
80 />
81 <Input
82 field={Form.$('password')}
83 showLabel={false}
84 showPasswordToggle
85 />
86 <div className={classes.buttons}>
87 <Button
88 type="button"
89 label="Cancel"
90 buttonType="secondary"
91 onClick={this.cancel.bind(this)}
92 />
93 <Button
94 type="submit"
95 label="Sign In"
96 />
97 </div>
98 </form>
99 </Modal>
100 );
101 }
102}
diff --git a/src/features/basicAuth/Form.js b/src/features/basicAuth/Form.js
new file mode 100644
index 000000000..95721d0e9
--- /dev/null
+++ b/src/features/basicAuth/Form.js
@@ -0,0 +1,17 @@
1import Form from '../../lib/Form';
2
3export default new Form({
4 fields: {
5 user: {
6 label: 'user',
7 placeholder: 'Username',
8 value: '',
9 },
10 password: {
11 label: 'Password',
12 placeholder: 'Password',
13 value: '',
14 type: 'password',
15 },
16 },
17});
diff --git a/src/features/basicAuth/index.js b/src/features/basicAuth/index.js
new file mode 100644
index 000000000..99abf0d11
--- /dev/null
+++ b/src/features/basicAuth/index.js
@@ -0,0 +1,68 @@
1import { ipcRenderer } from 'electron';
2import { observable } from 'mobx';
3
4import BasicAuthComponent from './Component';
5
6const debug = require('debug')('Franz:feature:basicAuth');
7
8const defaultState = {
9 isModalVisible: false,
10 service: null,
11 authInfo: null,
12};
13
14export const state = observable(defaultState);
15
16export function resetState() {
17 Object.assign(state, defaultState);
18 console.log('reset state', state);
19}
20
21export default function initialize(stores) {
22 debug('Initialize basicAuth feature');
23
24 window.franz.features.basicAuth = {
25 state,
26 };
27
28 ipcRenderer.on('feature:basic-auth-request', (e, data) => {
29 debug(e, data);
30 // state.serviceId = data.serviceId;
31 state.authInfo = data.authInfo;
32 state.isModalVisible = true;
33 });
34
35 // autorun(() => {
36 // // if (state.serviceId) {
37 // // const service = stores.services.one(state.serviceId);
38 // // if (service) {
39 // // state.service = service;
40 // // }
41 // // }
42 // });
43}
44
45export function mainIpcHandler(mainWindow, authInfo) {
46 debug('Sending basic auth call', authInfo);
47
48 mainWindow.webContents.send('feature:basic-auth-request', {
49 authInfo,
50 });
51}
52
53export function sendCredentials(user, password) {
54 debug('Sending credentials to main', user, password);
55
56 ipcRenderer.send('feature-basic-auth-credentials', {
57 user,
58 password,
59 });
60}
61
62export function cancelLogin() {
63 debug('Cancel basic auth event');
64
65 ipcRenderer.send('feature-basic-auth-cancel');
66}
67
68export const Component = BasicAuthComponent;
diff --git a/src/features/basicAuth/mainIpcHandler.js b/src/features/basicAuth/mainIpcHandler.js
new file mode 100644
index 000000000..87ac0b6df
--- /dev/null
+++ b/src/features/basicAuth/mainIpcHandler.js
@@ -0,0 +1,9 @@
1const debug = require('debug')('Franz:feature:basicAuth:main');
2
3export default function mainIpcHandler(mainWindow, authInfo) {
4 debug('Sending basic auth call', authInfo);
5
6 mainWindow.webContents.send('feature:basic-auth', {
7 authInfo,
8 });
9}
diff --git a/src/features/basicAuth/styles.js b/src/features/basicAuth/styles.js
new file mode 100644
index 000000000..6bdaf9a6e
--- /dev/null
+++ b/src/features/basicAuth/styles.js
@@ -0,0 +1,12 @@
1export default {
2 modal: {
3 width: 300,
4 },
5 buttons: {
6 display: 'flex',
7 justifyContent: 'space-between',
8 },
9 form: {
10 marginTop: 15,
11 },
12};