diff --git a/src/components/login/Registration.js b/src/components/login/Registration.js new file mode 100644 index 0000000000..a1ebe57cee --- /dev/null +++ b/src/components/login/Registration.js @@ -0,0 +1,147 @@ +/* +Copyright 2015 OpenMarket Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +'use strict'; + +var React = require('react'); + +var sdk = require('matrix-react-sdk'); +var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg'); +var ServerConfig = require("./ServerConfig"); +var RegistrationForm = require("./RegistrationForm"); + +module.exports = React.createClass({ + displayName: 'Registration', + + propTypes: { + onLoggedIn: React.PropTypes.func.isRequired, + registerLogic: React.PropTypes.any.isRequired, + // registration shouldn't know or care how login is done. + onLoginClick: React.PropTypes.func.isRequired + }, + + getInitialState: function() { + return { + busy: false, + errorText: null, + enteredHomeserverUrl: this.props.registerLogic.getHomeserverUrl(), + enteredIdentityServerUrl: this.props.registerLogic.getIdentityServerUrl() + }; + }, + + componentWillMount: function() { + + }, + + onHsUrlChanged: function(newHsUrl) { + this.props.registerLogic.setHomeserverUrl(newHsUrl); + this.forceUpdate(); // registration state may have changed. + }, + + onIsUrlChanged: function(newIsUrl) { + this.props.registerLogic.setIdentityServerUrl(newIsUrl); + this.forceUpdate(); // registration state may have changed. + }, + + onFormSubmit: function(formVals) { + console.log("Form vals: %s", formVals); + }, + + onFormValidationFailed: function(errCode) { + console.error("Ruh roh: %s", errCode); + }, + + _getRegisterContentJsx: function() { + var currState = this.props.registerLogic.getState(); + var registerStep; + switch (currState) { + case "Register.COMPLETE": + return this._getPostRegisterJsx(); + case "Register.START": + registerStep = ( + + ); + break; + case "Register.STEP_m.login.email.identity": + registerStep = ( +
+ Please check your email to continue registration. +
+ ); + break; + case "Register.STEP_m.login.recaptcha": + registerStep = ( +
+ This Home Server would like to make sure you are not a robot +
+
+ ); + break; + default: + console.error("Unknown register state: %s", currState); + break; + } + return ( +
+

Create an account

+ {registerStep} + +
{this.state.errorText}
+ + I already have an account + +
+ ); + }, + + _getPostRegisterJsx: function() { + var ChangeDisplayName = sdk.getComponent('molecules.ChangeDisplayName'); + var ChangeAvatar = sdk.getComponent('molecules.ChangeAvatar'); + return ( +
+ Set a display name: + + Upload an avatar: + + +
+ ); + }, + + render: function() { + return ( +
+
+
+ vector +
+ {this._getRegisterContentJsx()} +
+
+ ); + } +}); diff --git a/src/components/login/RegistrationForm.js b/src/components/login/RegistrationForm.js new file mode 100644 index 0000000000..3f9fb6ae12 --- /dev/null +++ b/src/components/login/RegistrationForm.js @@ -0,0 +1,126 @@ +/* +Copyright 2015 OpenMarket Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +'use strict'; + +var React = require('react'); +var sdk = require('matrix-react-sdk') + +/** + * A pure UI component which displays a registration form. + */ +module.exports = React.createClass({ + displayName: 'RegistrationForm', + + propTypes: { + defaultEmail: React.PropTypes.string, + defaultUsername: React.PropTypes.string, + showEmail: React.PropTypes.bool, + minPasswordLength: React.PropTypes.number, + onError: React.PropTypes.func, + onRegisterClick: React.PropTypes.func // onRegisterClick(Object) => ?Promise + }, + + getDefaultProps: function() { + return { + showEmail: false, + minPasswordLength: 6, + onError: function(e) { + console.error(e); + } + }; + }, + + getInitialState: function() { + return { + email: this.props.defaultEmail, + username: this.props.defaultUsername, + password: null, + passwordConfirm: null + }; + }, + + onSubmit: function(ev) { + ev.preventDefault(); + + var pwd1 = this.refs.password.value.trim(); + var pwd2 = this.refs.passwordConfirm.value.trim() + + var errCode; + if (!pwd1 || !pwd2) { + errCode = "RegistrationForm.ERR_PASSWORD_MISSING"; + } + else if (pwd1 !== pwd2) { + errCode = "RegistrationForm.ERR_PASSWORD_MISMATCH"; + } + else if (pwd1.length < this.props.minPasswordLength) { + errCode = "RegistrationForm.ERR_PASSWORD_LENGTH"; + } + if (errCode) { + this.props.onError(errCode); + return; + } + + var promise = this.props.onRegisterClick({ + username: this.refs.username.value.trim(), + password: pwd1, + email: this.refs.email.value.trim() + }); + + if (promise) { + ev.target.disabled = true; + promise.finally(function() { + ev.target.disabled = false; + }); + } + }, + + render: function() { + var emailSection, registerButton; + if (this.props.showEmail) { + emailSection = ( + + ); + } + if (this.props.onRegisterClick) { + registerButton = ( + + ); + } + + return ( +
+
+ {emailSection} +
+ +
+ +
+ +
+ {registerButton} +
+
+ ); + } +}); diff --git a/src/skins/vector/views/pages/MatrixChat.js b/src/skins/vector/views/pages/MatrixChat.js index 5ed96c3769..9c8872e01f 100644 --- a/src/skins/vector/views/pages/MatrixChat.js +++ b/src/skins/vector/views/pages/MatrixChat.js @@ -23,7 +23,10 @@ var MatrixChatController = require('matrix-react-sdk/lib/controllers/pages/Matri var dis = require('matrix-react-sdk/lib/dispatcher'); var Matrix = require("matrix-js-sdk"); -var ContextualMenu = require("../../../../ContextualMenu"); +var ContextualMenu = require("../../../../ContextualMenu") +var Login = require("../../../../components/login/Login"); +var Registration = require("../../../../components/login/Registration"); +var Signup = require("matrix-react-sdk/lib/Signup"); module.exports = React.createClass({ displayName: 'MatrixChat', @@ -93,12 +96,15 @@ module.exports = React.createClass({ this.showScreen("register"); }, + onLoginClick: function() { + this.showScreen("login"); + }, + render: function() { var LeftPanel = sdk.getComponent('organisms.LeftPanel'); var RoomView = sdk.getComponent('organisms.RoomView'); var RightPanel = sdk.getComponent('organisms.RightPanel'); var UserSettings = sdk.getComponent('organisms.UserSettings'); - var Register = sdk.getComponent('templates.Register'); var CreateRoom = sdk.getComponent('organisms.CreateRoom'); var RoomDirectory = sdk.getComponent('organisms.RoomDirectory'); var MatrixToolbar = sdk.getComponent('molecules.MatrixToolbar'); @@ -159,15 +165,23 @@ module.exports = React.createClass({ ); } else if (this.state.screen == 'register') { + /* return ( + ); */ + return ( + ); } else { - var Login = require("../../../../components/login/Login"); return ( );