-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathUserModel.php
More file actions
165 lines (130 loc) · 4.45 KB
/
UserModel.php
File metadata and controls
165 lines (130 loc) · 4.45 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
namespace App\User;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Foundation\Auth\Access\Authorizable;
class UserModel implements AuthenticatableContract, AuthorizableContract
{
use Authenticatable, Authorizable;
public $name;
public $password;
public $features;
public $profile_url;
public $google_login_url;
public $facebook_login_url;
public $forgot_password_url;
public $plans;
public $noindex;
public $intercom;
public $helpcrunch;
public function __construct()
{
/** @var {array} $options - Gets the old berta user from PHP file. */
/** @todo: Fix this, make user storage safer! */
include realpath(config('app.old_berta_root') . '/engine/config/inc.conf.php');
$this->name = $options['AUTH_user'];
$this->password = $options['AUTH_password'];
$this->profile_url = $this->getHostingData('HOSTING_PROFILE');
$this->google_login_url = $this->getHostingData('GOOGLE_LOGIN');
$this->facebook_login_url = $this->getHostingData('FACEBOOK_LOGIN');
$this->forgot_password_url = $this->getHostingData('FORGOTPASSWORD_LINK');
$this->plans = $this->getHostingData('PLANS');
$this->features = $this->getFeatures();
$this->noindex = $this->getHostingData('NOINDEX');
$this->intercom = $this->getIntercomData();
$this->helpcrunch = $this->getHelpcrunchData();
}
/**
* Get the name of the unique identifier for the user.
*
* @return string
*/
public function getAuthIdentifierName()
{
return 'name';
}
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->name;
}
public function getPlan()
{
$path = config('app.old_berta_root') . '/engine/plan';
if (! file_exists($path)) {
return null;
}
return intval(file_get_contents($path));
}
public function isBertaHosting()
{
return ! empty($this->profile_url);
}
private function getFeatures()
{
$features = [];
// Berta plans
// 1 - Basic
// 2 - Pro
// 3 - Shop
$plan = $this->getPlan();
$is_trial = $plan === null && $this->profile_url;
if (! $this->profile_url || $plan) {
$features[] = 'custom_javascript';
}
if ($is_trial || $plan > 1) {
$features[] = 'multisite';
$features[] = 'hide_berta_copyright';
}
if ($is_trial || $plan == 3) {
$features[] = 'shop';
}
return $features;
}
private function getHostingData($item)
{
$ENGINE_ROOT_PATH = realpath(config('app.old_berta_root') . '/engine') . '/';
include realpath(config('app.old_berta_root') . '/engine/inc.hosting.php');
if (! isset($options[$item])) {
return null;
}
return $options[$item];
}
private function getIntercomData()
{
$intercomAppId = $this->getHostingData('INTERCOM_APP_ID');
$intercomSecretKey = $this->getHostingData('INTERCOM_SECRET_KEY');
if (! $intercomAppId || ! $intercomSecretKey) {
return null;
}
$userHash = hash_hmac('sha256', $this->name, $intercomSecretKey);
return [
'appId' => $intercomAppId,
'userName' => $this->name,
'userHash' => $userHash,
];
}
private function getHelpcrunchData()
{
$helpcrunchApiOrganization = $this->getHostingData('HELPCRUNCH_API_ORGANIZATION');
$helpcrunchAppId = $this->getHostingData('HELPCRUNCH_APP_ID');
$helpcrunchApiKey = $this->getHostingData('HELPCRUNCH_API_KEY');
$uid = ! empty($_SESSION['_berta__user']['uid']) ? $_SESSION['_berta__user']['uid'] : null;
if (! $helpcrunchApiOrganization || ! $helpcrunchAppId || ! $helpcrunchApiKey || ! $uid) {
return null;
}
$security_hash = hash_hmac('sha256', $uid, $helpcrunchApiKey);
return [
'organization' => $helpcrunchApiOrganization,
'appId' => $helpcrunchAppId,
'user_id' => $uid,
'security_hash' => $security_hash,
'email' => $this->name,
];
}
}