-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReset.js
56 lines (52 loc) · 1.64 KB
/
Reset.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React,{useState} from 'react'
import {useNavigate} from 'react-router-dom'
import M from 'materialize-css'
const Reset = ()=>{
const navigate = useNavigate()
const [email,setEmail] = useState("")
const PostData = ()=>{
if(!/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email)){
M.toast({html: "invalid email",classes:"#c62828 red darken-3"})
return
}
fetch('/reset-password',{
method:"post",
headers:{
"Content-Type":"application/json"
},
body:JSON.stringify({
email
})
}).then(res=>res.json())
.then(data=>{
if(data.error){
M.toast({html: data.error,classes:"#c62828 red darken-3"})
}
else{
M.toast({html:data.message,classes:"#43a047 green darken-1"})
navigate('/login')
}
}).catch(err=>{
console.log(err)
})
}
return (
<div className="mycard">
<div className="card auth-card input-field">
<h2>Zaayka</h2>
<input
type="text"
placeholder="email"
value={email}
onChange={(e)=>setEmail(e.target.value)}
/>
<button className="btn waves-effect waves-light #64b5f6 blue darken-1"
onClick={()=>PostData()}
>
Reset Password
</button>
</div>
</div>
)
}
export default Reset