This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscamstop.php
85 lines (72 loc) · 2.02 KB
/
scamstop.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
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class ScamStop extends Module
{
private $moduleLogFile = _PS_MODULE_DIR_.'scamstop/log';
public function __construct()
{
$this->name = 'scamstop';
$this->tab = 'administration';
$this->version = '1.0';
$this->author = 'Christopher Morton';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
parent::__construct();
$this->displayName = $this->l('ScamStop');
$this->description = $this->l('Stops URLs from being added in customer names');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
}
/**
* Install.
*
* @return bool
*/
public function install()
{
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
if (parent::install()
&& $this->registerHook('actionBeforeSubmitAccount')
) {
return true;
}
return false;
}
/**
* Uninstall.
*
* @return bool
*/
public function uninstall()
{
if (parent::uninstall()) {
return true;
}
return false;
}
public function hookActionBeforeSubmitAccount()
{
$firstname = Tools::getValue('customer_firstname');
$lastname = Tools::getValue('customer_lastname');
if ($this->isUrl($firstname) || $this->isUrl($lastname)) {
$logData = date(DATE_ISO8601)." REJECTED: $firstname $lastname\n";
file_put_contents($this->moduleLogFile, $logData, FILE_APPEND);
$this->context->controller->errors[] =
Tools::displayError('Invalid account credentials');
}
}
/**
* Is Url.
*
* @return bool
*/
private function isUrl($input)
{
$regex =
'/^(https?:\/\/)?[$~:;#,%&_=\(\)\[\]\.\? \+\-@\/a-zA-Z0-9]+\..+/';
return preg_match($regex, $input);
}
}