import _ from 'lodash'; import { Meteor } from 'meteor/meteor'; import { SimpleSchema } from 'meteor/aldeed:simple-schema'; import { Bert } from 'meteor/themeteorchef:bert'; import React from 'react'; import { Container, Row, Col } from 'reactstrap'; import { Link } from 'react-router'; import { If, Case } from '/imports/client/components/Logic'; import { LoginPane } from '/imports/client/views/org/enter/LoginPane'; import { ForgotPane } from '/imports/client/views/org/enter/ForgotPane'; import { ResetPane } from '/imports/client/views/org/enter/ResetPane'; import Validation from '/imports/validation/validationMethods'; // const signupSchemaValidator = new SimpleSchema({ // email: { type: String, regEx: SimpleSchema.RegEx.Email}, // firstName: { type: String, }, // lastName: { type: String, }, // password: { type: String, min: 6}, // }).validator(); let validation = new Validation(); export class EnterLayout extends React.Component { constructor(props) { super(props); this.state = { email: '', password: '', firstName: '', lastName: '', orgName: '', loading: false, error: '', message: '', }; this.onClearState = this.onClearState.bind(this); }; componentWillReceiveProps(nextProps) { console.log(this.props.pane); console.log("this.props.pane"); if(this.props.pane !== nextProps.pane) { this.onClearState(); } }; onClearState(loading) { this.setState({ loading: loading || false, error: '', message: '', }); }; onUpdate(key, value) { this.setState({[key]: value}); }; onForgot(e) { e.preventDefault(); this.onClearState(true); Accounts.forgotPassword({email: this.state.email || '...'}, (error) => { this.onClearState(); if(error) { this.setState({error: 'An error occured.'}); } else { this.setState({message: 'Reset email has been sent. Check your inbox.'}); } }); }; onReset(e) { e.preventDefault(); this.onClearState(true); if(!validation.passwordValidation(this.state.password)){ Bert.alert('Password must be a minimum of 6 characters in length.', 'danger'); this.onClearState(); return false; }else if(!validation.noQwertysAllowed(this.state.password)){ Bert.alert('No qwertys allowed!', 'danger'); this.onClearState(); return false; } else{ Accounts.resetPassword( this.props.location.query.token, this.state.password, (error) => { this.onClearState(); if(error) { this.setState({error: 'An error occured.'}); } } ); } }; onLogin(e) { const self = this; e.preventDefault(); const email = this.state.email; const password = this.state.password; this.onClearState(true); if(email.trim() == '' || !validation.validateEmail(this.state.email)){ this.onClearState(); Bert.alert('Please enter a valid email address!', 'danger'); return false; } if(password.trim() == ''){ Bert.alert('Please enter your password!', 'danger'); this.onClearState(); return false; } Meteor.call('checkEmailInOrg', {email:email,orgId:Session.get('orgId')}, function (error, result) { if(result.success){ Meteor.loginWithPassword( email, password, (e, r) => { self.onClearState(); if(e) { self.setState({error: 'Wrong password.'}) } } ); }else{ Bert.alert('This email is not associated to this Organisation!', 'danger'); self.onClearState(); } }); }; render() { return (
( this.onUpdate(...a)} onForgot = {(...a) => this.onForgot(...a)} /> )} case1 = "reset" then1 = {() => ( this.onUpdate(...a)} onReset = {(...a) => this.onReset(...a)} /> )} else = {() => ( this.onUpdate(...a)} onLogin = {(...a) => this.onLogin(...a)} /> )} />
); }; };