From 99bab6cae9ff0f0f6d642525fdfe7d7003f3defb Mon Sep 17 00:00:00 2001 From: or-else Date: Thu, 15 Mar 2018 18:52:31 -0700 Subject: [PATCH] added validation screen --- index.html | 96 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 17 deletions(-) diff --git a/index.html b/index.html index c07ce2be..f3439152 100644 --- a/index.html +++ b/index.html @@ -1211,22 +1211,17 @@ render: function() { return (
-
+
+ +
{this.props.title}
{this.props.state === 'login' ? : - this.props.state === 'settings' ? - : - this.props.state === 'edit-account' ? - : - this.props.state === 'register' ? - : this.props.state === 'contacts' ? : - this.props.state === 'new-topic' ? - : null} + {this.props.onCancel ? + : null}
); } @@ -1263,18 +1258,22 @@ render: function() { var title = null; var avatar = false; + var onCancel = undefined; switch (this.props.state) { case 'login': title = "Sign In"; break; case 'register': title = "Create Account"; + onCancel = this.props.onCancel; break; case 'settings': title = "Settings"; + onCancel = this.props.onCancel; break; case 'edit-account': title = "Edit Account"; + onCancel = this.props.onCancel; break; case 'contacts': title = this.props.title; @@ -1282,9 +1281,11 @@ break; case 'new-topic': title = "Start New Chat"; + onCancel = this.props.onCancel; break; case 'validation': title = "Confirm Credentials"; + onCancel = this.props.onCancel; break; default:; }; @@ -1296,7 +1297,7 @@ onSignUp={this.props.onSignUp} onSettings={this.props.onSettings} onNewTopic={this.props.onNewTopic} - onCancel={this.props.onCancel} /> + onCancel={onCancel} /> : this.props.state === 'validation' ? -
[confirm]
: + : null} @@ -2227,6 +2232,51 @@ }); /* END Create new topic and invite users or send an invite */ + /* BEGIN ValidationView: panel for confirming credentials, like email or phone */ + var ValidationView = React.createClass({ + getInitialState: function() { + return { + code: '', + }; + }, + handleChange: function(e) { + this.setState({code: e.target.value}); + }, + handleKeyPress: function(e) { + if (e.key === 'Enter') { + this.handleSubmit(e); + } + }, + handleSubmit: function(e) { + e.preventDefault(); + if (this.state.code && this.state.code.trim()) { + this.props.onSubmit(this.props.validation[0], this.state.code.trim()); + } + }, + render: function() { + var methods = {'email': 'email', 'tel': 'phone'}; + var method = methods[this.props.validation[0]] || this.props.validation[0]; + return ( +
+
+ +
+
+ +
+
+ +
+
+ ); + } + }); + /* END ValidationView */ + /* BEGIN InfoView: panel with topic/user info */ var InfoView = React.createClass({ getInitialState: function() { @@ -3540,24 +3590,30 @@ this.doLogin(this.state.login, this.state.password); }, - doLogin: function(login, password) { - var instance = this; + doLogin: function(login, password, cred) { + console.log("doLogin", login, password, cred); + var instance = this; + cred = cred ? Tinode.addCredential(null, cred.type, null, null, cred.resp).cred : undefined; + + console.log("doLogin cred=", cred); // Try to login with token. If token is not available, try password. If no password, ask for it. var promise = null; var token = Tinode.getLoginToken(); + + console.log("doLogin token=", token); + if (token) { - promise = Tinode.loginToken(token.token); + promise = Tinode.loginToken(token.token, cred); } else if (password) { this.setState({password: null}); - promise = Tinode.loginBasic(login, password); + promise = Tinode.loginBasic(login, password, cred); } else { this.setState({loginDisabled: false}); } if (promise) { promise.then(function(ctrl) { - console.log(ctrl); if (ctrl.code >= 300 && ctrl.text === "validate credentials") { instance.handleCredentialsRequest(ctrl.params); } else { @@ -3953,6 +4009,10 @@ } }, + handleValidateCredentialsRequest: function(cred, code) { + this.doLogin(null, null, {type: cred, resp: code}); + }, + render: function() { return (
@@ -3979,6 +4039,7 @@ errorText={this.state.errorText} errorLevel={this.state.errorLevel} topicSelected={this.state.topicSelected} + validation={this.state.validation} serverAddress={this.state.serverAddress} onConnectionSettings={this.handleConnectionSettings} @@ -3995,6 +4056,7 @@ onCancel={this.handleSidepanelCancel} onOnlineChange={this.handleTopicSelectedOnline} onError={this.handleError} + onValidateCredentials={this.handleValidateCredentialsRequest} onInitFind={this.tnInitFind} contactsSearchQuery={this.state.contactsSearchQuery}