// 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'); module.exports = React.createClass({ handleSubmit: function(e) { e.preventDefault(); this.state.user.username = this.refs.name.getDOMNode().value.trim(); if (!this.state.user.username) { this.setState({name_error: "This field is required", email_error: "", password_error: ""}); return; } var username_error = utils.isValidUsername(this.state.user.username) if (username_error === "Cannot use a reserved word as a username.") { this.setState({name_error: "This username is reserved, please choose a new one." }); return; } else if (username_error) { this.setState({name_error: "Username must begin with a letter, and contain between 3 to 15 lowercase characters made up of numbers, letters, and the symbols '.', '-' and '_'." }); return; } this.state.user.email = this.refs.email.getDOMNode().value.trim(); if (!this.state.user.email) { this.setState({name_error: "", email_error: "This field is required", password_error: ""}); return; } this.state.user.password = this.refs.password.getDOMNode().value.trim(); if (!this.state.user.password || this.state.user.password .length < 5) { this.setState({name_error: "", email_error: "", password_error: "Please enter at least 5 characters"}); return; } this.state.user.allow_marketing = this.refs.email_service.getDOMNode().checked; client.createUser(this.state.user, this.state.data, this.state.hash, function(data) { client.track('signup', 'signup_user_02_complete'); if (data.email_verified) { client.loginByEmail(this.props.domain, this.state.user.email, this.state.user.password, function(data) { UserStore.setLastDomain(this.props.domain); UserStore.setLastEmail(this.state.user.email); UserStore.setCurrentUser(data); if (this.props.hash > 0) localStorage.setItem(this.props.hash, JSON.stringify({wizard: "finished"})); window.location.href = '/channels/town-square'; }.bind(this), function(err) { this.state.server_error = err.message; this.setState(this.state); }.bind(this) ); } else { window.location.href = "/verify?email="+ encodeURIComponent(this.state.user.email) + "&domain=" + encodeURIComponent(this.props.domain); } }.bind(this), function(err) { this.state.server_error = err.message; this.setState(this.state); }.bind(this) ); }, getInitialState: function() { var props = null; try { props = JSON.parse(localStorage.getItem(this.props.hash)); } catch(parse_error) { } if (!props) { props = {}; props.wizard = "welcome"; props.user = {}; props.user.team_id = this.props.team_id; props.user.email = this.props.email; props.hash = this.props.hash; props.data = this.props.data; props.original_email = this.props.email; } return props ; }, render: function() { client.track('signup', 'signup_user_01_welcome'); if (this.state.wizard == "finished") { return (
{"Choose your username and password for the " + this.props.team_name + " " + strings.Team +"."}
Your username can be made of lowercase letters and numbers.
{"Pick something " + strings.Team + "mates will recognize. Your username is how you will appear to others"}
{ yourEmailIs } You’ll use this address to sign in to {config.SiteName}.
{ server_error }By proceeding to create your account and use { config.SiteName }, you agree to our Terms of Service and Privacy Policy. If you do not agree, you cannot use {config.SiteName}.