public function check()
{
if ($data = $this->param('auth')) {
$user = $this->module('auth')->authenticate($data);
if ($user) {
$this->module("auth")->setUser($user);
// log to history
$this->helper("history")->log(["msg" => "%s logged in", "args" => [$user["name"] ? $user["name"] : $user["user"]], "mod" => "auth"]);
}
if ($this->req_is('ajax')) {
return $user ? json_encode(["success" => true, "user" => $user, "avatar" => md5($user["email"])]) : '{"success":0}';
} else {
$this->reroute('/');
}
}
return false;
}