import React, { Component } from "react"; import CustomInput from "./CustomInput.jsx"; import CustomErrors from "./CustomErrors.jsx"; import io from "../../io"; import config from "../../../../config/default"; export default class Login extends Component { constructor() { super(); this.state = { password: "", email: "", errors: [], inputInvalid: { email: true, password: true, }, }; this.login = this.login.bind(this); } updateField(field, event) { this.setState({ [field]: event.target.value, }); } login() { if (CustomInput.hasInvalidInput(this.state.inputInvalid)) { alert("Input invalid. Fix before continuing."); } else { this.setState({ errors: [] }); io.getSocket(socket => { socket.emit("users.login", this.state.email, this.state.password, res => { if (res.status === "success") { const date = new Date(); date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000)); const secure = (config.cookie.secure) ? "secure=true; " : ""; let domain = ""; if (config.cookie.domain !== "localhost") domain = ` domain=${ config.cookie.domain };`; document.cookie = `SID=${ res.SID }; expires=${ date.toGMTString() }; ${ domain }${ secure }path=/`; location.reload(); // if we could avoid this, then that would be better } else { this.setState({ errors: [res.message] }); } }); }); } } githubRedirect() { localStorage.setItem("github_redirect", window.location.pathname); } validationCallback = CustomInput.validationCallback(this); render() { return (
By logging in/registering you agree to our Terms of Service and Privacy Policy.