/
User.php
118 lines (99 loc) · 3.3 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace Models;
use Models\Base\User as BaseUser;
use Propel\Runtime\Connection\ConnectionInterface;
use Models\Map\UserTableMap;
use Models\UserGroup as ChildUserGroup;
use Models\UserGroupQuery as ChildUserGroupQuery;
use Models\Pack as ChildPack;
use Models\PackQuery as ChildPackQuery;
use Models\PackPermission as ChildPackPermission;
use Models\PackPermissionQuery as ChildPackPermissionQuery;
/**
* Skeleton subclass for representing a row from the 'user' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class User extends BaseUser
{
public function preSave(ConnectionInterface $con = null){
if($this->validate()){
$this->hashPassword();
$this->hashEmailConfirmToken();
$this->hashAccountRestoreToken();
$this->hashPasswordResetToken();
}
return $this->validate();
}
public function setPassword($v){
if ($v !== null) {
$v = (string) $v;
}
if($this->password !== $v){
$identities = $this->getIdentities();
foreach($identities as $identity){
$identity->delete();
}
$this->password = $v;
$this->modifiedColumns[UserTableMap::COL_PASSWORD] = true;
}
return $this;
}
public function hashPassword(){
$this->password = password_hash($this->password, PASSWORD_DEFAULT);
}
public function checkPassword($password){
return password_verify($password, $this->password);
}
public function hashEmailConfirmToken(){
$this->email_confirm_token = password_hash($this->email_confirm_token, PASSWORD_DEFAULT);
}
public function checkEmailConfirmToken($token){
return password_verify($token, $this->email_confirm_token);
}
public function hashAccountRestoreToken(){
$this->account_restore_token = password_hash($this->account_restore_token, PASSWORD_DEFAULT);
}
public function checkAccountRestoreToken($token){
return password_verify($token, $this->account_restore_token);
}
public function hashPasswordResetToken(){
$this->password_reset_token = password_hash($this->password_reset_token, PASSWORD_DEFAULT);
}
public function checkPasswordResetToken($token){
return password_verify($token, $this->password_reset_token);
}
public function getAvatar250(){
$dir = "Includes/images/avatars/250x250/";
return "/".$dir.(file_exists($dir.$this->avatar_path) && is_file($dir.$this->avatar_path) ? $this->avatar_path : "default.png");
}
public function getAvatar40(){
$dir = "Includes/images/avatars/40x40/";
return "/".$dir.(file_exists($dir.$this->avatar_path) && is_file($dir.$this->avatar_path) ? $this->avatar_path : "default.png");
}
public function getAddedToGroup($group, $format){
$timestamp = ChildUserGroupQuery::create()->filterByUser($this)->filterByGroup($group)->findOne()->getCreatedAt($format);
return $timestamp;
}
public function getPublicPacks(){
$packs = ChildPackQuery::create()->filterByOwner($this)->filterByPrivate(0)->find();
return $packs;
}
public function getForeignPacks(){
$packs = ChildPackQuery::create()
->select(array("pack.name", "user.username", "pack.id", "pack_permission.value"))
->useOwnerQuery()
->select("user.username")
->endUse()
->usePackPermissionQuery()
->filterByUser($this)
->endUse()
->find();
return $packs;
}
}