|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Vanillaforums plugin for Craft CMS 3.x |
|
4
|
|
|
* |
|
5
|
|
|
* Single Sign On plugin for VanillaForums/jsConnect and CraftCMS |
|
6
|
|
|
* |
|
7
|
|
|
* @link https://nystudio107.com/ |
|
8
|
|
|
* @copyright Copyright (c) 2019 nystudio107 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace nystudio107\vanillaforums\models; |
|
12
|
|
|
|
|
13
|
|
|
use nystudio107\vanillaforums\Vanillaforums; |
|
14
|
|
|
|
|
15
|
|
|
use craft\base\Model; |
|
16
|
|
|
use craft\behaviors\EnvAttributeParserBehavior; |
|
17
|
|
|
|
|
18
|
|
|
use yii\behaviors\AttributeTypecastBehavior; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author nystudio107 |
|
22
|
|
|
* @package Vanillaforums |
|
23
|
|
|
* @since 3.0.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
class Settings extends Model |
|
26
|
|
|
{ |
|
27
|
|
|
// Public Properties |
|
28
|
|
|
// ========================================================================= |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string Vanilla Forums jsConnect Client ID |
|
32
|
|
|
*/ |
|
33
|
|
|
public $vanillaForumsClientID = ''; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string Vanilla Forums jsConnect Secret |
|
37
|
|
|
*/ |
|
38
|
|
|
public $vanillaForumsSecret = ''; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string The hash algorithm to be ued when signing requests |
|
42
|
|
|
*/ |
|
43
|
|
|
public $hashAlgorithm = 'md5'; |
|
44
|
|
|
|
|
45
|
|
|
// Public Methods |
|
46
|
|
|
// ========================================================================= |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @inheritdoc |
|
50
|
|
|
*/ |
|
51
|
|
|
public function rules() |
|
52
|
|
|
{ |
|
53
|
|
|
return [ |
|
54
|
|
|
[['vanillaForumsClientID', 'vanillaForumsSecret'], 'string'], |
|
55
|
|
|
[['vanillaForumsClientID', 'vanillaForumsSecret'], 'default', 'value' => ''], |
|
56
|
|
|
['hashAlgorithm', 'string'], |
|
57
|
|
|
['hashAlgorithm', 'default', 'value' => 'md5'], |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @inheritdoc |
|
63
|
|
|
*/ |
|
64
|
|
|
public function behaviors() |
|
65
|
|
|
{ |
|
66
|
|
|
// Keep any parent behaviors |
|
67
|
|
|
$behaviors = parent::behaviors(); |
|
68
|
|
|
// Add in the AttributeTypecastBehavior |
|
69
|
|
|
$behaviors['typecast'] = [ |
|
70
|
|
|
'class' => AttributeTypecastBehavior::class, |
|
71
|
|
|
// 'attributeTypes' will be composed automatically according to `rules()` |
|
72
|
|
|
]; |
|
73
|
|
|
// If we're running Craft 3.1 or later, add in the EnvAttributeParserBehavior |
|
74
|
|
|
if (Vanillaforums::$craft31) { |
|
75
|
|
|
$behaviors['parser'] = [ |
|
76
|
|
|
'class' => EnvAttributeParserBehavior::class, |
|
77
|
|
|
'attributes' => [ |
|
78
|
|
|
'vanillaForumsClientID', |
|
79
|
|
|
'vanillaForumsSecret' |
|
80
|
|
|
], |
|
81
|
|
|
]; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $behaviors; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|