File tree 2 files changed +21
-7
lines changed
2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,11 @@ class SignupForm extends Model
27
27
*/
28
28
public $ password ;
29
29
30
+ /**
31
+ * @var UserModel
32
+ */
33
+ protected $ user ;
34
+
30
35
/**
31
36
* @inheritdoc
32
37
*/
@@ -72,13 +77,20 @@ public function signup()
72
77
return null ;
73
78
}
74
79
75
- $ user = new UserModel ();
76
- $ user ->username = $ this ->username ;
77
- $ user ->email = $ this ->email ;
78
- $ user ->setPassword ($ this ->password );
79
- $ user ->generateAuthKey ();
80
- $ user ->lastLogin = time ();
80
+ $ this ->user = new UserModel ();
81
+ $ this ->user ->setAttributes ($ this ->attributes );
82
+ $ this ->user ->setPassword ($ this ->password );
83
+ $ this ->user ->generateAuthKey ();
84
+ $ this ->user ->lastLogin = time ();
85
+
86
+ return $ this ->user ->save () ? $ this ->user : null ;
87
+ }
81
88
82
- return $ user ->save () ? $ user : null ;
89
+ /**
90
+ * @return UserModel|null
91
+ */
92
+ public function getUser ()
93
+ {
94
+ return $ this ->user ;
83
95
}
84
96
}
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ public function testSignupWithAlreadyExistEmail()
39
39
$ model ->username = 'demo ' ;
40
40
41
41
$ this ->assertNull ($ model ->signup ());
42
+ $ this ->assertNull ($ model ->getUser ());
42
43
$ this ->assertArrayHasKey ('email ' , $ model ->errors );
43
44
}
44
45
@@ -50,5 +51,6 @@ public function testSignupCorrect()
50
51
$ model ->username = 'demo2 ' ;
51
52
52
53
$ this ->assertInstanceOf (UserModel::class, $ model ->signup ());
54
+ $ this ->assertInstanceOf (UserModel::class, $ model ->getUser ());
53
55
}
54
56
}
You can’t perform that action at this time.
0 commit comments