2021-10-02 17:21:23 +09:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import { Button } from '@material-ui/core';
|
|
|
|
import { LoadingButton } from '@material-ui/lab';
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Login = () => {
|
|
|
|
const [phone, setPhone] = useState('');
|
|
|
|
const [password, setPassword] = useState('');
|
|
|
|
|
2021-10-02 20:49:05 +09:00
|
|
|
const [errors, setErrors] = useState({phone:'', password:''})
|
|
|
|
const [err_msg, setErrMsg] = useState('')
|
2021-10-02 17:21:23 +09:00
|
|
|
|
|
|
|
const handleSubmit = (e) => {
|
|
|
|
e.preventDefault();
|
2021-10-02 20:49:05 +09:00
|
|
|
setErrMsg('');
|
2021-10-02 17:21:23 +09:00
|
|
|
if(!validateForm()) return;
|
|
|
|
const formdata = new FormData();
|
2021-10-02 20:49:05 +09:00
|
|
|
formdata.append('tel', phone);
|
2021-10-02 17:21:23 +09:00
|
|
|
formdata.append('password', password);
|
2021-10-02 20:49:05 +09:00
|
|
|
axios.post('/children/login/', formdata)
|
2021-10-02 17:21:23 +09:00
|
|
|
.then(response => {
|
|
|
|
if(response.data.status_code==200){
|
2021-10-02 20:49:05 +09:00
|
|
|
window.location.href = '/c-account/meating';
|
2021-10-02 17:21:23 +09:00
|
|
|
}
|
2021-10-02 20:49:05 +09:00
|
|
|
elseif(response.data.status_code == 400)
|
|
|
|
{
|
|
|
|
setErrMsg("ログインに失敗しました。10回連続で失敗すると、一定期間ログインできなくなります。")
|
|
|
|
}
|
|
|
|
// elseif(response.data.status_code == 422){
|
|
|
|
|
|
|
|
// }
|
2021-10-02 17:21:23 +09:00
|
|
|
})
|
2021-10-02 20:49:05 +09:00
|
|
|
.catch(err=>{setErrMsg("Server Error!")})
|
2021-10-02 17:21:23 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
const validateForm = () => {
|
|
|
|
let errors = {};
|
|
|
|
let formIsValid = true;
|
|
|
|
|
2021-10-02 20:49:05 +09:00
|
|
|
if(phone.length == 0){ formIsValid = false; errors['phone'] = 'Required'; }
|
|
|
|
else errors['phone'] = '';
|
2021-10-02 17:21:23 +09:00
|
|
|
|
2021-10-02 20:49:05 +09:00
|
|
|
if(password.length == 0){ formIsValid = false; errors['password'] = 'Required'; }
|
|
|
|
else errors['password'] = '';
|
2021-10-02 17:21:23 +09:00
|
|
|
|
|
|
|
setErrors(errors);
|
|
|
|
return formIsValid;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<form onSubmit={handleSubmit} noValidate>
|
|
|
|
<p className="text-center font-weight-bold ft-20">ログイン</p>
|
2021-10-02 20:49:05 +09:00
|
|
|
{
|
|
|
|
err_msg.length != 0 &&
|
|
|
|
<span className="l-alert__text--red ft-16 ft-md-14">{err_msg}</span>
|
|
|
|
}
|
2021-10-02 17:21:23 +09:00
|
|
|
|
|
|
|
<div className="c-input mt-80-px">
|
|
|
|
<label htmlFor="phone" className="c-input__label"> 電話番号 </label>
|
|
|
|
<input type="text" name="phone" id="phone" className={`w-100 c-input__edit ${ errors['phone'] && "is-invalid c-input__target" }`} value={phone} onChange={e=>setPhone(e.target.value)} autoFocus/>
|
|
|
|
{
|
2021-10-02 20:49:05 +09:00
|
|
|
errors['phone'].length != 0 &&
|
|
|
|
<span className="l-alert__text--red ft-16 ft-md-14">{errors['phone']}</span>
|
2021-10-02 17:21:23 +09:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="c-input mt-40-px">
|
|
|
|
<label htmlFor="password" className="c-input__label"> パスワード </label>
|
|
|
|
<input type="password" name="password" id="password" className={`w-100 c-input__edit ${ errors['password'] && "is-invalid c-input__target" }`} value={password} onChange={e=>setPassword(e.target.value)} autoFocus/>
|
|
|
|
{
|
2021-10-02 20:49:05 +09:00
|
|
|
errors['password'].length != 0 &&
|
|
|
|
<span className="l-alert__text--red ft-16 ft-md-14">{errors['password']}</span>
|
2021-10-02 17:21:23 +09:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
2021-10-02 20:49:05 +09:00
|
|
|
<div className="c-input mt-40-px">
|
|
|
|
<div className="c-input__checkbox text-center">
|
|
|
|
<label htmlFor="remember_me" className="m-0 ft-15 ft-md-13">
|
|
|
|
<span>ログイン情報を保持する</span>
|
|
|
|
<input id="remember_me" name="remember" type="checkbox" value="remember"/>
|
|
|
|
<div className="color-box"></div>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-10-02 17:21:23 +09:00
|
|
|
|
2021-10-02 20:49:05 +09:00
|
|
|
<div className="mt-4">
|
|
|
|
<Button type="submit" fullWidth className="p-3 rounded-20 ft-15 ft-md-13 font-weight-bold text-black bg-color-2">ログイン</Button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="mt-4 text-center">
|
|
|
|
<a href="/forgot-password/c-account" className="ft-15 ft-md-13 text-black text-decoration-none scale-1">パスワード紛失の方はコチラ</a>
|
2021-10-02 17:21:23 +09:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(document.getElementById('login')){
|
|
|
|
ReactDOM.render(
|
|
|
|
<Login />,
|
|
|
|
document.getElementById('login')
|
|
|
|
)
|
|
|
|
}
|