/** * Confirm controller function * Sets confirm to 1 of user with userid * * @return json|xml True on success otherwise false */ public function confirm() { try { $error_flag = false; $message = ""; $user = new LoveUser(); $username = $_REQUEST["username"]; $token = $_REQUEST["token"]; if ($user->loadByUsername($username) && $user->getConfirmed() == 0 && $user->getToken() == $token) { $user->setConfirmed(1)->setActive(1); $user->save(); // push user confirmed to registred applications if (!$this->getResponse()->pushUser($this->AppAuth->getAppName(), $user->getId(), 'pushVerifyUser')) { throw Exception('User could not be pushed to the registred applications.'); } echo json_encode(array("error" => 0, "message" => "User confirmed")); exit(0); } else { echo json_encode(array("error" => 1, "message" => "Unable to confirm the user")); exit(0); } } catch (Exception $e) { $msg = 'An error occured while updating:' . "\n"; $msg .= "\n" . ' ' . $e->getMessage(); if (defined('APPLICATION_ENV') && APPLICATION_ENV == 'development') { $msg .= "\n\nFile: " . $e->getFile(); $msg .= "\nLine: " . $e->getLine(); $msg .= "\n" . $e->getTraceAsString(); } else { if (defined('APPLICATION_ENV') && APPLICATION_ENV == 'testing') { $msg .= "<br /><br />File: " . $e->getFile(); $msg .= "<br />Line: " . $e->getLine(); $msg .= "<br />" . $e->getTraceAsString(); } } echo $msg; exit; } }