public function __construct()
 {
     parent::__construct();
     if (!DinklyUser::isLoggedIn() || !DinklyUser::isMemberOf('admin')) {
         $this->loadModule('admin', 'home', 'default', true);
         return false;
     }
 }
 public static function getByArrayOfIds($user_ids, $db = null)
 {
     $peer_object = new DinklyUser();
     if ($db == null) {
         $db = self::fetchDB();
     }
     $clean_ids = array();
     if (!is_array($user_ids)) {
         return false;
     }
     foreach ($user_ids as $id) {
         if (is_numeric($id)) {
             $clean_ids[] = $id;
         }
     }
     $query = $peer_object->getSelectQuery() . " where id in (" . implode(',', $clean_ids) . ")";
     return self::getCollection($peer_object, $query, $db);
 }
Example #3
0
 /**
  * Default Constructor
  *
  */
 public function __construct()
 {
     //Let's make this accessible across the admin for display of all dates
     $this->date_format = null;
     //We use this for the profile modal
     $this->logged_user = null;
     $this->db = DinklyDataConnector::fetchDB();
     if (DinklyUser::isLoggedIn()) {
         $this->logged_user = new DinklyUser();
         $this->logged_user->init(DinklyUser::getAuthSessionValue('logged_id'));
         $this->date_format = $this->date_format = $this->logged_user->getDateFormat() . ' ' . $this->logged_user->getTimeFormat();
         return false;
     } else {
         if (Dinkly::getCurrentModule() != 'login') {
             $this->loadModule('admin', 'login', 'default', true, true);
         }
     }
     return true;
 }
Example #4
0
>
          <a href="/admin/group/">Groups</a>
        </li>
        <?php 
}
?>
      </ul>
      <ul class="nav navbar-nav pull-right dinkly-admin-user-menu">
        <?php 
if (DinklyUser::isLoggedIn()) {
    ?>
        <li>
          <div class="btn-group">
            <button type="button" class="btn  btn-sm btn-primary dropdown-toggle" data-toggle="dropdown">
              <?php 
    echo DinklyUser::getLoggedUsername();
    ?>
 <span class="caret"></span>
            </button>
            <ul class="dropdown-menu pull-right" role="menu">
              <li><a href="/admin/profile">Edit Profile</a></li>
              <li role="presentation" class="divider"></li>
              <li><a href="/admin/login/logout/">Logout</a></li>
            </ul>
          </div>
        </li>
        <?php 
}
?>
      </ul>
    </div>
 /**
  * Load default view
  *
  * @return bool: always returns true on successful construction of view
  *
  */
 public function loadDefault()
 {
     $this->user = $this->logged_user;
     //Handle save
     if (isset($_POST['user-id'])) {
         $this->user->init($_POST['user-id']);
         //Make sure the submitted user matches the one logged in
         if ($_POST['user-id'] == DinklyUser::getLoggedId()) {
             $this->validateUserPost($_POST);
             if ($_POST['date-format'] == 'MM/DD/YY') {
                 $this->user->setDateFormat('m/d/y');
             } else {
                 if ($_POST['date-format'] == 'DD/MM/YY') {
                     $this->user->setDateFormat('d/m/y');
                 }
             }
             if ($_POST['time-format'] == '12') {
                 $this->user->setTimeFormat('g:i a');
             } else {
                 if ($_POST['time-format'] == '24') {
                     $this->user->setTimeFormat('H:i');
                 }
             }
             //If we have no errors, save the user
             if ($this->errors == array()) {
                 $this->user->save();
                 $this->logged_user = $this->user;
                 DinklyFlash::set('good_user_message', 'Profile Updated');
             }
         }
     }
     //Timezone dropdown (http://stackoverflow.com/a/7022536/53079)
     $utc = new DateTimeZone('UTC');
     $dt = new DateTime('now', $utc);
     $this->select_options = null;
     $timezone_identifiers = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'US');
     foreach ($timezone_identifiers as $tz) {
         $current_tz = new DateTimeZone($tz);
         $offset = $current_tz->getOffset($dt);
         $transition = $current_tz->getTransitions($dt->getTimestamp(), $dt->getTimestamp());
         $abbr = $transition[0]['abbr'];
         $selected = null;
         if ($this->user->getTimeZone() == $tz) {
             $selected = 'selected="selected"';
         }
         $this->select_options .= '<option ' . $selected . ' value="' . $tz . '">' . str_replace('_', ' ', $tz) . ' [' . $abbr . ' ' . DinklyUser::formatOffset($offset) . ']</option>';
     }
     return true;
 }
 /**
  * Logs out admin user and loads default module
  * 
  * @return bool: always returns false on successful log out
  */
 public function loadLogout()
 {
     DinklyUser::logout();
     $this->loadModule('admin', 'home', 'default', true);
     return false;
 }
Example #7
0
 /**
  * Verify with database the user credentials are correct and log in if so
  * 
  *
  * @param string $username: input username of user attempting to log in
  * @param string $input_password: input password of user attempting to log in
  * 
  * @return bool: true if correct credentials and logged on, false otherwise
  */
 public static function authenticate($username, $input_password)
 {
     $dbo = self::fetchDB();
     $sql = "select * from dinkly_user where username=" . $dbo->quote($username);
     $result = $dbo->query($sql)->fetchAll();
     //We found a match for the username
     if ($result != array()) {
         $user = new DinklyUser();
         $user->init($result[0]['id']);
         $hashed_password = $result[0]['password'];
         if (function_exists('password_verify')) {
             $valid_password = password_verify($input_password, $hashed_password) == $hashed_password;
         } else {
             $valid_password = crypt($input_password, $hashed_password) == $hashed_password;
         }
         if ($valid_password) {
             $count = $user->getLoginCount() + 1;
             $user->setLastLoginAt(date('Y-m-d G:i:s'));
             $user->setLoginCount($count);
             $user->save();
             self::setLoggedIn(true, $result[0]['id'], $result[0]['username'], $user->getGroups());
             return true;
         }
     }
     return false;
 }