front > login : login page working
This commit is contained in:
parent
ca5b3ed8c4
commit
d15d4898c6
4 changed files with 109 additions and 5 deletions
35
public/site/config/routes/login.php
Normal file
35
public/site/config/routes/login.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
"pattern" => "login.json",
|
||||
"method" => "POST",
|
||||
"action" => function () {
|
||||
$json = file_get_contents("php://input");
|
||||
$data = json_decode($json);
|
||||
|
||||
$kirby = kirby();
|
||||
|
||||
$email = $data->email;
|
||||
$password = $data->password;
|
||||
|
||||
if(V::email($email)) {
|
||||
try {
|
||||
$kirby->auth()->login($email, $password);
|
||||
return json_encode([
|
||||
"status" => "success",
|
||||
"role" => (string) $kirby->user()->role()
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
return json_encode([
|
||||
"status" => "error",
|
||||
"message" => "<strong>Email ou mot de passe invalide.</strong><br>Contactez l'administrateur pour demander la réinitialisation de vos informations de connexion."
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
return json_encode([
|
||||
"status" => "error",
|
||||
"message" => "<strong>Email invalide.</strong>"
|
||||
]);
|
||||
}
|
||||
},
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue