Skip to content

Commit

Permalink
Merge branch 'release/2.8.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirPal committed Oct 30, 2018
2 parents 048680c + 96b510b commit b718410
Show file tree
Hide file tree
Showing 36 changed files with 650 additions and 323 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<a name="2.8.2"></a>
## [2.8.2](https://github.com/web-pal/chronos-timetracker/compare/v2.8.1...v2.8.2) (2018-10-30)
Authentication bug fixes



<a name="2.8.1"></a>
## [2.8.1](https://github.com/web-pal/chronos-timetracker/compare/v2.8.0...v2.8.1) (2018-10-28)

Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Chronos",
"productName": "Chronos",
"version": "2.8.1",
"version": "2.8.2",
"description": "Native app for time-tracking fully integrated with JIRA",
"main": "./dist/main.prod.js",
"author": {
Expand Down
1 change: 1 addition & 0 deletions app/renderer/actions/actionTypes/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

export const AUTH_REQUEST = 'auth/AUTH_REQUEST';
export const AUTH_SELF_HOST_REQUEST = 'auth/AUTH_SELF_HOST_REQUEST';
export const LOGOUT_REQUEST = 'auth/LOGOUT_REQUEST';
export const SWITCH_ACCOUNT = 'auth/SWITCH_ACCOUNT';
export const ADD_AUTH_DEBUG_MESSAGE = 'auth/ADD_AUTH_DEBUG_MESSAGE';
8 changes: 8 additions & 0 deletions app/renderer/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export const authRequest = (payload: {|
payload,
});

export const authSelfHostRequest = (payload: {|
username: string,
password: string,
|}): AuthAction => ({
type: actionTypes.AUTH_SELF_HOST_REQUEST,
payload,
});

export const logoutRequest = (payload: {
dontForget: boolean
} = { dontForget: false }): AuthAction => ({
Expand Down
56 changes: 56 additions & 0 deletions app/renderer/api/profile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
import {
remote,
} from 'electron';
import config from 'config';
import jira from 'utils/jiraClient';
import {
Expand Down Expand Up @@ -190,3 +193,56 @@ export function getPermissions(
): Promise<*> {
return jira.client.myPermissions.getMyPermissions(opts);
}

export function getAuthCookies(
payload: {
username: string,
password: string,
baseUrl: string,
},
): Promise<*> {
const { username, password, baseUrl } = payload;
const url: string = `${baseUrl}/rest/auth/1/session`;
const request = remote.net.request({
url,
method: 'POST',
});
return new Promise((resolve, reject) => {
request.on('response', (response) => {
const status = response.statusCode;
response.on('data', (chunk) => {
try {
const json = JSON.parse(chunk);
if (status === 200) {
resolve(json);
} else {
reject(json);
}
} catch (e) {
reject(e);
}
});
response.on('error', (error) => {
reject(error);
});
});
request.on('error', (error) => {
reject(error);
});
request.setHeader(
'User-agent',
'request',
);
request.setHeader(
'Content-Type',
'application/json',
);
request.write(
JSON.stringify({
username,
password,
}),
);
request.end();
});
}
43 changes: 10 additions & 33 deletions app/renderer/authPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ function hideNode(el, scope) {
}
}

function back() {
function back(error = null) {
store.dispatch(
uiActions.setUiState('authFormStep', 1, 'allRenderer'),
);
store.dispatch(
uiActions.setUiState('authFormIsComplete', false, 'allRenderer'),
);
store.dispatch(uiActions.setUiState('authError', null));
store.dispatch(uiActions.setUiState('authError', error, 'allRenderer'));
}

function initAtlassian(base, reset) {
Expand Down Expand Up @@ -59,35 +59,16 @@ function initGoogle(base) {
ev.preventDefault();
back();
});
}

function initSelfHost(base) {
hideNode('#header', base);
hideNode('#footer', base);
hideNode('#login-form .checkbox', base);
document.body.style.minWidth = 'auto';
document.body.style.width = 'auto';
const panel = base.querySelector('.aui-page-panel');
if (panel) {
panel.style.marginTop = '35px';
panel.style.maxWidth = '345px';

const a = document.createElement('a');
a.innerHTML = 'Back to Jira';
panel.appendChild(a);
a.addEventListener('click', (ev) => {
ev.preventDefault();
back();
});
}

store.dispatch(
uiActions.setUiState('authFormIsComplete', true, 'allRenderer'),
);
}

function init() {
if (global.location.host === 'id.atlassian.com') {
store.dispatch(
uiActions.setUiState('authFormIsComplete', false, 'allRenderer'),
);
if (global.location.host === 'id.atlassian.com' && global.location.pathname === '/login') {
const base = document.getElementById('root');
const reset = document.getElementById('resetPassword');
if (base && reset) {
Expand All @@ -102,14 +83,10 @@ function init() {
} else {
setTimeout(init, 500);
}
} else if (global.location.pathname.endsWith('/login.jsp')
|| global.location.pathname.endsWith('/secure/ForgotLoginDetails.jspa')) {
const base = document.getElementById('page');
if (base) {
initSelfHost(base);
} else {
setTimeout(init, 500);
}
} else if (global.location.pathname === '/login') {
back('Something has gone wrong');
} else {
setTimeout(init, 500);
}
}

Expand Down
30 changes: 19 additions & 11 deletions app/renderer/components/ReduxFormComponents/Input.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// @flow
import React, { Component } from 'react';
import React, {
Component,
} from 'react';


import type {
FieldProps,
} from 'redux-form';

import {
FormGroup,
StyledInput,
Error,
} from './styled';

type Props = {
Expand All @@ -15,27 +20,30 @@ type Props = {
placeholder: string,
} & FieldProps;


class Input extends Component<Props> {
input = null;

render() {
const {
meta,
input,
autoFocus,
type,
placeholder,
} = this.props;
return (
<StyledInput
{...input}
innerRef={(el) => {
this.input = el;
}}
type={type}
autoFocus={autoFocus}
placeholder={placeholder}
/>
<FormGroup>
<StyledInput
{...input}
innerRef={(el) => {
this.input = el;
}}
type={type}
autoFocus={autoFocus}
placeholder={placeholder}
/>
{meta.touched && meta.error && <Error>{meta.error}</Error>}
</FormGroup>
);
}
}
Expand Down
29 changes: 18 additions & 11 deletions app/renderer/components/ReduxFormComponents/UnderlineInput.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// @flow
import React, { Component } from 'react';
import React, {
Component,
} from 'react';

import type {
FieldProps,
} from 'redux-form';

import {
FormGroup,
UnderlineStyledInput,
Error,
} from './styled';

type Props = {
Expand All @@ -15,27 +19,30 @@ type Props = {
placeholder: string,
} & FieldProps;


class UnderlineInput extends Component<Props> {
input = null;

render() {
const {
meta,
input,
autoFocus,
type,
placeholder,
} = this.props;
return (
<UnderlineStyledInput
{...input}
innerRef={(el) => {
this.input = el;
}}
type={type}
autoFocus={autoFocus}
placeholder={placeholder}
/>
<FormGroup>
<UnderlineStyledInput
{...input}
innerRef={(el) => {
this.input = el;
}}
type={type}
autoFocus={autoFocus}
placeholder={placeholder}
/>
{meta.touched && meta.error && <Error>{meta.error}</Error>}
</FormGroup>
);
}
}
Expand Down
46 changes: 25 additions & 21 deletions app/renderer/components/ReduxFormComponents/styled/index.jsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
import styled from 'styled-components';


export const UnderlineStyledInput = styled.input`
const baseInput = styled.input`
width: calc(100% - 10px);
height: 40px;
min-height: 40px;
color: #091E42;
font-size: 14px;
letter-spacing: 0;
color: #091E42;
&::-webkit-input-placeholder {
font-size: 14px;
}
`;


export const UnderlineStyledInput = styled(baseInput)`
background: white;
border: 0px;
border-bottom: 2px solid #0052cc;
border-radius: 0px;
padding: 0px;
font-size: 14px;
font-weight: 500;
margin-bottom: 40px;
&::-webkit-input-placeholder {
font-size: 14px;
}
&:focus {
border-color: hsla(216, 49%, 43%, 1);
}
`;

export const StyledInput = styled.input`
width: calc(100% - 10px);
height: 40px;
min-height: 40px;
export const StyledInput = styled(baseInput)`
padding-left: 10px;
margin-bottom: 10px;
font-size: 14px;
letter-spacing: 0;
background-color: #FAFBFC;
border: 1px solid #F4F5F7;
border-radius: 5px;
color: #091E42;
&::-webkit-input-placeholder {
font-size: 14px;
}
&:hover {
background-color: #F4F5F7;
border-color: #F4F5F7;
Expand All @@ -55,3 +47,15 @@ export const StyledInput = styled.input`
background: white;
}
`;

export const FormGroup = styled.div`
width: 100%;
margin-bottom: 10px;
`;

export const Error = styled.div`
color: #DE350B;
align-self: left;
font-size: 12px;
margin-top: 5px;
`;
Loading

0 comments on commit b718410

Please sign in to comment.