import React, { Component, PropTypes } from "react"; export class LoginForm extends Component { constructor (props) { super(props); this.handleSubmit = this.handleSubmit.bind(this); } setError (formGroup, error) { if (error) { formGroup.classList.add("has-error"); formGroup.classList.remove("has-success"); return true; } formGroup.classList.remove("has-error"); formGroup.classList.add("has-success"); return false; } handleSubmit (e) { e.preventDefault(); const username = this.refs.username.value.trim(); const password = this.refs.password.value.trim(); const endpoint = this.refs.endpoint.value.trim(); const rememberMe = this.refs.rememberMe.checked; var hasError = this.setError(this.refs.usernameFormGroup, !username); hasError |= this.setError(this.refs.passwordFormGroup, !password); hasError |= this.setError(this.refs.endpointFormGroup, !endpoint); if (!hasError) { this.props.onSubmit(username, password, endpoint, rememberMe); } } componentDidUpdate () { if (this.props.error) { $(this.refs.loginForm).shake(3, 10, 300); this.setError(this.refs.usernameFormGroup, this.props.error); this.setError(this.refs.passwordFormGroup, this.props.error); this.setError(this.refs.endpointFormGroup, this.props.error); } } render () { return (
{ this.props.error }
{ this.props.info }
Welcome back on Ampache, let"s go!