-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.php
More file actions
141 lines (120 loc) · 2.75 KB
/
Copy pathUser.php
File metadata and controls
141 lines (120 loc) · 2.75 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php namespace Feather\Models;
use Str;
use Hash;
class User extends Base {
/**
* The table name.
*
* @var string
*/
public $table = 'users';
/**
* Timestamps are enabled.
*
* @var bool
*/
public $timestamps = true;
/**
* A user can have many and belong to many roles.
*
* @return object
*/
public function roles()
{
return $this->belongsToMany('Feather\\Core\\Role', 'user_roles', 'user_id', 'role_id');
}
/**
* When setting a password it must be hashed before stored in the database.
*
* @param string $password
* @return void
*/
public function setPassword($password)
{
$this->setAttribute('password', Hash::make($password));
}
/**
* Getter for a users slug.
*
* @return string
*/
public function getSlug()
{
return Str::slug($this->getAttribute('username'));
}
/**
* Getter for a users name.
*
* @return string
*/
public function getName()
{
return $this->getAttribute('username');
}
/**
* Getter for a users avatar URL, provided by Gravatar.
*
* @return string
*/
public function getAvatar()
{
return 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($this->getAttribute('email'))));
}
/**
* Register a new user and return the new user object.
*
* @param array $input
* @param bool $activated
* @return Feather\Core\User
*/
public static function register($input)
{
$user = new static(array(
'username' => $input['username'],
'password' => $input['password'],
'email' => $input['email']
));
if(Config::get('feather: db.registration.confirm_email'))
{
$user->fill(array(
'activation_key' => Str::random(30),
'activated' => 0
));
}
if(!$user->save())
{
throw new FeatherModelException;
}
// Attach the users role. If the user needs to confirm their e-mail address they are given
// the confirming role status which has an ID of 4. If not then they receive the standard
// member role which has an ID of 2.
$user->roles()->attach(Config::get('feather: db.registration.confirm_email') ? 4 : 2);
return $user;
}
public static function edit($user, $input)
{
}
/**
* Register a new user and associate it with an e-mail from an authenticator.
*
* @param array $associate
* @param array $input
* @return Feather\Core\User
*/
public static function associate($associate, $input)
{
$user = new static(array(
'username' => $input['username'],
'authenticator' => Config::get('feather: db.auth.driver'),
'authenticator_token' => $associate['token'],
'authenticator_associated_email' => $associate['email'],
'email' => $input['email']
));
if(!$user->save())
{
throw new FeatherModelException;
}
$user->roles()->attach(2);
return $user;
}
}