/modules/base/entities/user.php

https://github.com/sseshachala/Open-Web-Analytics · PHP · 96 lines · 54 code · 15 blank · 27 comment · 1 complexity · cd8b1777494ca8c8e3e127827e956916 MD5 · raw file

  1. <?php
  2. //
  3. // Open Web Analytics - An Open Source Web Analytics Framework
  4. //
  5. // Copyright 2006 Peter Adams. All rights reserved.
  6. //
  7. // Licensed under GPL v2.0 http://www.gnu.org/copyleft/gpl.html
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // $Id$
  16. //
  17. /**
  18. * User Entity
  19. *
  20. * @author Peter Adams <peter@openwebanalytics.com>
  21. * @copyright Copyright &copy; 2006 Peter Adams <peter@openwebanalytics.com>
  22. * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0
  23. * @category owa
  24. * @package owa
  25. * @version $Revision$
  26. * @since owa 1.0.0
  27. */
  28. class owa_user extends owa_entity {
  29. function __construct() {
  30. $this->setTableName('user');
  31. $this->setCachable();
  32. // properties
  33. $this->properties['id'] = new owa_dbColumn;
  34. $this->properties['id']->setDataType(OWA_DTD_SERIAL);
  35. $this->properties['id']->setAutoIncrement();
  36. $this->properties['user_id'] = new owa_dbColumn;
  37. $this->properties['user_id']->setDataType(OWA_DTD_VARCHAR255);
  38. $this->properties['user_id']->setPrimaryKey();
  39. $this->properties['password'] = new owa_dbColumn;
  40. $this->properties['password']->setDataType(OWA_DTD_VARCHAR255);
  41. $this->properties['role'] = new owa_dbColumn;
  42. $this->properties['role']->setDataType(OWA_DTD_VARCHAR255);
  43. $this->properties['real_name'] = new owa_dbColumn;
  44. $this->properties['real_name']->setDataType(OWA_DTD_VARCHAR255);
  45. $this->properties['email_address'] = new owa_dbColumn;
  46. $this->properties['email_address']->setDataType(OWA_DTD_VARCHAR255);
  47. $this->properties['temp_passkey'] = new owa_dbColumn;
  48. $this->properties['temp_passkey']->setDataType(OWA_DTD_VARCHAR255);
  49. $this->properties['creation_date'] = new owa_dbColumn;
  50. $this->properties['creation_date']->setDataType(OWA_DTD_BIGINT);
  51. $this->properties['last_update_date'] = new owa_dbColumn;
  52. $this->properties['last_update_date']->setDataType(OWA_DTD_BIGINT);
  53. $apiKey = new owa_dbColumn;
  54. $apiKey->setName('api_key');
  55. $apiKey->setDataType(OWA_DTD_VARCHAR255);
  56. $this->setProperty($apiKey);
  57. }
  58. function createNewUser($user_id, $role, $password = '', $email_address = '', $real_name = '') {
  59. if (!$password) {
  60. $password = $this->generateRandomPassword();
  61. }
  62. $this->set('user_id', $user_id);
  63. $this->set('role', $role);
  64. $this->set('real_name', $real_name);
  65. $this->set('email_address', $email_address);
  66. $this->set('temp_passkey', $this->generateTempPasskey($user_id));
  67. $this->set('password', owa_lib::encryptPassword($password));
  68. $this->set('creation_date', time());
  69. $this->set('last_update_date', time());
  70. $this->set('api_key', $this->generateTempPasskey($user_id));
  71. $ret = $this->create();
  72. return $ret;
  73. }
  74. function generateTempPasskey($seed) {
  75. return md5($seed.time().rand());
  76. }
  77. function generateRandomPassword() {
  78. return substr(owa_lib::encryptPassword(microtime()),0,6);
  79. }
  80. }
  81. ?>