This repository was archived by the owner on Feb 21, 2022. It is now read-only.
File tree 3 files changed +32
-4
lines changed 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace app ;
4
4
5
+ use dektrium \user \controllers \RegistrationController ;
5
6
use dektrium \user \events \FormEvent ;
6
7
use yii \base \Application ;
7
8
use yii \base \BootstrapInterface ;
8
- use dektrium \user \controllers \RegistrationController ;
9
9
use yii \base \Event ;
10
10
11
- class Bootstrap implements BootstrapInterface{
11
+ class Bootstrap implements BootstrapInterface
12
+ {
12
13
13
14
/**
14
15
* Bootstrap method to be called during application bootstrap stage.
@@ -19,9 +20,11 @@ public function bootstrap($app)
19
20
Event::on (
20
21
RegistrationController::className (),
21
22
RegistrationController::EVENT_BEFORE_REGISTER ,
22
- function ($ event ) {
23
+ function (FormEvent $ event) use ( $ app ) {
23
24
// generating api key
24
-
25
+ $ form = $ event ->getForm ();
26
+ $ form ->api_key = $ app ->security ->generateRandomString (16 );
27
+ $ event ->setForm ($ form );
25
28
}
26
29
);
27
30
Original file line number Diff line number Diff line change 19
19
'class ' => 'dektrium\user\Module ' ,
20
20
'modelMap ' => [
21
21
'User ' => 'app\models\User ' ,
22
+ 'RegistrationForm ' => 'app\models\user\RegistrationForm ' ,
22
23
],
23
24
],
24
25
'rbac ' => 'dektrium\rbac\RbacWebModule ' ,
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace app \models \user ;
4
+
5
+ use dektrium \user \models \RegistrationForm as BaseRegistrationForm ;
6
+
7
+ class RegistrationForm extends BaseRegistrationForm
8
+ {
9
+ /**
10
+ * @var string
11
+ */
12
+ public $ api_key ;
13
+
14
+ /**
15
+ * @inheritdoc
16
+ */
17
+ public function rules ()
18
+ {
19
+ $ rules = parent ::rules ();
20
+ $ rules [] = ['api_key ' , 'required ' ];
21
+ $ rules [] = ['api_key ' , 'string ' , 'max ' => 16 ];
22
+ return $ rules ;
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments