// 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 TeamStore = require('../stores/team_store.jsx'); var BrowserStore = require('../stores/browser_store.jsx'); var Constants = require('../utils/constants.jsx'); module.exports = React.createClass({ handleSubmit: function(e) { e.preventDefault(); var state = { } var name = this.props.teamName if (!name) { state.server_error = "Bad team name" this.setState(state); return; } var email = this.refs.email.getDOMNode().value.trim(); if (!email) { state.server_error = "An email is required" this.setState(state); return; } var password = this.refs.password.getDOMNode().value.trim(); if (!password) { state.server_error = "A password is required" this.setState(state); return; } if (!BrowserStore.isLocalStorageSupported()) { state.server_error = "This service requires local storage to be enabled. Please enable it or exit private browsing."; this.setState(state); return; } state.server_error = ""; this.setState(state); client.loginByEmail(name, email, password, function(data) { UserStore.setCurrentUser(data); UserStore.setLastEmail(email); var redirect = utils.getUrlParameter("redirect"); if (redirect) { window.location.pathname = decodeURI(redirect); } else { window.location.pathname = '/' + name + '/channels/town-square'; } }.bind(this), function(err) { if (err.message == "Login failed because email address has not been verified") { window.location.href = '/verify_email?name=' + encodeURIComponent(name) + '&email=' + encodeURIComponent(email); return; } state.server_error = err.message; this.valid = false; this.setState(state); }.bind(this) ); }, getInitialState: function() { return { }; }, render: function() { var server_error = this.state.server_error ? : null; var priorEmail = UserStore.getLastEmail() !== "undefined" ? 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; } return (