示例#1
0
 /**
  * Checks if the entered captcha is the same like the one from the rendered image which has been saved in session
  * @param $captcha string The captcha characters
  * @return bool success of captcha check
  */
 public static function checkCaptcha($captcha)
 {
     if ($captcha == Session::get('captcha')) {
         return true;
     }
     return false;
 }
示例#2
0
 /**
  * Kicks the selected user out of the system instantly by resetting the user's session.
  * This means, the user will be "logged out".
  *
  * @param $userId
  * @return bool
  */
 private static function resetUserSession($userId)
 {
     $database = DatabaseFactory::getFactory()->getConnection();
     $query = $database->prepare("UPDATE users SET session_id = :session_id  WHERE user_id = :user_id LIMIT 1");
     $query->execute(array(':session_id' => null, ':user_id' => $userId));
     if ($query->rowCount() == 1) {
         Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_USER_SUCCESSFULLY_KICKED'));
         return true;
     }
 }
示例#3
0
 /**
  * Writes the new account type marker to the database and to the session
  *
  * @param $type
  *
  * @return bool
  */
 public static function saveRoleToDatabase($type)
 {
     // if $type is not 1 or 2
     if (!in_array($type, [1, 2])) {
         return false;
     }
     $database = DatabaseFactory::getFactory()->getConnection();
     $query = $database->prepare("UPDATE users SET user_account_type = :new_type WHERE user_id = :user_id LIMIT 1");
     $query->execute(array(':new_type' => $type, ':user_id' => Session::get('user_id')));
     if ($query->rowCount() == 1) {
         // set account type in session
         Session::set('user_account_type', $type);
         return true;
     }
     return false;
 }
示例#4
0
 /**
  * Removes the avatar image file from the filesystem
  *
  * @param integer $userId
  * @return bool
  */
 public static function deleteAvatarImageFile($userId)
 {
     // Check if file exists
     if (!file_exists(Config::get('PATH_AVATARS') . $userId . ".jpg")) {
         Session::add("feedback_negative", Text::get("FEEDBACK_AVATAR_IMAGE_DELETE_NO_FILE"));
         return false;
     }
     // Delete avatar file
     if (!unlink(Config::get('PATH_AVATARS') . $userId . ".jpg")) {
         Session::add("feedback_negative", Text::get("FEEDBACK_AVATAR_IMAGE_DELETE_FAILED"));
         return false;
     }
     return true;
 }
示例#5
0
 /**
  * Returns the current state of the user's login
  *
  * @return bool user's login status
  */
 public static function isUserLoggedIn()
 {
     return Session::userIsLoggedIn();
 }
示例#6
0
 /**
  * Password Change Action
  * Submit form, if retured positive redirect to index, otherwise show the changePassword page again
  */
 public function changePassword_action()
 {
     $result = PasswordResetModel::changePassword(Session::get('user_name'), Request::post('user_password_current'), Request::post('user_password_new'), Request::post('user_password_repeat'));
     if ($result) {
         Redirect::to('user/index');
     } else {
         Redirect::to('user/changePassword');
     }
 }
示例#7
0
<?php

use Huge\Core\Session;
// get the feedback (they are arrays, to make multiple positive/negative messages possible)
$feedback_positive = Session::get('feedback_positive');
$feedback_negative = Session::get('feedback_negative');
// echo out positive messages
if (isset($feedback_positive)) {
    foreach ($feedback_positive as $feedback) {
        echo '<div class="feedback success">' . $feedback . '</div>';
    }
}
// echo out negative messages
if (isset($feedback_negative)) {
    foreach ($feedback_negative as $feedback) {
        echo '<div class="feedback error">' . $feedback . '</div>';
    }
}
示例#8
0
                    </li>
                    <li <?php 
    if (View::checkForActiveController($filename, "login")) {
        echo ' class="active" ';
    }
    ?>
 >
                        <a href="<?php 
    echo Config::get('URL');
    ?>
login/logout">Logout</a>
                    </li>
                </ul>
            </li>
            <?php 
    if (Session::get("user_account_type") == 7) {
        ?>
                <li <?php 
        if (View::checkForActiveController($filename, "admin")) {
            echo ' class="active" ';
        }
        ?>
 >
                    <a href="<?php 
        echo Config::get('URL');
        ?>
admin/">Admin</a>
                </li>
            <?php 
    }
    ?>
示例#9
0
 /**
  * Delete a specific note
  * @param int $note_id id of the note
  * @return bool feedback (was the note deleted properly ?)
  */
 public static function deleteNote($note_id)
 {
     if (!$note_id) {
         return false;
     }
     $database = DatabaseFactory::getFactory()->getConnection();
     $sql = "DELETE FROM notes WHERE note_id = :note_id AND user_id = :user_id LIMIT 1";
     $query = $database->prepare($sql);
     $query->execute(array(':note_id' => $note_id, ':user_id' => Session::get('user_id')));
     if ($query->rowCount() == 1) {
         return true;
     }
     // default return
     Session::add('feedback_negative', Text::get('FEEDBACK_NOTE_DELETION_FAILED'));
     return false;
 }
示例#10
0
 /**
  * Edit the user's email
  *
  * @param $new_user_email
  *
  * @return bool success status
  */
 public static function editUserEmail($new_user_email)
 {
     // email provided ?
     if (empty($new_user_email)) {
         Session::add('feedback_negative', Text::get('FEEDBACK_EMAIL_FIELD_EMPTY'));
         return false;
     }
     // check if new email is same like the old one
     if ($new_user_email == Session::get('user_email')) {
         Session::add('feedback_negative', Text::get('FEEDBACK_EMAIL_SAME_AS_OLD_ONE'));
         return false;
     }
     // user's email must be in valid email format, also checks the length
     // @see http://stackoverflow.com/questions/21631366/php-filter-validate-email-max-length
     // @see http://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address
     if (!filter_var($new_user_email, FILTER_VALIDATE_EMAIL)) {
         Session::add('feedback_negative', Text::get('FEEDBACK_EMAIL_DOES_NOT_FIT_PATTERN'));
         return false;
     }
     // strip tags, just to be sure
     $new_user_email = substr(strip_tags($new_user_email), 0, 254);
     // check if user's email already exists
     if (self::doesEmailAlreadyExist($new_user_email)) {
         Session::add('feedback_negative', Text::get('FEEDBACK_USER_EMAIL_ALREADY_TAKEN'));
         return false;
     }
     // write to database, if successful ...
     // ... then write new email to session, Gravatar too (as this relies to the user's email address)
     if (self::saveNewEmailAddress(Session::get('user_id'), $new_user_email)) {
         Session::set('user_email', $new_user_email);
         Session::set('user_gravatar_image_url', AvatarModel::getGravatarLinkByEmail($new_user_email));
         Session::add('feedback_positive', Text::get('FEEDBACK_EMAIL_CHANGE_SUCCESSFUL'));
         return true;
     }
     Session::add('feedback_negative', Text::get('FEEDBACK_UNKNOWN_ERROR'));
     return false;
 }
示例#11
0
        </p>
	    <p>
		    Please note: This whole process has been renamed from AccountType (v3.0) to UserRole (v3.1).
	    </p>

        <h2>Currently your account type is: <?php 
echo Session::get('user_account_type');
?>
</h2>
        <!-- basic implementation for two account types: type 1 and type 2 -->
	    <form action="<?php 
echo Config::get('URL');
?>
user/changeUserRole_action" method="post">
            <?php 
if (Session::get('user_account_type') == 1) {
    ?>
                <input type="submit" name="user_account_upgrade" value="Upgrade my account (to Premium User)" />
	        <?php 
} else {
    if (Session::get('user_account_type') == 2) {
        ?>
	            <input type="submit" name="user_account_downgrade" value="Downgrade my account (to Basic User)" />
	        <?php 
    }
}
?>
	    </form>
    </div>
</div>
 /**
  * Validates current and new passwords
  *
  * @param string $user_name
  * @param string $user_password_current
  * @param string $user_password_new
  * @param string $user_password_repeat
  *
  * @return bool
  */
 public static function validatePasswordChange($user_name, $user_password_current, $user_password_new, $user_password_repeat)
 {
     $database = DatabaseFactory::getFactory()->getConnection();
     $sql = "SELECT user_password_hash, user_failed_logins FROM users WHERE user_name = :user_name LIMIT 1;";
     $query = $database->prepare($sql);
     $query->execute(array(':user_name' => $user_name));
     $user = $query->fetch();
     if ($query->rowCount() == 1) {
         $user_password_hash = $user->user_password_hash;
     } else {
         Session::add('feedback_negative', Text::get('FEEDBACK_USER_DOES_NOT_EXIST'));
         return false;
     }
     if (!password_verify($user_password_current, $user_password_hash)) {
         Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_CURRENT_INCORRECT'));
         return false;
     } else {
         if (empty($user_password_new) || empty($user_password_repeat)) {
             Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_FIELD_EMPTY'));
             return false;
         } else {
             if ($user_password_new !== $user_password_repeat) {
                 Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_REPEAT_WRONG'));
                 return false;
             } else {
                 if (strlen($user_password_new) < 6) {
                     Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_TOO_SHORT'));
                     return false;
                 } else {
                     if ($user_password_current == $user_password_new) {
                         Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_NEW_SAME_AS_CURRENT'));
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }
 /**
  * checks the email/verification code combination and set the user's activation status to true in the database
  *
  * @param int $user_id user id
  * @param string $user_activation_verification_code verification token
  *
  * @return bool success status
  */
 public static function verifyNewUser($user_id, $user_activation_verification_code)
 {
     $database = DatabaseFactory::getFactory()->getConnection();
     $sql = "UPDATE users SET user_active = 1, user_activation_hash = NULL\n                WHERE user_id = :user_id AND user_activation_hash = :user_activation_hash LIMIT 1";
     $query = $database->prepare($sql);
     $query->execute(array(':user_id' => $user_id, ':user_activation_hash' => $user_activation_verification_code));
     if ($query->rowCount() == 1) {
         Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_ACTIVATION_SUCCESSFUL'));
         return true;
     }
     Session::add('feedback_negative', Text::get('FEEDBACK_ACCOUNT_ACTIVATION_FAILED'));
     return false;
 }