Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Exception handling ajax login

  • Loading branch information...
commit 3b59fde1e16a38596bc4c78ce94ddcc650b17b64 1 parent 41cbedd
@chardev authored
Showing with 23 additions and 10 deletions.
  1. +23 −10 website/public/api/user.php
View
33 website/public/api/user.php
@@ -1,18 +1,14 @@
<?php
- use chardev\backend\UserDatabase;
+ use chardev\backend\UserDatabase;
-use chardev\Session;
+use chardev\Session;
require_once '../../app/chardev/Autoloader.php';
use chardev\Ajax;
chardev\Session::startBackendSession();
-/*
- if( isset($_GET['language']) ) {
- set_user_settings("language",(int)$_GET['language']);
- }
-*/
+
$ud = null;
try {
@@ -32,9 +28,26 @@
UserDatabase::getInstance()->changePassword($_POST['UserId'], $_POST['Password']);
}
else if( isset($_POST['UserName']) && isset($_POST['Password'])) {
-
- $loggedInUser = Session::logIn($_POST['UserName'], $_POST['Password'], isset($_POST['Cookie']) ? true : false);
-
+ try {
+ $loggedInUser = Session::logIn($_POST['UserName'], $_POST['Password'], isset($_POST['Cookie']) ? true : false);
+ }
+ catch( \InvalidArgumentException $iae ) {
+ Ajax::dieOnError("Unable to log in","Invalid inputs: " . $iae->getMessage());
+ }
+ catch( \chardev\backend\RegistrationPendingException $rpe ) {
+ Ajax::dieOnError(
+ "Unable to log in",
+ "Your registration is pending!<br/>".
+ "You should have received an activation email, if not, click <a class='std_link' href='?resend_mail&to=".$_POST['UserName']."'>here</a> to send the mail again."
+ );
+ }
+ catch( \chardev\backend\WrongUserNamePasswordException $rpe ) {
+ Ajax::dieOnError(
+ "Unable to log in",
+ "Wrong user name or password"
+ );
+ }
+
echo json_encode(array(
"session_id" => session_id(),
"user_id" => $loggedInUser->getId(),
Please sign in to comment.
Something went wrong with that request. Please try again.