blob: eaa1362f9b30226aa880621d1950ab2cb88576fe [file] [log] [blame]
Adrien Béraud6ecaa402021-04-06 17:37:25 -04001import React from 'react';
2
Adrien Béraudab519ff2022-05-03 15:34:48 -04003import Button from '@mui/material/Button';
4import TextField from '@mui/material/TextField';
5import FormControlLabel from '@mui/material/FormControlLabel';
6import Checkbox from '@mui/material/Checkbox';
7import Link from '@mui/material/Link';
Adrien Béraudab519ff2022-05-03 15:34:48 -04008import Typography from '@mui/material/Typography';
Adrien Béraudab519ff2022-05-03 15:34:48 -04009import DialogTitle from '@mui/material/DialogTitle';
10import Dialog from '@mui/material/Dialog';
11import DialogActions from '@mui/material/DialogActions';
12import DialogContent from '@mui/material/DialogContent';
Adrien Béraud6ecaa402021-04-06 17:37:25 -040013
14import authManager from '../AuthManager'
15
16function Copyright() {
17 return (
18 <Typography variant="body2" color="textSecondary" align="center">
19 {'Copyright © 2016-'}{new Date().getFullYear()}{' Savoir-faire Linux Inc.'}
20 <Link color="inherit" href="https://jami.net/">
21 Jami.net
22 </Link>{' '}
23 {'.'}
24 </Typography>
25 );
26}
27
Adrien Béraud6ecaa402021-04-06 17:37:25 -040028class SignInPage extends React.Component {
29
30 constructor(props) {
31 console.log("SignInPage " + props.open)
32 super(props)
33 this.state = {
Adrien Béraud6ecaa402021-04-06 17:37:25 -040034 submitted: false,
idillon-sfl5d174552022-08-23 14:34:24 -040035 loading: false,
Adrien Béraud6ecaa402021-04-06 17:37:25 -040036 }
37 this.handleSubmit = this.handleSubmit.bind(this);
38 this.localLogin = this.localLogin.bind(this);
39 }
40
41 handleusername(text) {
42 this.setState({ username: text.target.value })
43 }
44
45 handlePassword(text) {
46 this.setState({ password: text.target.value })
47 }
48
49 localLogin() {
50 this.setState({
51 submitted: true,
52 loading: true
53 })
Adrien Béraude74741b2021-04-19 13:22:54 -040054 authManager.authenticate('admin', 'admin')
Adrien Béraud6ecaa402021-04-06 17:37:25 -040055 /*fetch('/api/localLogin?username=none&password=none', {
56 header: { "Content-Type": "application/json" },
57 method: "POST",
58 credentials: 'same-origin'
59 //body: JSON.stringify({ obj })
60 })
61 .then((res) => {
62 if (res.status === '200') {
63 this.setState({
64 redirect: true
65 });
66 } else if (res.status === '401') {
67 this.setState({
68 loading: false,
69 error: true,
70 open: true,
71 errorMessage: "Wrong credentials! Your are not allowed to connect"
72 })
73 }
74 //this.setState({ session: res });
75 }).catch((e) => {
76 this.setState({
77 loading: false,
78 error: true,
79 open: true,
80 errorMessage: e.toString()
81 })
82 })*/
83 }
84
85 handleSubmit(event) {
86 event.preventDefault();
87 let obj = {}
88 obj.username = this.state.username;
89 obj.password = this.state.password;
90
91 this.setState({
92 submitted: true,
93 loading: true
94 })
95
96 fetch('/api/login?username=' + obj.username + '&password=' + obj.password,
97 {
98 header: {
99 "Content-Type": "application/json"
100 },
101 method: "POST",
102 credentials: 'same-origin'
103 //body: JSON.stringify({ obj })
104 }
105 ).then((res) => {
106 if (res.status === '200') {
107 this.setState({
108 redirect: true
109 });
110 } else if (res.status === '401') {
111 this.setState({
112 loading: false,
113 error: true,
114 open: true,
115 errorMessage: "Wrong credentials! Your are not allowed to connect"
116 })
117 }
118 //this.setState({ session: res });
119 }).catch((e) => {
120 this.setState({
121 loading: false,
122 error: true,
123 open: true,
124 errorMessage: e.toString()
125 })
126 })
127 }
128
129 render() {
130 console.log("SignInPage render " + this.props.open)
131 return (
132 <Dialog open={this.props.open}>
133 <DialogTitle>Se connecter</DialogTitle>
134 <DialogContent>
135 <Button
136 type="submit"
137 fullWidth
138 variant="contained"
139 color="primary"
140 className=""/*{classes.submit}*/
141 onClick={() => { this.localLogin() }}
142 >
143 Compte local
144 </Button>
Adrien Béraud6ecaa402021-04-06 17:37:25 -0400145 <TextField
146 variant="outlined"
147 margin="normal"
148 required
149 fullWidth
150 id="username"
151 label="LDAP Savoir-faire Linux"
152 name="username"
153 autoComplete="email"
154 autoFocus
155 onChange={(text) => { this.handleusername(text) }}
156 />
157 <TextField
158 variant="outlined"
159 margin="normal"
160 required
161 fullWidth
162 name="password"
163 label="Mot de passe"
164 type="password"
165 id="password"
166 autoComplete="current-password"
167 onChange={(text) => { this.handlePassword(text) }}
168 />
169 <FormControlLabel
170 control={<Checkbox value="remember" color="primary" />}
171 label="Se rapeller de moi"
172 />
173 </DialogContent>
174
175 <DialogActions>
176 <Button
177 type="submit"
178 size="medium"
179 onClick={this.handleSubmit}
180 >
181 Se connecter
182 </Button>
183 </DialogActions>
184 </Dialog>
185 );
186 }
187}
188
189
190export default SignInPage;