summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2016-02-01 19:33:57 -0500
committerMalf Furious <m@lfurio.us>2016-02-01 19:33:57 -0500
commitfaa6ca0b2e9430d2f9d689aab583a7f881ed03bf (patch)
treeb85e40a6be971bcaceb17e527fe2243937b9765a /app
parentc776b36fd884808435dd1208f0dd9a57216b3927 (diff)
downloadscrott-faa6ca0b2e9430d2f9d689aab583a7f881ed03bf.tar.gz
scrott-faa6ca0b2e9430d2f9d689aab583a7f881ed03bf.zip
Implement 'login' action on Auth MVC
Finished initial functionality for Auth MVC by implementing the login feature
Diffstat (limited to 'app')
-rw-r--r--app/controller/auth.control.php10
-rw-r--r--app/model/auth.mod.php27
2 files changed, 37 insertions, 0 deletions
diff --git a/app/controller/auth.control.php b/app/controller/auth.control.php
index 9bb8349..0e970dd 100644
--- a/app/controller/auth.control.php
+++ b/app/controller/auth.control.php
@@ -25,6 +25,10 @@ class Auth extends Controller
$this->action_signup_submit($mod);
break;
+ case "login":
+ $this->action_login($mod);
+ break;
+
default:
$this->action_default($mod);
break;
@@ -50,6 +54,12 @@ class Auth extends Controller
$mod->signupSubmit($_REQUEST['input']);
$this->action_signup($mod);
}
+
+ function action_login($mod)
+ {
+ $mod->login($_REQUEST['input']);
+ $this->action_default($mod);
+ }
}
?>
diff --git a/app/model/auth.mod.php b/app/model/auth.mod.php
index 9fa67e4..2b61b91 100644
--- a/app/model/auth.mod.php
+++ b/app/model/auth.mod.php
@@ -66,6 +66,33 @@ class AuthModel extends CommonModel
$this->setCurrentUser($user);
$this->redirectTo($this->ap() . "/");
}
+
+ /*
+ * Attempt to login
+ */
+ function login($input)
+ {
+ $form = new Form();
+ $form->field_text("username");
+ $form->field_text("password", null, false);
+
+ if (!$form->populate($input))
+ {
+ $this->logFormErrors($form);
+ return;
+ }
+
+ $user = new User();
+
+ if (!($user->initByUsername($form->username) && $user->validatePassword($form->password)))
+ {
+ $this->logError("Username or password is incorrect");
+ return;
+ }
+
+ $this->setCurrentUser($user);
+ $this->redirectTo($this->ap() . "/");
+ }
}
?>