1 <?php
2 3 4 5 6 7
8 class MemberActivation extends DataObjectDecorator {
9
10 static $key_length = 20;
11 static $key_sub = 5;
12 static $key_pool = '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
13
14 function () {
15 return array(
16 'db' => array(
17 'ActivationKey' => 'Varchar',
18 ),
19 );
20 }
21
22 static function get_by_activation_key($key) {
23 $key = Convert::raw2sql($key);
24 return DataObject::get_one('Member', "\"Member\".\"ActivationKey\" = '{$key}'");
25 }
26
27 static function ClearUnconfirmed() {
28
29 $sc = SiteConfig::current_site_config();
30 $every = intval($sc->AuthActivationTTL);
31 if ($every > 0 && $unconfirmed = DataObject::get('Member', "Created < NOW() - INTERVAL $every DAY")) {
32 foreach ($unconfirmed as $item){
33 if ($item->inGroup('unconfirm-site-members')) {
34 $item->delete();
35 }
36 }
37 }
38 }
39
40 static function generate_key() {
41 $key = '';
42 for ($i = 0; $i < self::$key_length; $i++) {
43 $key .= substr(self::$key_pool, mt_rand(0, strlen(self::$key_pool) - 1), 1);
44 if (($i + 1) % self::$key_sub == 0 && ($i + 1) != self::$key_length)
45 $key .= '-';
46 }
47 return $key;
48 }
49
50 51 52
53 function canLogIn(&$result){
54 foreach ($this->owner->Groups() as $group) {
55 if($group->Code == 'unconfirm-site-members'){
56 $result->error(_t(
57 'Member.NOTACTIVE',
58 'Ваша учетная запись не активирована'
59 ));
60 }
61 }
62 return $result;
63 }
64
65 function updateCMSFields(&$fields) {
66 $fields->removeByName('ActivationKey');
67 }
68
69 function updateMemberFormFields(&$fields) {
70 $fields->removeByName('ActivationKey');
71 $fields->removeByName('Locale');
72 }
73
74 function onBeforeWrite() {
75 if (!$this->owner->IsInDB() && !$this->owner->ActivationKey)
76 $this->owner->ActivationKey = self::generate_key();
77 }
78
79 function ProfileLink() {
80 return Director::absoluteURL(ProfilePage::find_link());
81 }
82
83 }
84
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-