48 lines
1.2 KiB
D
48 lines
1.2 KiB
D
module requests.authorization;
|
|
|
|
import vibe.vibe;
|
|
import response;
|
|
import structures;
|
|
import singlog;
|
|
|
|
void login(HTTPServerRequest req, HTTPServerResponse res, AuthData serverAuthData) {
|
|
auto userAuthData = deserializeJson!AuthData(req.json);
|
|
|
|
if (!(serverAuthData.login == userAuthData.login &&
|
|
serverAuthData.password == userAuthData.password)) {
|
|
log.i(("Данные авторизации не верны: %s").format(req.json));
|
|
res.send(
|
|
true,
|
|
"Данные авторизации не верны"
|
|
);
|
|
return;
|
|
}
|
|
|
|
auto user = UserData(true);
|
|
|
|
req.session = res.startSession();
|
|
req.session.set!UserData("user", user);
|
|
|
|
log.i("Авторизация успешно пройдена");
|
|
|
|
res.send();
|
|
}
|
|
|
|
void logout(HTTPServerRequest req, HTTPServerResponse res) {
|
|
req.session.set!UserData("user", UserData.init);
|
|
res.terminateSession();
|
|
|
|
log.i("Выход из системы");
|
|
|
|
res.send();
|
|
}
|
|
|
|
bool checkAuth(HTTPServerRequest req) {
|
|
if (req.session)
|
|
return req.session.get!UserData("user").login;
|
|
|
|
log.d("Отсутствует авторизация");
|
|
|
|
return false;
|
|
}
|