Skip to content

Commit

Permalink
Testing documentation coverage updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Oct 15, 2016
1 parent 608aea5 commit 07811eb
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 36 deletions.
12 changes: 8 additions & 4 deletions dist/twist/Core/Utilities/Session.utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public function getSessionID(){
* Set and get the Twist session data
* Passing only a key will return the data stored against that key, pass in a value as well will set and return the result
* @note You can pass multidimensional keys separated by '/', but this will not be able to change an existing value from a non-array value to an array value
* @param $strKey The key for the item to be returned
* @param $mxdValue The value to be set against the provided key, passing null will not set any data
* @param string $strKey The key for the item to be returned
* @param null $mxdValue The value to be set against the provided key, passing null will not set any data
* @return mixed Return the data that is contained in the provided key (if any exists otherwise NULL)
*/
public function data($strKey,$mxdValue = null){
Expand All @@ -116,7 +116,7 @@ public function data($strKey,$mxdValue = null){
/**
* Null a value in the session array
* @note You can pass multidimensional keys separated by '/'
* @param $strKey The key for the item to be nulled
* @param string $strKey The key for the item to be nulled
* @return void
*/
public function nullData($strKey){
Expand All @@ -132,7 +132,7 @@ public function nullData($strKey){
/**
* Remove a single session item or clear the whole session by leaving the key field null
* @note You can pass multidimensional keys separated by '/'
* @param $strKey The key for the item to be removed, passing null removes all
* @param string $strKey The key for the item to be removed, passing null removes all
*/
public function delete($strKey = null){

Expand All @@ -152,6 +152,10 @@ public function remove($strKey = null){
$this->delete($strKey);
}

/**
* @param string $strReference
* @return mixed|null|string
*/
public function viewExtension($strReference){

$strData = '';
Expand Down
93 changes: 61 additions & 32 deletions dist/twist/Core/Utilities/User.utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function loggedInLevel(){
public function current(){

$arrAuthData = Auth::current();
if($this->resCurrentUser == null && $arrAuthData['status']){
if(is_null($this->resCurrentUser) && $arrAuthData['status']){
$this->resCurrentUser = $this->get($arrAuthData['user_id']);
}

Expand Down Expand Up @@ -128,7 +128,7 @@ public function authenticate($strEmailAddress = null,$strPassword = null,$blReme
$strPassword = (array_key_exists('password',$_POST) && !is_null($_POST['password'])) ? $_POST['password'] : null;
}

$blRememberMe = (is_null($blRememberMe)) ? ((array_key_exists('remember',$_POST) && $_POST['remember'] == '1') ? true : false) : $blRememberMe;
$blRememberMe = (is_null($blRememberMe)) ? ((array_key_exists('remember',$_POST) && $_POST['remember'] === '1') ? true : false) : $blRememberMe;

return Auth::login($strEmailAddress,$strPassword,$blRememberMe);
}
Expand All @@ -140,11 +140,13 @@ public function logout(){
return Auth::logout();
}

/**
* Get the pre-built, unbranded HTML registration form and return it as a string.
*/
/**
* Get the pre-built, unbranded HTML registration form and return it as a string.
* @param string $strLoginPage
* @return string
*/
public function getRegistrationForm($strLoginPage = ''){
return $this->viewExtension(($strLoginPage == '') ? 'registration_form' : sprintf('%s,%s','registration_form',$strLoginPage));
return $this->viewExtension(($strLoginPage === '') ? 'registration_form' : sprintf('%s,%s','registration_form',$strLoginPage));
}

/**
Expand All @@ -153,7 +155,7 @@ public function getRegistrationForm($strLoginPage = ''){
* @return mixed
*/
public function getLoginForm($strLoginPage = ''){
return $this->viewExtension(($strLoginPage == '') ? 'login_form' : sprintf('%s,%s','login_form',$strLoginPage));
return $this->viewExtension(($strLoginPage === '') ? 'login_form' : sprintf('%s,%s','login_form',$strLoginPage));
}

/**
Expand All @@ -162,7 +164,7 @@ public function getLoginForm($strLoginPage = ''){
* @return mixed
*/
public function getForgottenPasswordForm($strLoginPage = ''){
return $this->viewExtension(($strLoginPage == '') ? 'forgotten_password_form' : sprintf('%s,%s','forgotten_password_form',$strLoginPage));
return $this->viewExtension(($strLoginPage === '') ? 'forgotten_password_form' : sprintf('%s,%s','forgotten_password_form',$strLoginPage));
}

/**
Expand All @@ -171,7 +173,7 @@ public function getForgottenPasswordForm($strLoginPage = ''){
* @return mixed
*/
public function getChangePasswordForm($strLoginPage = ''){
return $this->viewExtension(($strLoginPage == '') ? 'change_password_form' : sprintf('%s,%s','change_password_form',$strLoginPage));
return $this->viewExtension(($strLoginPage === '') ? 'change_password_form' : sprintf('%s,%s','change_password_form',$strLoginPage));
}

public function afterLoginRedirect(){
Expand All @@ -197,17 +199,24 @@ public function afterLoginRedirect(){
//$this->goToPage( sprintf('%s?change',$this->strLoginUrl), false );
$this->goToPage( sprintf('%s%s?change',\Twist::Route()->current('registered_uri'),$this->strLoginUrl), false );
}
}elseif($objSession->data('user-temp_password') == '1' && !strstr($_SERVER['REQUEST_URI'],'?change')){
}elseif($objSession->data('user-temp_password') === '1' && !strstr($_SERVER['REQUEST_URI'],'?change')){
//$this->goToPage( '?change', false );
$this->goToPage( sprintf('%s%s?change',\Twist::Route()->current('registered_uri'),$this->strLoginUrl), false );
}
}

/**
* @param null $strRedirectURL
* @return mixed
*/
public function setAfterLoginRedirect($strRedirectURL = null){
$strRedirectURL = (is_null($strRedirectURL)) ? $_SERVER['REQUEST_URI'] : str_replace('//','/',$strRedirectURL);
return \Twist::Session()->data('site-login_redirect',$strRedirectURL);
}

/**
* @return mixed
*/
public function getAfterLoginRedirect(){
return \Twist::Session()->data('site-login_redirect');
}
Expand All @@ -218,7 +227,7 @@ public function clearAfterLoginRedirect(){

/**
* Redirect the user to a relevant page when required
* @param $strPageURI
* @param string $strPageURI
* @param bool $blReturnUserAfterLogin
*/
protected function goToPage($strPageURI, $blReturnUserAfterLogin = false){
Expand All @@ -235,7 +244,7 @@ protected function goToPage($strPageURI, $blReturnUserAfterLogin = false){

/**
* Get the user as an object
* @param $intUserID
* @param integer $intUserID
* @return \Twist\Core\Models\User\User
*/
public function get($intUserID){
Expand All @@ -252,7 +261,7 @@ public function create(){

/**
* Get an array of the users default information by User ID
* @param $intUserID
* @param integer $intUserID
* @return array
*/
public function getData($intUserID){
Expand All @@ -261,7 +270,7 @@ public function getData($intUserID){

/**
* Get and array of the users default information by User Email
* @param $strEmail
* @param string $strEmail
* @return array
*/
public function getByEmail($strEmail){
Expand All @@ -270,7 +279,7 @@ public function getByEmail($strEmail){

/**
* Get user full details by User ID
* @param $intUserID
* @param integer $intUserID
* @return array
*/
public function getDetailsByID($intUserID){
Expand All @@ -294,7 +303,7 @@ public function getDetailsByID($intUserID){

/**
* Get and array of the users default information by User ID
* @param $intUserID
* @param integer $intUserID
* @return array
*/
public function getAll($strOrderBy = 'id'){
Expand All @@ -303,7 +312,7 @@ public function getAll($strOrderBy = 'id'){

/**
* Get and array of the users default information by User ID
* @param $intUserID
* @param integer $intUserID
* @return array
*/
public function getAllByLevel($intLevelID){
Expand All @@ -312,7 +321,7 @@ public function getAllByLevel($intLevelID){

/**
* Get information about any given user level ID
* @param $intLevelID
* @param integer $intLevelID
* @return array
*/
public function getLevel($intLevelID){
Expand All @@ -321,12 +330,16 @@ public function getLevel($intLevelID){

/**
* Get all the levels in the system
* @return int
* @return array
*/
public function getLevels(){
return \Twist::Database()->records(TWIST_DATABASE_TABLE_PREFIX.'user_levels')->find();
}

/**
* @param $strVerificationCode
* @return bool
*/
public function verifyEmail($strVerificationCode){

$blOut = false;
Expand All @@ -337,7 +350,7 @@ public function verifyEmail($strVerificationCode){
$arrParts = explode('|',$strVerifyData);

//Check that the email address is semi valid and code is long enough
if(strstr($arrParts[0],'@') && strstr($arrParts[0],'.') && strlen($arrParts[1]) == 16){
if(strstr($arrParts[0],'@') && strstr($arrParts[0],'.') && strlen($arrParts[1]) === 16){

$resResult = \Twist::Database()->query("UPDATE `%s`.`%susers`
SET `verified` = '1',
Expand All @@ -363,12 +376,20 @@ public function verifyEmail($strVerificationCode){
return $blOut;
}

/**
* @param string $strData
* @return string
*/
protected function base64url_encode($strData) {
$strBase64 = base64_encode($strData);
$strBase64URL = strtr($strBase64, '+/=', '-_$');
return $strBase64URL;
}

/**
* @param string $strBase64URL
* @return string
*/
protected function base64url_decode($strBase64URL) {
$strBase64 = strtr($strBase64URL, '-_$', '+/=');
$strData = base64_decode($strBase64);
Expand All @@ -378,8 +399,8 @@ protected function base64url_decode($strBase64URL) {
/**
* Update the users password to a new password. THis is the non secure method for when you don't know the users original password.
* Default use would be for a forgotten password system etc.
* @param $intUserID
* @param $strNewPassword
* @param integer $intUserID
* @param string $strNewPassword
* @return bool
*/
public function updatePassword($intUserID,$strNewPassword){
Expand Down Expand Up @@ -408,17 +429,18 @@ public function updatePassword($intUserID,$strNewPassword){
/**
* Change password, this used when you have both the users old and new password, very useful to ensure the user who is changing
* the password is the valid account holder.
* @param $intUserID
* @param $strNewPassword
* @param $strCurrentPassword
* @param integer $intUserID
* @param string $strNewPassword
* @param string $strCurrentPassword
* @param bool $blRedirectOnFail
* @return bool
*/
public function changePassword($intUserID,$strNewPassword,$strCurrentPassword,$blRedirectOnFail=true){

$blPasswordChanged = false;
$resUser = $this->get($intUserID);

if($strNewPassword == $strCurrentPassword){
if($strNewPassword === $strCurrentPassword){
\Twist::Session()->data('site-error_message','Your new password must be different from your current password');
}else{
if($resUser->comparePasswordHash(sha1($strCurrentPassword))){
Expand All @@ -445,6 +467,9 @@ public function changePassword($intUserID,$strNewPassword,$strCurrentPassword,$b
return $blPasswordChanged;
}

/**
* @param string $strViewLocation
*/
public function setCustomTemplateLocation($strViewLocation){

if(!file_exists($strViewLocation)){
Expand All @@ -457,6 +482,10 @@ public function setCustomTemplateLocation($strViewLocation){
$this->strViewLocation = $strViewLocation;
}

/**
* @param string $strReference
* @return string
*/
public function viewExtension($strReference){

$strData = '';
Expand All @@ -471,7 +500,7 @@ public function viewExtension($strReference){
}

//If the user is on a temp password show the change password form
if(\Twist::Session()->data('user-temp_password') == '1' && $strReference == 'login_form'){
if(\Twist::Session()->data('user-temp_password') === '1' && $strReference === 'login_form'){
$strReference = 'change_password_form';
}

Expand All @@ -494,7 +523,7 @@ public function viewExtension($strReference){
case'login_form':

if($this->loggedIn()){
//\Twist::redirect(($strLoginPage == $_SERVER['REQUEST_URI']) ? './' : $strLoginPage);
//\Twist::redirect(($strLoginPage === $_SERVER['REQUEST_URI']) ? './' : $strLoginPage);
\Twist::redirect('./');
}else{

Expand Down Expand Up @@ -528,7 +557,7 @@ public function viewExtension($strReference){
);
\Twist::Session()->data('site-error_message',null);

if(\Twist::Session()->data('user-temp_password') == '0' || is_null(\Twist::Session()->data('user-temp_password'))){
if(\Twist::Session()->data('user-temp_password') === '0' || is_null(\Twist::Session()->data('user-temp_password'))){
$strData = $this->resView->build( $this->strViewLocation.'change-password.tpl', $arrTags );
}else{
$strData = $this->resView->build( $this->strViewLocation.'change-password-initial.tpl', $arrTags );
Expand Down Expand Up @@ -569,9 +598,9 @@ public function viewExtension($strReference){
$strDeviceList = '';
foreach($arrDevices as $arrEachDevice){

$arrEachDevice['current'] = ($arrCurrentDevices['id'] == $arrEachDevice['id']) ? true : false;
$arrEachDevice['current'] = ($arrCurrentDevices['id'] === $arrEachDevice['id']) ? true : false;

if(array_key_exists('edit-device',$_GET) && $arrEachDevice['device'] == $_GET['edit-device']){
if(array_key_exists('edit-device',$_GET) && $arrEachDevice['device'] === $_GET['edit-device']){
$strDeviceList .= $this->resView->build($this->strViewLocation.'device-each-edit.tpl',$arrEachDevice);
}else{
$strDeviceList .= $this->resView->build($this->strViewLocation.'device-each.tpl',$arrEachDevice);
Expand All @@ -597,7 +626,7 @@ public function viewExtension($strReference){
case'level_description':
$intUsersLevel = $this->loggedInData('level');

if($intUsersLevel == 0){
if($intUsersLevel === 0){
$strData = 'Root';
}else{
$arrLevelData = $this->getLevel($intUsersLevel);
Expand Down

0 comments on commit 07811eb

Please sign in to comment.