<commit_before>import React from 'react';
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import Cookies from 'js-cookie';
import { Link } from 'react-router-dom';

// components:
import Utils from '/imports/lib/utils';
import OAuthButtons from '/imports/ui/components/auth/OAuthButtons';
import PWDSignupForm from '/imports/ui/components/auth/PWDSignupForm';

class ModalSignup extends React.Component {
	static propTypes = {
		lowered: React.PropTypes.bool,
		closeModal: React.PropTypes.func,
	};

	static defaultProps = {
		lowered: false,
	};

	constructor(props) {
		super(props);

		this.state = {
			errorMsg: '',
			errorSocial: '',
		};

		// methids
		this._handleKeyDown = this._handleKeyDown.bind(this);
		this.handleSignup = this.handleSignup.bind(this);
		this.handleSignupFacebook = this.handleSignupFacebook.bind(this);
		this.handleSignupGoogle = this.handleSignupGoogle.bind(this);
		this.handleSignupTwitter = this.handleSignupTwitter.bind(this);
		this.goToSigIn = this.goToSigIn.bind(this);
	}

	componentWillMount() {
		document.addEventListener('keydown', this._handleKeyDown);
	}

	componentWillUnmount() {
		document.removeEventListener('keydown', this._handleKeyDown);
	}

	_handleKeyDown(event) {

		const { closeModal } = this.props;

		if (event.keyCode === ESCAPE_KEY) closeModal();
	}

	handleSignup(email, password, passwordRepeat) {

		if (password !== passwordRepeat) {
			this.setState({
				errorMsg: 'Passwords do not match.',
			});
			throw new Meteor.Error('Passwords do not match');
		}

		const checkPassword = Accounts._hashPassword(password);

		Meteor.call('createAccount', { email, checkPassword }, (err, result) => {
			const path = '/';

			if (!err) {
				Meteor.loginWithToken(result.stampedToken.token, (_err) => {
					if (_err) {
						this.setState({
							errorMsg: 'Invalid email or password',
						});

						return false;
					}

					const domain = Utils.getEnvDomain();

					if (domain) {
						Cookies.set('userId', Meteor.userId(), { domain });
						Cookies.set('loginToken', token, { domain });
					} else {
						Cookies.set('userId', Meteor.userId());
						Cookies.set('loginToken', token);
					}
					this.props.closeModal();
				});
			} else {
				this.setState({
					errorMsg: 'Invalid email or password',
				});
			}
		});
	}

	handleSignupFacebook() {
		Meteor.loginWithFacebook({}, (err) => {
			if (!err) {
				this.props.closeModal();
			} else {
				this.setState({
					errorSocial: `Error with signing in with Facebook: ${err.reason}`,
				});
			}
		});
	}

	handleSignupGoogle() {
		Meteor.loginWithGoogle({}, (err) => {
			if (!err) {
				this.props.closeModal();
			} else {
				this.setState({
					errorSocial: `Error with signing in with Google: ${err.reason}`,
				});
			}
		});
	}

	handleSignupTwitter() {
		Meteor.loginWithTwitter({}, (err) => {
			if (!err) {
				this.props.closeModal();
			} else {
				this.setState({
					errorSocial: `Error with signing in with Twitter: ${err.reason}`,
				});
			}
		});
	}
	
	goToSigIn(event) {
		event.preventDefault();
		this.props.closeModal();
		this.props.loginModal();
	};<commit_msg>add modal function to props check<commit_after>import React from 'react';
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import Cookies from 'js-cookie';
import { Link } from 'react-router-dom';

// components:
import Utils from '/imports/lib/utils';
import OAuthButtons from '/imports/ui/components/auth/OAuthButtons';
import PWDSignupForm from '/imports/ui/components/auth/PWDSignupForm';

class ModalSignup extends React.Component {
	static propTypes = {
		lowered: React.PropTypes.bool,
		closeModal: React.PropTypes.func,
		loginModal: React.PropTypes.func,
	};

	static defaultProps = {
		lowered: false,
	};

	constructor(props) {
		super(props);

		this.state = {
			errorMsg: '',
			errorSocial: '',
		};

		// methids
		this._handleKeyDown = this._handleKeyDown.bind(this);
		this.handleSignup = this.handleSignup.bind(this);
		this.handleSignupFacebook = this.handleSignupFacebook.bind(this);
		this.handleSignupGoogle = this.handleSignupGoogle.bind(this);
		this.handleSignupTwitter = this.handleSignupTwitter.bind(this);
		this.goToSigIn = this.goToSigIn.bind(this);
	}

	componentWillMount() {
		document.addEventListener('keydown', this._handleKeyDown);
	}

	componentWillUnmount() {
		document.removeEventListener('keydown', this._handleKeyDown);
	}

	_handleKeyDown(event) {

		const { closeModal } = this.props;

		if (event.keyCode === ESCAPE_KEY) closeModal();
	}

	handleSignup(email, password, passwordRepeat) {

		if (password !== passwordRepeat) {
			this.setState({
				errorMsg: 'Passwords do not match.',
			});
			throw new Meteor.Error('Passwords do not match');
		}

		const checkPassword = Accounts._hashPassword(password);

		Meteor.call('createAccount', { email, checkPassword }, (err, result) => {
			const path = '/';

			if (!err) {
				Meteor.loginWithToken(result.stampedToken.token, (_err) => {
					if (_err) {
						this.setState({
							errorMsg: 'Invalid email or password',
						});

						return false;
					}

					const domain = Utils.getEnvDomain();

					if (domain) {
						Cookies.set('userId', Meteor.userId(), { domain });
						Cookies.set('loginToken', token, { domain });
					} else {
						Cookies.set('userId', Meteor.userId());
						Cookies.set('loginToken', token);
					}
					this.props.closeModal();
				});
			} else {
				this.setState({
					errorMsg: 'Invalid email or password',
				});
			}
		});
	}

	handleSignupFacebook() {
		Meteor.loginWithFacebook({}, (err) => {
			if (!err) {
				this.props.closeModal();
			} else {
				this.setState({
					errorSocial: `Error with signing in with Facebook: ${err.reason}`,
				});
			}
		});
	}

	handleSignupGoogle() {
		Meteor.loginWithGoogle({}, (err) => {
			if (!err) {
				this.props.closeModal();
			} else {
				this.setState({
					errorSocial: `Error with signing in with Google: ${err.reason}`,
				});
			}
		});
	}

	handleSignupTwitter() {
		Meteor.loginWithTwitter({}, (err) => {
			if (!err) {
				this.props.closeModal();
			} else {
				this.setState({
					errorSocial: `Error with signing in with Twitter: ${err.reason}`,
				});
			}
		});
	}
	
	goToSigIn(event) {
		event.preventDefault();
		this.props.closeModal();
		this.props.loginModal();
	}
{'fraction_non_alphanumeric': 0.1539303016096265, 'fraction_numerical': 0.0, 'mean_word_length': 3.438280166435506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7053132', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2101, 'n_words': 401}