Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. <?php
  2. namespace Application\Models;
  3. require_once "Zend/Acl/Role/Interface.php";
  4. require_once "Zend/Acl/Resource/Interface.php";
  5. /**
  6.  * @Entity @Table(name="users") @HasLifeCycleCallbacks
  7.  */
  8. class User implements \Zend_Acl_Role_Interface, \Zend_Acl_Resource_Interface {
  9.     /**
  10.      * @Id @Column(type="integer")
  11.      * @GeneratedValue(strategy="AUTO")
  12.      */
  13.     protected $id;
  14.     /**
  15.      * @Column(type="string", length=30)
  16.      */
  17.     protected $name;
  18.     /**
  19.      * @Column(type="string", length=64)
  20.      */
  21.     protected $password;
  22.     /**
  23.      * @Column(type="string", length=64)
  24.      */
  25.     protected $salt;
  26.     /**
  27.      * @Column(type="string", length=64, nullable=true)
  28.      */
  29.     protected $email;
  30.     /**
  31.      * @Column(type="string", length=1000, nullable=true)
  32.      */
  33.     protected $bio;
  34.     /**
  35.      * @Column(type="date")
  36.      */
  37.     protected $joinDate;
  38.     /**
  39.      * @OneToMany(targetEntity="Post", mappedBy="user")
  40.      */
  41.     protected $posts;
  42.     /**
  43.      * @Column(type="string", length=12)
  44.      */
  45.     protected $role;
  46.    
  47.     function __get($name) {
  48.         return $this->$name;
  49.     }
  50.     function __set($name, $value) {
  51.         $this->$name = $value;
  52.     }
  53.     function __toArray() {
  54.         $arr = array();
  55.         $arr['id'] = $this->id;
  56.         $arr['name'] = $this->name;
  57.         $arr['email'] = $this->email;
  58.         $arr['bio'] = $this->bio;
  59.         return $arr;
  60.     }
  61.    
  62.     static function register($username, $password) {
  63.         $user = new User;
  64.         $user->name = $username;
  65.         $user->salt = hash('sha256', mt_rand());
  66.         $user->password = hash_hmac('sha256', $password, $user->salt);
  67.         return $user;
  68.     }
  69.    
  70.     // Zend_Acl_Role_Interface
  71.     function getRoleId() {
  72.         return $this->role;
  73.     }
  74.     // Zend_Acl_Resource_Interface
  75.     function getResourceId() {
  76.         return 'users';
  77.     }
  78.    
  79.     /**
  80.      * @PrePersist
  81.      */
  82.     function onPrePersist() {
  83.         $this->role = 'member';
  84.         $this->joinDate = date_create(date('Y-m-d'));
  85.     }
  86.    
  87.     function updateProfile($values = array()) {
  88.         $this->name = $values['name'];
  89.         $this->email = $values['email'];
  90.         $this->bio = $values['bio'];
  91.     }
  92.    
  93.     function changePassword($password) {
  94.         $this->salt = hash('sha256', mt_rand());
  95.         $this->password = hash_hmac('sha256', $password, $this->salt);
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement