diff --git a/security/RIGHTS.php b/security/RIGHTS.php index 2e6d162..2a75471 100644 --- a/security/RIGHTS.php +++ b/security/RIGHTS.php @@ -1,24 +1,39 @@ id = $id; $this->username = $username; diff --git a/security/qq/SYS_SECURITY_AVAILABLE.php b/security/qq/SYS_SECURITY_AVAILABLE.php index 01266fb..58c65bb 100644 --- a/security/qq/SYS_SECURITY_AVAILABLE.php +++ b/security/qq/SYS_SECURITY_AVAILABLE.php @@ -1,5 +1,19 @@ username !== $username && self::check(\SYSTEM\SECURITY\RIGHTS::SYS_SAI_SECURITY_RIGHTS_EDIT))){ throw new \SYSTEM\LOG\ERROR("You need to be logged in to trigger this function on your account.");} @@ -102,6 +171,17 @@ class security { return \mail($to, $subject, $message, $header) ? \SYSTEM\LOG\JsonResult::ok() : \SYSTEM\LOG\JsonResult::fail(); } + + /** + * Reset users Password. + * This will facilitate the @see \SYSTEM\TOKEN\token utility to generate + * a token and send it to the users email using php mailinc function. + * A new password is generated on invoke and sent with the email. + * After confirming the token the new password given in the email is valid. + * + * @param string $username Username whos subject to the password reset + * @return bool Returns true or false + */ public static function reset_password($username) { //find all userdata $vars = \SYSTEM\SQL\SYS_SECURITY_USER_INFO::Q1(array($username)); @@ -123,6 +203,19 @@ class security { return \mail($to, $subject, $message, $header) ? \SYSTEM\LOG\JsonResult::ok() : \SYSTEM\LOG\JsonResult::fail(); } + + /** + * Request an Confirm-Email for given Username. + * This will facilitate the @see \SYSTEM\TOKEN\token utility to generate + * a token and send it to the users email using php mailinc function. + * + * This function can only be invoked if the user is logged in and uses the + * function on himself or \SYSTEM\SECURITY\RIGHTS::SYS_SAI_SECURITY_RIGHTS_EDIT + * is present for the invoking user. + * + * @param string $username Username whos subject to the email confirm request + * @return bool Returns true or false + */ public static function confirm_email($username) { if(!self::isLoggedIn() || (self::getUser()->username !== $username && self::check(\SYSTEM\SECURITY\RIGHTS::SYS_SAI_SECURITY_RIGHTS_EDIT))){ throw new \SYSTEM\LOG\ERROR("You need to be logged in to trigger this function on your account.");} @@ -145,39 +238,82 @@ class security { return \mail($to, $subject, $message, $header) ? \SYSTEM\LOG\JsonResult::ok() : \SYSTEM\LOG\JsonResult::fail(); } + + /** + * Confirm a token sent using @see \SYSTEM\TOKEN\token utility + * (email confirm, email change, password reset) + * + * @param string $token Token given in eg an email. + * @param bool $json_result Return data as JSON or Array + * @return bool Returns json with status true or false or a bool + */ public static function confirm($token,$json_result = false) { return \SYSTEM\TOKEN\token::confirm($token) ? ($json_result ? \SYSTEM\LOG\JsonResult::ok() : true) : ($json_result ? \SYSTEM\LOG\JsonResult::fail() : false);} + /** + * Get Userinfo stored in the current Session. + * + * @return User Returns User object or NULL + */ public static function getUser(){ if(!self::isLoggedIn(false)){ return NULL;} return $_SESSION[\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL)]; } - //Session + /** + * End the current Session and logout the User + * + * @param bool $json_result Return data as JSON or Array + * @return mixed Returns Json status true or true + */ public static function logout($json_result = false){ self::startSession(); session_destroy(); return $json_result ? \SYSTEM\LOG\JsonResult::ok() : true;} - + + /** + * Save a key=>value into the current session(not preserved) + * + * @param string $key key for the given value + * @param mixed $value Value for the given Key to be saved + * @return null Returns null. + */ public static function save($key,$value){ self::startSession(); $_SESSION['values'][$key] = $value;} + /** + * Save the value of a key from the current session(not preserved) + * + * @param string $key key to be queried + * @return mixed Returns Value or null. + */ public static function load($key){ self::startSession(); if(!isset($_SESSION['values'][$key])){ return NULL;} return $_SESSION['values'][$key];} - + + /** + * Check if the current session is a logged in user + * + * @param bool $json_result Return data as JSON or Array + * @return mixed Returns json with status true or false or a bool. + */ public static function isLoggedIn($json_result = false){ self::startSession(); return (isset($_SESSION[\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL)]) && $_SESSION[\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL)] instanceof User) ? ($json_result ? \SYSTEM\LOG\JsonResult::ok() : true) : ($json_result ? \SYSTEM\LOG\JsonResult::fail() : false);} - + + /** + * State the Session for the current request + * + * @return null Returns null. + */ protected static function startSession(){ if(!isset($_SESSION) && !headers_sent()){ \session_start();}