2008-11-12 03:40:49 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
|
|
|
|
/**
|
|
|
|
|
* Gallery - a web based photo album viewer and editor
|
|
|
|
|
* Copyright (C) 2000-2008 Bharat Mediratta
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
|
* your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
class Login_Controller extends Controller {
|
2009-03-16 04:33:45 +00:00
|
|
|
|
|
|
|
|
public function ajax() {
|
|
|
|
|
$view = new View("login_ajax.html");
|
|
|
|
|
$view->form = user::get_login_form("login/auth_ajax");
|
|
|
|
|
print $view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function auth_ajax() {
|
2009-03-16 08:05:44 +00:00
|
|
|
list ($valid, $form) = $this->_auth("login/auth_ajax");
|
2009-03-16 04:33:45 +00:00
|
|
|
if ($valid) {
|
|
|
|
|
print json_encode(
|
2009-05-10 19:57:58 +00:00
|
|
|
array("result" => "success"));
|
2008-12-25 05:12:46 +00:00
|
|
|
} else {
|
2009-03-16 04:33:45 +00:00
|
|
|
print json_encode(
|
|
|
|
|
array("result" => "error",
|
|
|
|
|
"form" => $form->__toString()));
|
2008-12-25 05:12:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-16 04:33:45 +00:00
|
|
|
public function html() {
|
|
|
|
|
print user::get_login_form("login/auth_html");
|
2009-03-11 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-16 04:33:45 +00:00
|
|
|
public function auth_html() {
|
2009-03-16 08:05:44 +00:00
|
|
|
list ($valid, $form) = $this->_auth("login/auth_html");
|
2009-03-16 04:33:45 +00:00
|
|
|
if ($valid) {
|
|
|
|
|
url::redirect("albums/1");
|
|
|
|
|
} else {
|
|
|
|
|
print $form;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-12 03:40:49 +00:00
|
|
|
|
2009-03-16 08:05:44 +00:00
|
|
|
private function _auth($url) {
|
|
|
|
|
$form = user::get_login_form($url);
|
2008-12-25 05:12:46 +00:00
|
|
|
$valid = $form->validate();
|
|
|
|
|
if ($valid) {
|
|
|
|
|
$user = ORM::factory("user")->where("name", $form->login->inputs["name"]->value)->find();
|
|
|
|
|
if (!$user->loaded || !user::is_correct_password($user, $form->login->password->value)) {
|
2008-12-25 23:43:44 +00:00
|
|
|
log::warning(
|
2009-04-05 20:43:05 +00:00
|
|
|
"user",
|
|
|
|
|
t("Failed login for %name", array("name" => $form->login->inputs["name"]->value)));
|
2008-12-25 05:12:46 +00:00
|
|
|
$form->login->inputs["name"]->add_error("invalid_login", 1);
|
|
|
|
|
$valid = false;
|
2008-11-12 03:40:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-11-12 21:42:40 +00:00
|
|
|
|
2008-12-25 05:12:46 +00:00
|
|
|
if ($valid) {
|
|
|
|
|
user::login($user);
|
2009-01-15 10:02:41 +00:00
|
|
|
log::info("user", t("User %name logged in", array("name" => $user->name)));
|
2009-04-05 20:43:05 +00:00
|
|
|
|
|
|
|
|
// If this user is an admin, check to see if there are any post-install tasks that we need
|
|
|
|
|
// to run and take care of those now.
|
|
|
|
|
if ($user->admin && module::get_var("core", "choose_default_tookit", null)) {
|
|
|
|
|
graphics::choose_default_toolkit();
|
|
|
|
|
module::clear_var("core", "choose_default_tookit");
|
|
|
|
|
}
|
2008-12-25 05:12:46 +00:00
|
|
|
}
|
2009-02-04 05:49:29 +00:00
|
|
|
|
2009-03-16 04:33:45 +00:00
|
|
|
return array($valid, $form);
|
2008-11-12 03:40:49 +00:00
|
|
|
}
|
|
|
|
|
}
|