2015-11-12 15:28:57 +00:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-03-14 11:50:13 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2015-11-12 15:28:57 +00:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-08-03 15:59:17 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
|
import classNames from 'classnames';
|
2017-03-14 11:50:13 +00:00
|
|
|
import sdk from '../../../index';
|
2016-08-03 15:59:17 +01:00
|
|
|
import {field_input_incorrect} from '../../../UiEffects';
|
|
|
|
|
|
2015-11-12 15:28:57 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A pure UI component which displays a username/password form.
|
|
|
|
|
*/
|
|
|
|
|
module.exports = React.createClass({displayName: 'PasswordLogin',
|
|
|
|
|
propTypes: {
|
2016-01-12 17:20:16 +00:00
|
|
|
onSubmit: React.PropTypes.func.isRequired, // fn(username, password)
|
2016-03-06 14:33:36 -05:00
|
|
|
onForgotPasswordClick: React.PropTypes.func, // fn()
|
|
|
|
|
initialUsername: React.PropTypes.string,
|
2017-03-14 11:50:13 +00:00
|
|
|
initialPhoneCountry: React.PropTypes.string,
|
|
|
|
|
initialPhoneNumber: React.PropTypes.string,
|
2016-03-06 14:33:36 -05:00
|
|
|
initialPassword: React.PropTypes.string,
|
|
|
|
|
onUsernameChanged: React.PropTypes.func,
|
2017-03-14 11:50:13 +00:00
|
|
|
onPhoneCountryChanged: React.PropTypes.func,
|
|
|
|
|
onPhoneNumberChanged: React.PropTypes.func,
|
2016-03-06 14:33:36 -05:00
|
|
|
onPasswordChanged: React.PropTypes.func,
|
2016-08-03 15:59:17 +01:00
|
|
|
loginIncorrect: React.PropTypes.bool,
|
2016-03-06 14:33:36 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
|
return {
|
|
|
|
|
onUsernameChanged: function() {},
|
|
|
|
|
onPasswordChanged: function() {},
|
2017-03-14 11:50:13 +00:00
|
|
|
onPhoneCountryChanged: function() {},
|
|
|
|
|
onPhoneNumberChanged: function() {},
|
2016-03-06 18:42:09 -05:00
|
|
|
initialUsername: "",
|
2017-03-14 11:50:13 +00:00
|
|
|
initialPhoneCountry: "",
|
|
|
|
|
initialPhoneNumber: "",
|
2016-03-06 18:42:09 -05:00
|
|
|
initialPassword: "",
|
2016-08-03 15:59:17 +01:00
|
|
|
loginIncorrect: false,
|
2016-03-06 14:33:36 -05:00
|
|
|
};
|
2015-11-12 15:28:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
|
return {
|
2016-03-06 14:33:36 -05:00
|
|
|
username: this.props.initialUsername,
|
|
|
|
|
password: this.props.initialPassword,
|
2017-03-14 11:50:13 +00:00
|
|
|
phoneCountry: this.props.initialPhoneCountry,
|
|
|
|
|
phoneNumber: this.props.initialPhoneNumber,
|
2015-11-12 15:28:57 +00:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
2016-08-03 15:59:17 +01:00
|
|
|
componentWillMount: function() {
|
|
|
|
|
this._passwordField = null;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps: function(nextProps) {
|
|
|
|
|
if (!this.props.loginIncorrect && nextProps.loginIncorrect) {
|
|
|
|
|
field_input_incorrect(this._passwordField);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2015-11-12 15:28:57 +00:00
|
|
|
onSubmitForm: function(ev) {
|
|
|
|
|
ev.preventDefault();
|
2017-03-14 11:50:13 +00:00
|
|
|
this.props.onSubmit(
|
|
|
|
|
this.state.username,
|
|
|
|
|
this.state.phoneCountry,
|
|
|
|
|
this.state.phoneNumber,
|
|
|
|
|
this.state.password,
|
|
|
|
|
);
|
2015-11-12 15:28:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onUsernameChanged: function(ev) {
|
|
|
|
|
this.setState({username: ev.target.value});
|
2016-03-06 14:33:36 -05:00
|
|
|
this.props.onUsernameChanged(ev.target.value);
|
2015-11-12 15:28:57 +00:00
|
|
|
},
|
|
|
|
|
|
2017-03-14 11:50:13 +00:00
|
|
|
onPhoneCountryChanged: function(country) {
|
|
|
|
|
this.setState({phoneCountry: country});
|
|
|
|
|
this.props.onPhoneCountryChanged(country);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onPhoneNumberChanged: function(ev) {
|
|
|
|
|
this.setState({phoneNumber: ev.target.value});
|
|
|
|
|
this.props.onPhoneNumberChanged(ev.target.value);
|
|
|
|
|
},
|
|
|
|
|
|
2015-11-12 15:28:57 +00:00
|
|
|
onPasswordChanged: function(ev) {
|
|
|
|
|
this.setState({password: ev.target.value});
|
2016-03-06 14:33:36 -05:00
|
|
|
this.props.onPasswordChanged(ev.target.value);
|
2015-11-12 15:28:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
render: function() {
|
2016-01-12 17:20:16 +00:00
|
|
|
var forgotPasswordJsx;
|
|
|
|
|
|
|
|
|
|
if (this.props.onForgotPasswordClick) {
|
|
|
|
|
forgotPasswordJsx = (
|
|
|
|
|
<a className="mx_Login_forgot" onClick={this.props.onForgotPasswordClick} href="#">
|
|
|
|
|
Forgot your password?
|
|
|
|
|
</a>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 15:59:17 +01:00
|
|
|
const pwFieldClass = classNames({
|
|
|
|
|
mx_Login_field: true,
|
|
|
|
|
error: this.props.loginIncorrect,
|
|
|
|
|
});
|
|
|
|
|
|
2017-03-14 11:50:13 +00:00
|
|
|
const CountryDropdown = sdk.getComponent('views.login.CountryDropdown');
|
2015-11-12 15:28:57 +00:00
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<form onSubmit={this.onSubmitForm}>
|
2017-03-14 11:50:13 +00:00
|
|
|
<input className="mx_Login_field mx_Login_username" type="text"
|
2016-10-14 15:34:44 +01:00
|
|
|
name="username" // make it a little easier for browser's remember-password
|
2015-11-12 15:28:57 +00:00
|
|
|
value={this.state.username} onChange={this.onUsernameChanged}
|
2015-12-15 15:27:56 +00:00
|
|
|
placeholder="Email or user name" autoFocus />
|
2017-03-14 11:50:13 +00:00
|
|
|
or
|
|
|
|
|
<div className="mx_Login_phoneSection">
|
|
|
|
|
<CountryDropdown ref="phone_country" onOptionChange={this.onPhoneCountryChanged}
|
|
|
|
|
className="mx_Login_phoneCountry"
|
|
|
|
|
value={this.state.phoneCountry}
|
|
|
|
|
/>
|
|
|
|
|
<input type="text" ref="phoneNumber"
|
|
|
|
|
onChange={this.onPhoneNumberChanged}
|
|
|
|
|
placeholder="Mobile phone number"
|
|
|
|
|
className="mx_Login_phoneNumberField mx_Login_field"
|
|
|
|
|
value={this.state.phoneNumber}
|
|
|
|
|
name="phoneNumber"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2015-11-12 15:28:57 +00:00
|
|
|
<br />
|
2016-08-03 15:59:17 +01:00
|
|
|
<input className={pwFieldClass} ref={(e) => {this._passwordField = e;}} type="password"
|
2016-10-14 15:34:44 +01:00
|
|
|
name="password"
|
2015-11-12 15:28:57 +00:00
|
|
|
value={this.state.password} onChange={this.onPasswordChanged}
|
|
|
|
|
placeholder="Password" />
|
|
|
|
|
<br />
|
2016-01-12 17:20:16 +00:00
|
|
|
{forgotPasswordJsx}
|
2016-09-29 17:38:52 +01:00
|
|
|
<input className="mx_Login_submit" type="submit" value="Sign in" />
|
2015-11-12 15:28:57 +00:00
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-08-03 15:59:17 +01:00
|
|
|
});
|