Skip to content
Next
Projects
Groups
Snippets
Help
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
295
Merge Requests
45
CI / CD
Security & Compliance
Packages
Wiki
Snippets
Members
Collapse sidebar
Close sidebar
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Compare Revisions
826fbcf7fc8604fab5bc3995ee263bb3de5e3c6a...c3a7551ec394d58e17e50c23f76bb14bf3d922f9
Source
c3a7551ec394d58e17e50c23f76bb14bf3d922f9
...
Target
826fbcf7fc8604fab5bc3995ee263bb3de5e3c6a
Compare
Commits (2)
(feat): Domain validation
· c340b657
Emiliano Balbuena
authored
41 minutes ago
c340b657
Merge branch 'feat/pro-domain-check-e977' into 'master'
· c3a7551e
Mark Harding
authored
41 minutes ago
(feat): Domain validation Closes
#977
See merge request
!387
c3a7551e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
210 additions
and
0 deletions
+210
-0
Controllers/api/v2/pro/settings.php
View file @
c3a7551e
...
...
@@ -8,6 +8,7 @@ namespace Minds\Controllers\api\v2\pro;
use
Exception
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Pro\Domain
as
ProDomain
;
use
Minds\Core\Pro\Manager
;
use
Minds\Core\Session
;
use
Minds\Entities\User
;
...
...
@@ -81,6 +82,18 @@ class settings implements Interfaces\Api
]);
}
if
(
isset
(
$_POST
[
'domain'
]))
{
/** @var ProDomain $proDomain */
$proDomain
=
Di
::
_
()
->
get
(
'Pro\Domain'
);
if
(
!
$proDomain
->
isAvailable
(
$_POST
[
'domain'
],
(
string
)
$user
->
guid
))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'This domain is taken'
,
]);
}
}
try
{
$success
=
$manager
->
set
(
$_POST
);
...
...
This diff is collapsed.
Controllers/api/v2/pro/settings/domain.php
0 → 100644
View file @
c3a7551e
<?php
/**
* domain
* @author edgebal
*/
namespace
Minds\Controllers\api\v2\pro\settings
;
use
Exception
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Pro\Domain
as
ProDomain
;
use
Minds\Core\Session
;
use
Minds\Entities\User
;
use
Minds\Interfaces
;
use
Minds\Api\Factory
;
class
domain
implements
Interfaces\Api
{
/**
* Equivalent to HTTP GET method
* @param array $pages
* @return mixed|null
* @throws Exception
*/
public
function
get
(
$pages
)
{
$user
=
Session
::
getLoggedinUser
();
if
(
isset
(
$pages
[
0
])
&&
$pages
[
0
])
{
if
(
!
Session
::
isAdmin
())
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'You are not authorized'
,
]);
}
$user
=
new
User
(
$pages
[
0
]);
}
/** @var ProDomain $proDomain */
$proDomain
=
Di
::
_
()
->
get
(
'Pro\Domain'
);
return
Factory
::
response
([
'isValid'
=>
$proDomain
->
isAvailable
(
$_GET
[
'domain'
],
(
string
)
$user
->
guid
)
]);
}
/**
* Equivalent to HTTP POST method
* @param array $pages
* @return mixed|null
*/
public
function
post
(
$pages
)
{
return
Factory
::
response
([]);
}
/**
* Equivalent to HTTP PUT method
* @param array $pages
* @return mixed|null
*/
public
function
put
(
$pages
)
{
return
Factory
::
response
([]);
}
/**
* Equivalent to HTTP DELETE method
* @param array $pages
* @return mixed|null
*/
public
function
delete
(
$pages
)
{
return
Factory
::
response
([]);
}
}
This diff is collapsed.
Core/Pro/Domain.php
View file @
c3a7551e
...
...
@@ -9,6 +9,7 @@ namespace Minds\Core\Pro;
use
Exception
;
use
Minds\Core\Config
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Util\StringValidator
;
use
Minds\Entities\User
;
class
Domain
...
...
@@ -49,6 +50,27 @@ class Domain
])
->
first
();
}
/**
* @param string $domain
* @param string $userGuid
* @return bool|null
*/
public
function
isAvailable
(
string
$domain
,
string
$userGuid
)
:
?
bool
{
$rootDomains
=
$this
->
config
->
get
(
'pro'
)[
'root_domains'
]
??
[];
if
(
in_array
(
strtolower
(
$domain
),
$rootDomains
,
true
))
{
return
false
;
}
if
(
!
StringValidator
::
isDomain
(
$domain
))
{
return
null
;
}
$settings
=
$this
->
lookup
(
$domain
);
return
!
$settings
||
((
string
)
$settings
->
getUserGuid
()
===
$userGuid
);
}
/**
* @param Settings $settings
* @param User|null $owner
...
...
This diff is collapsed.
Spec/Core/Pro/DomainSpec.php
View file @
c3a7551e
...
...
@@ -75,6 +75,104 @@ class DomainSpec extends ObjectBehavior
->
shouldReturn
(
null
);
}
public
function
it_should_check_if_domain_is_unavailable
(
Response
$getListResponse
,
Settings
$settings
)
{
$this
->
config
->
get
(
'pro'
)
->
shouldBeCalled
()
->
willReturn
([
'root_domains'
=>
[
'phpspec.test'
]
]);
$this
->
repository
->
getList
([
'domain'
=>
'phpspec-test.com'
])
->
shouldBeCalled
()
->
willReturn
(
$getListResponse
);
$getListResponse
->
first
()
->
shouldBeCalled
()
->
willReturn
(
$settings
);
$settings
->
getUserGuid
()
->
shouldBeCalled
()
->
willReturn
(
1001
);
$this
->
isAvailable
(
'phpspec-test.com'
,
1000
)
->
shouldReturn
(
false
);
}
public
function
it_should_check_if_domain_is_available_if_same_owner
(
Response
$getListResponse
,
Settings
$settings
)
{
$this
->
config
->
get
(
'pro'
)
->
shouldBeCalled
()
->
willReturn
([
'root_domains'
=>
[
'phpspec.test'
]
]);
$this
->
repository
->
getList
([
'domain'
=>
'phpspec-test.com'
])
->
shouldBeCalled
()
->
willReturn
(
$getListResponse
);
$getListResponse
->
first
()
->
shouldBeCalled
()
->
willReturn
(
$settings
);
$settings
->
getUserGuid
()
->
shouldBeCalled
()
->
willReturn
(
1000
);
$this
->
isAvailable
(
'phpspec-test.com'
,
1000
)
->
shouldReturn
(
true
);
}
public
function
it_should_check_if_domain_is_available
(
Response
$getListResponse
)
{
$this
->
config
->
get
(
'pro'
)
->
shouldBeCalled
()
->
willReturn
([
'root_domains'
=>
[
'phpspec.test'
]
]);
$this
->
repository
->
getList
([
'domain'
=>
'phpspec-test.com'
])
->
shouldBeCalled
()
->
willReturn
(
$getListResponse
);
$getListResponse
->
first
()
->
shouldBeCalled
()
->
willReturn
(
null
);
$this
->
isAvailable
(
'phpspec-test.com'
,
1000
)
->
shouldReturn
(
true
);
}
public
function
it_should_return_as_unavailable_if_root_domain
()
{
$this
->
config
->
get
(
'pro'
)
->
shouldBeCalled
()
->
willReturn
([
'root_domains'
=>
[
'phpspec.test'
]
]);
$this
->
repository
->
getList
(
Argument
::
cetera
())
->
shouldNotBeCalled
();
$this
->
isAvailable
(
'phpspec.test'
,
1000
)
->
shouldReturn
(
false
);
}
public
function
it_should_get_icon
(
Settings
$settings
,
User
$owner
...
...
This diff is collapsed.