// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. var utils = require('../utils/utils.jsx'); var client = require('../utils/client.jsx'); var UserStore = require('../stores/user_store.jsx'); var BrowserStore = require('../stores/browser_store.jsx'); var Constants = require('../utils/constants.jsx'); export default class Login extends React.Component { constructor(props) { super(props); this.handleSubmit = this.handleSubmit.bind(this); this.state = {}; } handleSubmit(e) { e.preventDefault(); var state = {}; var name = this.props.teamName; if (!name) { state.serverError = 'Bad team name'; this.setState(state); return; } var email = this.refs.email.getDOMNode().value.trim(); if (!email) { state.serverError = 'An email is required'; this.setState(state); return; } var password = this.refs.password.getDOMNode().value.trim(); if (!password) { state.serverError = 'A password is required'; this.setState(state); return; } if (!BrowserStore.isLocalStorageSupported()) { state.serverError = 'This service requires local storage to be enabled. Please enable it or exit private browsing.'; this.setState(state); return; } state.serverError = ''; this.setState(state); client.loginByEmail(name, email, password, function loggedIn(data) { UserStore.setCurrentUser(data); UserStore.setLastEmail(email); var redirect = utils.getUrlParameter('redirect'); if (redirect) { window.location.href = decodeURIComponent(redirect); } else { window.location.href = '/' + name + '/channels/town-square'; } }, function loginFailed(err) { if (err.message === 'Login failed because email address has not been verified') { window.location.href = '/verify_email?teamname=' + encodeURIComponent(name) + '&email=' + encodeURIComponent(email); return; } state.serverError = err.message; this.valid = false; this.setState(state); }.bind(this) ); } render() { var serverError; if (this.state.serverError) { serverError = ; } var priorEmail = UserStore.getLastEmail(); var emailParam = utils.getUrlParameter('email'); if (emailParam) { priorEmail = decodeURIComponent(emailParam); } var teamDisplayName = this.props.teamDisplayName; var teamName = this.props.teamName; var focusEmail = false; var focusPassword = false; if (priorEmail !== '') { focusPassword = true; } else { focusEmail = true; } var authServices = JSON.parse(this.props.authServices); var loginMessage = []; if (authServices.indexOf(Constants.GITLAB_SERVICE) >= 0) { loginMessage.push(
{'Log in with GitLab'}
); } if (authServices.indexOf(Constants.GOOGLE_SERVICE) >= 0) { loginMessage.push(
{'Log in with Google'}
); } var errorClass = ''; if (serverError) { errorClass = ' has-error'; } return (
Sign in to:

{teamDisplayName}

on {config.SiteName}

{serverError}
{loginMessage}
{'Find other ' + strings.TeamPlural}
I forgot my password
{'Want to create your own ' + strings.Team + '? '} Sign up now
); } } Login.defaultProps = { teamName: '', teamDisplayName: '', authServices: '' }; Login.propTypes = { teamName: React.PropTypes.string, teamDisplayName: React.PropTypes.string, authServices: React.PropTypes.string };