* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { getJSON } from '../helpers/request';
+import { getJSON, parseJSON, request } from '../helpers/request';
import throwGlobalError from '../app/utils/throwGlobalError';
export function getGlobalNavigation(): Promise<any> {
export function getSettingsNavigation(): Promise<any> {
return getJSON('/api/navigation/settings').catch(throwGlobalError);
}
+
+export function tryGetGlobalNavigation(): Promise<any> {
+ return request('/api/navigation/global')
+ .submit()
+ .then(response => {
+ if (response.status >= 200 && response.status < 300) {
+ return parseJSON(response);
+ } else if (response.status === 401) {
+ return {};
+ } else {
+ return Promise.reject(response);
+ }
+ })
+ .catch(response => throwGlobalError({ response }).catch(() => Promise.resolve({})));
+}
import { IdentityProvider } from '../../../api/users';
interface Props {
+ onSonarCloud: boolean;
identityProviders: IdentityProvider[];
onSubmit: (login: string, password: string) => void;
}
this.setState({ password: event.currentTarget.value });
render() {
+ const loginTitle = this.props.onSonarCloud
+ ? translate('login.login_to_sonarcloud')
+ : translate('login.login_to_sonarqube');
+
return (
<div id="login_form">
- <h1 className="maintenance-title text-center">{translate('login.login_to_sonarqube')}</h1>
+ <h1 className="login-title text-center">{loginTitle}</h1>
{this.props.identityProviders.length > 0 && (
<OAuthProviders identityProviders={this.props.identityProviders} />
import { connect } from 'react-redux';
import LoginForm from './LoginForm';
import { doLogin } from '../../../store/rootActions';
-import { getAppState } from '../../../store/rootReducer';
+import { tryGetGlobalNavigation } from '../../../api/nav';
import { IdentityProvider, getIdentityProviders } from '../../../api/users';
import { getBaseUrl } from '../../../helpers/urls';
interface State {
identityProviders?: IdentityProvider[];
+ onSonarCloud: boolean;
}
class LoginFormContainer extends React.PureComponent<Props, State> {
mounted: boolean;
- state: State = {};
+ state: State = { onSonarCloud: false };
componentDidMount() {
this.mounted = true;
- getIdentityProviders().then(r => {
+ Promise.all([
+ getIdentityProviders(),
+ tryGetGlobalNavigation()
+ ]).then(([identityProvidersResponse, appState]) => {
if (this.mounted) {
- this.setState({ identityProviders: r.identityProviders });
+ this.setState({
+ onSonarCloud:
+ appState.settings && appState.settings['sonar.sonarcloud.enabled'] === 'true',
+ identityProviders: identityProvidersResponse.identityProviders
+ });
}
});
}
};
render() {
- if (!this.state.identityProviders) {
+ const { identityProviders, onSonarCloud } = this.state;
+ if (!identityProviders) {
return null;
}
return (
- <LoginForm identityProviders={this.state.identityProviders} onSubmit={this.handleSubmit} />
+ <LoginForm
+ identityProviders={identityProviders}
+ onSonarCloud={onSonarCloud}
+ onSubmit={this.handleSubmit}
+ />
);
}
}
-const mapStateToProps = (state: any) => ({
- appState: getAppState(state)
-});
-
+const mapStateToProps = null;
const mapDispatchToProps = { doLogin };
export default connect(mapStateToProps, mapDispatchToProps)(LoginFormContainer as any);
it('logs in with simple credentials', () => {
const onSubmit = jest.fn();
- const wrapper = shallow(<LoginForm identityProviders={[]} onSubmit={onSubmit} />);
+ const wrapper = shallow(
+ <LoginForm onSonarCloud={false} identityProviders={[]} onSubmit={onSubmit} />
+ );
expect(wrapper).toMatchSnapshot();
change(wrapper.find('#login'), 'admin');
it('logs in with identity provider', () => {
const wrapper = shallow(
- <LoginForm identityProviders={[identityProvider]} onSubmit={jest.fn()} />
+ <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} />
);
expect(wrapper).toMatchSnapshot();
});
it('expands more options', () => {
const wrapper = shallow(
- <LoginForm identityProviders={[identityProvider]} onSubmit={jest.fn()} />
+ <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} />
);
expect(wrapper).toMatchSnapshot();
id="login_form"
>
<h1
- className="maintenance-title text-center"
+ className="login-title text-center"
>
login.login_to_sonarqube
</h1>
id="login_form"
>
<h1
- className="maintenance-title text-center"
+ className="login-title text-center"
>
login.login_to_sonarqube
</h1>
id="login_form"
>
<h1
- className="maintenance-title text-center"
+ className="login-title text-center"
>
login.login_to_sonarqube
</h1>
id="login_form"
>
<h1
- className="maintenance-title text-center"
+ className="login-title text-center"
>
login.login_to_sonarqube
</h1>
@import (reference) "../variables";
@import (reference) "../mixins";
+.login-title {
+ margin-bottom: 40px;
+ line-height: 1.5;
+ font-size: 24px;
+ font-weight: 300;
+ text-align: center;
+}
+
.login-input {
width: 100% !important;
height: auto !important;
user.login_or_email_used_as_scm_account=Login and email are automatically considered as SCM accounts
login.login_to_sonarqube=Log In to SonarQube
+login.login_to_sonarcloud=Log In to SonarCloud
login.more_options=More options
login.login_with_x=Log in with {0}