@@ -18,33 +18,50 @@ class Once extends \OpenTHC\SSO\Controller\Base
18
18
*/
19
19
function __invoke ($ REQ , $ RES , $ ARG )
20
20
{
21
+ session_regenerate_id (true );
22
+
23
+ $ _SESSION = [];
24
+
21
25
// Token Links
22
26
if (empty ($ _GET ['_ ' ])) {
23
- __exit_text ('Invalid Request [CAO-016] ' , 400 );
27
+ return $ RES ->withJSON ([
28
+ 'data ' => null ,
29
+ 'meta ' => [ 'note ' => 'Invalid Request [CAO-016] ' ]
30
+ ], 400 );
24
31
}
25
32
26
33
if (!preg_match ('/^([\w\-]{32,128})$/i ' , $ _GET ['_ ' ], $ m )) {
27
34
return $ RES ->withJSON ([
28
35
'data ' => null ,
29
- 'meta ' => [ 'detail ' => 'Invalid Request [CAO-022] ' ]
36
+ 'meta ' => [ 'note ' => 'Invalid Request [CAO-022] ' ]
30
37
], 400 );
31
38
}
32
39
33
- $ act = \OpenTHC \SSO \Auth_Context_Ticket::get ($ _GET ['_ ' ]);
34
- if (empty ($ act )) {
35
- return $ RES ->withRedirect ('/done?e=CAO-077 ' );
40
+ // Get Token
41
+ $ act = new \OpenTHC \Auth_Context_Ticket ($ this ->_container ->DBC_AUTH , $ _GET ['_ ' ]);
42
+ if ( ! $ act ->isValid ()) {
43
+ $ data = [
44
+ 'error_code ' => 'CAO-040 '
45
+ ];
46
+ $ RES = $ RES ->withStatus (400 );
47
+ $ RES = $ RES ->write ( $ this ->render ('done.php ' , $ data ) );
48
+ return $ RES ;
36
49
}
37
50
51
+ $ act = $ act ->getMeta ();
52
+
38
53
// Intention Router
39
54
switch ($ act ['intent ' ]) {
40
55
case 'account-create ' :
41
56
return $ this ->accountCreate ($ RES , $ act );
42
57
break ;
43
58
case 'email-verify ' :
44
- return $ RES ->withRedirect (sprintf ('/verify/email?_=%s ' , $ _GET ['_ ' ]));
59
+ $ tok = \OpenTHC \SSO \Auth_Context_Ticket::set ($ act );
60
+ return $ RES ->withRedirect (sprintf ('/verify/email?_=%s ' , $ tok ));
45
61
break ;
46
62
case 'password-reset ' :
47
- return $ RES ->withRedirect ('/account/password?_= ' . $ _GET ['_ ' ]);
63
+ $ tok = \OpenTHC \SSO \Auth_Context_Ticket::set ($ act );
64
+ return $ RES ->withRedirect (sprintf ('/account/password?_=%s ' , $ tok ));
48
65
break ;
49
66
case 'account-open ' :
50
67
case 'oauth-migrate ' :
@@ -56,8 +73,8 @@ function __invoke($REQ, $RES, $ARG)
56
73
$ data ['Page ' ]['title ' ] = 'Error ' ;
57
74
$ data ['body ' ] = '<div class="alert alert-danger">Invalid Request [CAO-061]</div> ' ;
58
75
59
- $ RES = $ RES ->write ( $ this ->render ('done.php ' , $ data ) );
60
76
$ RES = $ RES ->withStatus (400 );
77
+ $ RES = $ RES ->write ( $ this ->render ('done.php ' , $ data ) );
61
78
62
79
return $ RES ;
63
80
@@ -72,8 +89,16 @@ private function accountCreate($RES, $act_data)
72
89
$ dbc_main = $ this ->_container ->DBC_MAIN ;
73
90
74
91
// Update Contact, Promote Email to Username
75
- $ chk = $ dbc_auth ->fetchOne ('SELECT id, flag, stat FROM auth_contact WHERE id = :c0 ' , [ ':c0 ' => $ act_data ['contact ' ]['id ' ] ]);
92
+ $ sql = 'SELECT id, flag, stat FROM auth_contact WHERE id = :c0 ' ;
93
+ $ arg = [ ':c0 ' => $ act_data ['contact ' ]['id ' ] ];
94
+ $ chk = $ dbc_auth ->fetchOne ($ sql , $ arg );
76
95
if (empty ($ chk )) {
96
+ $ data = [
97
+ 'error_code ' => 'CAO-094 '
98
+ ];
99
+ $ RES = $ RES ->withStatus (400 );
100
+ $ RES = $ RES ->write ( $ this ->render ('done.php ' , $ data ) );
101
+ return $ RES ;
77
102
__exit_text ('Invalid Account [CAO-079] ' , 400 );
78
103
}
79
104
@@ -88,22 +113,21 @@ private function accountCreate($RES, $act_data)
88
113
$ dbc_main ->query ('BEGIN ' );
89
114
90
115
// Update Auth Contact
91
- $ ct_auth = new Auth_Contact ($ dbc_auth , $ act_data ['contact ' ]);
92
- $ ct_auth ['username ' ] = $ act_data ['contact ' ]['email ' ];
93
- $ ct_auth ['password ' ] = null ;
116
+ $ ct_auth = new Auth_Contact ($ dbc_auth , $ act_data ['contact ' ]['id ' ]);
94
117
$ ct_auth ->setFlag (\OpenTHC \Contact::FLAG_EMAIL_GOOD | \OpenTHC \Contact::FLAG_PHONE_WANT );
95
118
$ ct_auth ->save ();
96
119
97
120
// Update Base Contact
98
- $ ct_main = new \OpenTHC \Contact ($ dbc_main , $ act_data ['contact ' ]);
121
+ $ ct_main = new \OpenTHC \Contact ($ dbc_main , $ act_data ['contact ' ][ ' id ' ] );
99
122
$ ct_main ->setFlag (\OpenTHC \Contact::FLAG_EMAIL_GOOD | \OpenTHC \Contact::FLAG_PHONE_WANT );
100
123
$ ct_main ->save ();
101
124
102
125
$ dbc_auth ->query ('COMMIT ' );
103
126
$ dbc_main ->query ('COMMIT ' );
104
127
105
- // Init with this same token
106
- return $ RES ->withRedirect (sprintf ('/auth/init?_=%s ' , $ _GET ['_ ' ]));
128
+ // Verify after Create
129
+ $ tok = \OpenTHC \SSO \Auth_Context_Ticket::set ($ act_data );
130
+ return $ RES ->withRedirect (sprintf ('/verify?_=%s ' , $ tok ));
107
131
108
132
}
109
133
0 commit comments