diff --git a/app/components/RegisterForm.js b/app/components/RegisterForm.js index 9a830d0..0193bbc 100644 --- a/app/components/RegisterForm.js +++ b/app/components/RegisterForm.js @@ -1,188 +1,188 @@ import React, { Component } from 'react'; import { View, Text, Linking, Keyboard } from 'react-native'; import PropTypes from 'prop-types'; import ipaddr from 'ipaddr.js'; import autoBind from 'auto-bind'; import FooterBox from './FooterBox'; import { Button, TextInput, Title, Subheading } from 'react-native-paper'; import EnrollmentModal from './EnrollmentModal'; import storage from '../storage'; import config from '../config'; import styles from '../assets/styles/blink/_RegisterForm.scss'; function isASCII(str) { return /^[\x00-\x7F]*$/.test(str); } function handleLink(event) { Linking.openURL('https://mdns.sipthor.net/sip_login_reminder.phtml'); } class RegisterForm extends Component { constructor(props) { super(props); autoBind(this); this.state = { accountId: '', password: '', registering: false, remember: false, showEnrollmentModal: false }; } componentDidMount() { storage.get('account').then((account) => { if (account) { this.setState(Object.assign({}, account, {remember: true})); if (this.props.autoLogin && this.state.password !== '') { this.props.handleRegistration(this.state.accountId, this.state.password); } } }); } handleAccountIdChange(value) { - this.setState({accountId: value}); + this.setState({accountId: value.trim()}); } handlePasswordChange(value) { - this.setState({password: value}); + this.setState({password: value.trim()}); } handleSubmit(event) { if (!this.validInput()) { return; } if (event) { event.preventDefault(); } let account = this.state.accountId; if (this.state.accountId.indexOf('@') === -1 ) { account = this.state.accountId + '@' + config.defaultDomain; } Keyboard.dismiss(); this.props.handleRegistration(account, this.state.password, true); } handleEnrollment(account) { this.setState({showEnrollmentModal: false}); if (account !== null) { this.setState({accountId: account.accountId, password: account.password, registering: true}); this.props.handleRegistration(account.accountId, account.password); } } createAccount(event) { event.preventDefault(); this.setState({showEnrollmentModal: true}); } validInput() { const domain = this.state.accountId.indexOf('@') !== -1 ? this.state.accountId.substring(this.state.accountId.indexOf('@') + 1): ''; const validDomain = domain === '' || (!ipaddr.IPv4.isValidFourPartDecimal(domain) && !ipaddr.IPv6.isValid(domain) && domain.length > 3 && domain.indexOf('.') !== - 1 && (domain.length - 2 - domain.indexOf('.')) > 0); const validInput = isASCII(this.state.accountId) && validDomain && this.state.password !== '' && isASCII(this.state.password); return validInput; } render() { let containerClass; if (this.props.isTablet) { containerClass = this.props.orientation === 'landscape' ? styles.landscapeTabletContainer : styles.portraitTabletContainer; } else { containerClass = this.props.orientation === 'landscape' ? styles.landscapeContainer : styles.portraitContainer; } return ( Sylk Sign in to continue this.passwordInput.focus()} /> { this.passwordInput = ref; }} /> { config.enrollmentUrl ? : null } handleLink()} style={styles.recoverLink}>Recover lost passsword... ); } } RegisterForm.propTypes = { classes : PropTypes.object, handleRegistration : PropTypes.func.isRequired, registrationInProgress : PropTypes.bool.isRequired, autoLogin : PropTypes.bool, orientation : PropTypes.string, isTablet : PropTypes.bool, phoneNumber : PropTypes.string }; export default RegisterForm;