Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Application\Models;
- require_once "Zend/Acl/Role/Interface.php";
- require_once "Zend/Acl/Resource/Interface.php";
- /**
- * @Entity @Table(name="users") @HasLifeCycleCallbacks
- */
- class User implements \Zend_Acl_Role_Interface, \Zend_Acl_Resource_Interface {
- /**
- * @Id @Column(type="integer")
- * @GeneratedValue(strategy="AUTO")
- */
- protected $id;
- /**
- * @Column(type="string", length=30)
- */
- protected $name;
- /**
- * @Column(type="string", length=64)
- */
- protected $password;
- /**
- * @Column(type="string", length=64)
- */
- protected $salt;
- /**
- * @Column(type="string", length=64, nullable=true)
- */
- protected $email;
- /**
- * @Column(type="string", length=1000, nullable=true)
- */
- protected $bio;
- /**
- * @Column(type="date")
- */
- protected $joinDate;
- /**
- * @OneToMany(targetEntity="Post", mappedBy="user")
- */
- protected $posts;
- /**
- * @Column(type="string", length=12)
- */
- protected $role;
- function __get($name) {
- return $this->$name;
- }
- function __set($name, $value) {
- $this->$name = $value;
- }
- function __toArray() {
- $arr = array();
- $arr['id'] = $this->id;
- $arr['name'] = $this->name;
- $arr['email'] = $this->email;
- $arr['bio'] = $this->bio;
- return $arr;
- }
- static function register($username, $password) {
- $user = new User;
- $user->name = $username;
- $user->salt = hash('sha256', mt_rand());
- $user->password = hash_hmac('sha256', $password, $user->salt);
- return $user;
- }
- // Zend_Acl_Role_Interface
- function getRoleId() {
- return $this->role;
- }
- // Zend_Acl_Resource_Interface
- function getResourceId() {
- return 'users';
- }
- /**
- * @PrePersist
- */
- function onPrePersist() {
- $this->role = 'member';
- $this->joinDate = date_create(date('Y-m-d'));
- }
- function updateProfile($values = array()) {
- $this->name = $values['name'];
- $this->email = $values['email'];
- $this->bio = $values['bio'];
- }
- function changePassword($password) {
- $this->salt = hash('sha256', mt_rand());
- $this->password = hash_hmac('sha256', $password, $this->salt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement