PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/server/application/modules/admin/models/Users.php

http://display-ui.googlecode.com/
PHP | 83 lines | 52 code | 0 blank | 31 comment | 5 complexity | c2bf725cbafb2e1a4917394540c47efa MD5 | raw file
  1. <?php
  2. /**
  3. * Users model for control panel
  4. *
  5. * Copyright 2011 Frederick Ding<br />
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. *
  9. * You may obtain a copy of the License at
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. * or the full licensing terms for this project at
  12. * http://code.google.com/p/display-ui/wiki/License
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * @author Frederick
  21. * @license http://code.google.com/p/display-ui/wiki/License Apache License 2.0
  22. * @version $Id: Users.php 448 2011-06-24 22:23:22Z Frederick $
  23. */
  24. /**
  25. * Provides logic and data for managing users
  26. */
  27. class Admin_Model_Users extends Default_Model_DatabaseAbstract
  28. {
  29. /**
  30. * Retrieves an associative array of all users.
  31. *
  32. * @return array an array of clients
  33. */
  34. public function fetchUsers ()
  35. {
  36. if (! is_null($this->db)) {
  37. $select = $this->db->select()
  38. ->from(array(
  39. 'u' => 'dui_users'),
  40. array(
  41. 'id',
  42. 'username',
  43. 'email',
  44. 'last_active',
  45. 'acl_role',
  46. 'has_yubikey' => new Zend_Db_Expr('yubikey_public IS NOT NULL')))
  47. ->order('id ASC');
  48. $result = $select->query()->fetchAll(Zend_Db::FETCH_ASSOC);
  49. // error_log($select->assemble());
  50. return $result;
  51. }
  52. return array();
  53. }
  54. public function insertUser ($_username, $_password, $_email, $_acl_role,
  55. $_yubikey)
  56. {
  57. if(is_null($this->db))
  58. return false;
  59. $PasswordHash = new Default_Model_PasswordHash(8, false);
  60. $data = array(
  61. 'username' => $_username,
  62. 'password' => $PasswordHash->HashPassword($_password),
  63. 'email' => $_email,
  64. 'last_active' => new Zend_Db_Expr('UTC_TIMESTAMP()'),
  65. 'acl_role' => $_acl_role
  66. );
  67. if(isset($_yubikey) && strlen($_yubikey) >= 12) {
  68. $data['yubikey_public'] = substr($_yubikey, 0, 12);
  69. }
  70. $insert = $this->db->insert('dui_users', $data);
  71. return $insert;
  72. }
  73. public function deleteUser ($_id)
  74. {
  75. $_id = (int) $_id;
  76. if (! is_null($this->db)) {
  77. $result = $this->db->delete('dui_users',
  78. $this->db->quoteInto('id = ?', $_id, 'INTEGER'));
  79. return (bool) $result;
  80. }
  81. return FALSE;
  82. }
  83. }