@@ -16,59 +16,54 @@ function __construct($swoole)
16
16
17
17
function verify ()
18
18
{
19
- session ();
20
- $ this ->swoole ->http ->header ('Content-Type ' , 'image/png ' );
21
- Swoole \Image::verifycode_gd ();
19
+ $ this ->session ->start ();
20
+ $ this ->http ->header ('Content-Type ' , 'image/jpeg ' );
21
+ $ verifyCode = Swoole \Image::verifycode_gd ();
22
+ $ _SESSION ['authcode ' ] = $ verifyCode ['code ' ];
23
+ return $ verifyCode ['image ' ];
22
24
}
23
25
24
- function test2 ()
26
+ function oauth ()
25
27
{
26
28
session ();
27
- $ _SESSION ['test ' ] =1 ;
28
- var_dump ($ _SESSION );
29
- }
29
+ if (empty ($ _GET ['s ' ]) or $ _GET ['s ' ] == 'sina ' )
30
+ {
31
+ $ conf = $ this ->config ['oauth ' ]['weibo ' ];
32
+ $ oauth = new \WeiboOAuth ($ conf ['appid ' ], $ conf ['skey ' ]);
33
+ $ keys = $ oauth ->getRequestToken ();
34
+ $ _SESSION ['oauth_keys ' ] = $ keys ;
35
+ $ _SESSION ['oauth_serv ' ] = 'sina ' ;
36
+ $ login_url = $ oauth ->getAuthorizeURL ($ keys ['oauth_token ' ], false , WEBROOT . '/page/oauth_callback/ ' );
37
+ $ this ->swoole ->http ->redirect ($ login_url );
38
+ }
39
+ elseif ($ _GET ['s ' ] == 'qq ' )
40
+ {
30
41
31
- function oauth ()
32
- {
33
- session ();
34
- if (empty ($ _GET ['s ' ]) or $ _GET ['s ' ]=='sina ' )
35
- {
36
- $ conf = $ this ->config ['oauth ' ]['weibo ' ];
37
- $ oauth = new \WeiboOAuth ($ conf ['appid ' ], $ conf ['skey ' ]);
38
- $ keys = $ oauth ->getRequestToken ();
39
- $ _SESSION ['oauth_keys ' ] = $ keys ;
40
- $ _SESSION ['oauth_serv ' ] = 'sina ' ;
41
- $ login_url = $ oauth ->getAuthorizeURL ($ keys ['oauth_token ' ],false ,WEBROOT .'/page/oauth_callback/ ' );
42
- $ this ->swoole ->http ->redirect ($ login_url );
43
- }
44
- elseif ($ _GET ['s ' ]=='qq ' )
45
- {
46
-
47
- $ conf = $ this ->config ['oauth ' ]['qq ' ];
48
- $ oauth = new \QQOAuth ($ conf ['APP_ID ' ], $ conf ['APP_KEY ' ]);
49
- $ token = $ oauth ->getRequestToken ();
50
- $ _SESSION ['oauth_keys ' ] = $ token ;
51
- $ _SESSION ['oauth_serv ' ] = 'qq ' ;
52
- $ login_url = $ oauth ->getAuthorizeURL ($ token ,WEBROOT .'/page/oauth_callback/ ' );
42
+ $ conf = $ this ->config ['oauth ' ]['qq ' ];
43
+ $ oauth = new \QQOAuth ($ conf ['APP_ID ' ], $ conf ['APP_KEY ' ]);
44
+ $ token = $ oauth ->getRequestToken ();
45
+ $ _SESSION ['oauth_keys ' ] = $ token ;
46
+ $ _SESSION ['oauth_serv ' ] = 'qq ' ;
47
+ $ login_url = $ oauth ->getAuthorizeURL ($ token , WEBROOT . '/page/oauth_callback/ ' );
53
48
$ this ->swoole ->http ->redirect ($ login_url );
54
- }
55
- }
49
+ }
50
+ }
51
+
56
52
function oauth_callback ()
57
53
{
58
- session ();
59
- if ($ _SESSION ['oauth_serv ' ]=='sina ' )
60
- {
61
-
54
+ session ();
55
+ if ($ _SESSION ['oauth_serv ' ] == 'sina ' )
56
+ {
62
57
$ conf = $ this ->config ['oauth ' ]['weibo ' ];
63
58
$ oauth = new \WeiboOAuth ($ conf ['appid ' ], $ conf ['skey ' ], $ _SESSION ['oauth_keys ' ]['oauth_token ' ], $ _SESSION ['oauth_keys ' ]['oauth_token_secret ' ]);
64
59
$ _SESSION ['last_key ' ] = $ oauth ->getAccessToken ($ _REQUEST ['oauth_verifier ' ]);
65
60
66
- $ client = new \WeiboClient ($ conf ['appid ' ], $ conf ['skey ' ],$ _SESSION ['last_key ' ]['oauth_token ' ],$ _SESSION ['last_key ' ]['oauth_token_secret ' ]);
67
- $ userinfo = $ client ->verify_credentials ();
68
- if (!isset ($ userinfo ['id ' ]))
61
+ $ client = new \WeiboClient ($ conf ['appid ' ], $ conf ['skey ' ], $ _SESSION ['last_key ' ]['oauth_token ' ],
62
+ $ _SESSION ['last_key ' ]['oauth_token_secret ' ]);
63
+ $ userinfo = $ client ->verify_credentials ();
64
+ if (!isset ($ userinfo ['id ' ]))
69
65
{
70
- var_dump ($ conf , $ _SESSION );
71
- return "请求错误: " .var_export ($ userinfo , true );
66
+ return "请求错误: " . var_export ($ userinfo , $ conf , $ _SESSION , true );
72
67
}
73
68
$ model = createModel ('UserInfo ' );
74
69
$ username = 'sina_ ' .$ userinfo ['id ' ];
@@ -88,7 +83,7 @@ function oauth_callback()
88
83
$ _SESSION ['user_id ' ] = $ u ['id ' ];
89
84
$ _SESSION ['user ' ] = $ u ;
90
85
$ this ->setLoginStat ();
91
- $ this ->swoole -> http ->edirect (WEBROOT ."/person/index/ " );
86
+ $ this ->http ->redirect (WEBROOT ."/person/index/ " );
92
87
}
93
88
elseif ($ _SESSION ['oauth_serv ' ]=='qq ' )
94
89
{
@@ -98,13 +93,17 @@ function oauth_callback()
98
93
$ oauth ->getAccessToken ($ _GET ['oauth_token ' ], $ _SESSION ['oauth_keys ' ]['oauth_token_secret ' ], $ _GET ['oauth_vericode ' ]);
99
94
100
95
$ username = $ oauth ->access_token ['openid ' ];
96
+
101
97
$ model = createModel ('UserInfo ' );
102
98
$ u = $ model ->get ($ username ,'username ' )->get ();
103
- //不存在,则插入数据库
104
- if (empty ($ u ))
105
- {
106
- $ user = $ oauth ->api_get ('user/get_user_info ' );
107
- if (empty ($ user )) return Swoole \JS ::js_back ("请求错误 " );
99
+ //不存在,则插入数据库
100
+ if (empty ($ u ))
101
+ {
102
+ $ user = $ oauth ->api_get ('user/get_user_info ' );
103
+ if (empty ($ user ))
104
+ {
105
+ return Swoole \JS ::js_back ("请求错误 " );
106
+ }
108
107
109
108
$ u ['username ' ] = $ username ;
110
109
$ u ['nickname ' ] = $ user ['nickname ' ];
@@ -117,9 +116,10 @@ function oauth_callback()
117
116
$ _SESSION ['user_id ' ] = $ u ['id ' ];
118
117
$ _SESSION ['user ' ] = $ u ;
119
118
$ this ->setLoginStat ();
120
- $ this ->swoole -> http ->redirect (WEBROOT ."/person/index/ " );
119
+ $ this ->http ->redirect (WEBROOT ."/person/index/ " );
121
120
}
122
121
}
122
+
123
123
function flist ()
124
124
{
125
125
//Error::dbd();
@@ -208,8 +208,9 @@ function index()
208
208
$ gets ['fid ' ] = 9 ;
209
209
$ model = createModel ('News ' );
210
210
$ list = $ model ->gets ($ gets );
211
-
211
+
212
212
$ userlist = $ this ->getActiveUsers (50 );
213
+
213
214
$ this ->swoole ->tpl ->assign ('userlist ' , $ userlist );
214
215
$ this ->swoole ->tpl ->assign ('list ' , $ list );
215
216
$ this ->swoole ->tpl ->display ('index.html ' );
@@ -218,14 +219,15 @@ function index()
218
219
{
219
220
$ page = $ _GET ['p ' ];
220
221
$ model = createModel ('Cpage ' );
222
+
221
223
$ det = $ model ->get ($ page ,'pagename ' );
222
224
$ this ->swoole ->tpl ->assign ('det ' ,$ det );
223
225
$ this ->swoole ->tpl ->display ('index_page.html ' );
224
226
}
225
227
}
228
+
226
229
/**
227
230
* 个人用户登录
228
- * @return unknown_type
229
231
*/
230
232
function login ()
231
233
{
@@ -330,8 +332,8 @@ function register()
330
332
}
331
333
else
332
334
{
333
- require WEBPATH . '/dict/forms.php ' ;
334
- $ _forms ['sex ' ] = Swoole \Form::radio ('sex ' , $ forms ['sex ' ]);
335
+ $ forms = require WEBPATH . '/dict/forms.php ' ;
336
+ $ _forms ['sex ' ] = Swoole \Form::radio ('sex ' , $ forms ['sex ' ]);
335
337
//$_forms['level'] = Form::radio('php_level',$forms['level'],'');
336
338
$ this ->swoole ->tpl ->assign ('forms ' ,$ _forms );
337
339
$ this ->swoole ->tpl ->display ();
@@ -346,25 +348,26 @@ function chatroom()
346
348
$ this ->swoole ->tpl ->assign ('user ' ,$ userInfo ->get ($ _SESSION ['user_id ' ])->get ());
347
349
$ this ->swoole ->tpl ->display ();
348
350
}
351
+
349
352
/**
350
353
* 忘记密码
351
- * @return unknown_type
352
354
*/
353
355
function forgot ()
354
- {
355
- if ($ _POST )
356
- {
357
- $ gets ['realname ' ] = $ _POST ['realname ' ];
358
- $ gets ['username ' ] = $ _POST ['email ' ];
359
- $ gets ['mobile ' ] = $ _POST ['mobile ' ];
360
- $ gets ['select ' ] = 'id ' ;
361
- $ ul = $ this ->model ->UserInfo ->gets ($ gets );
362
- if (count ($ ul )!=0 )
363
- {
364
- $ password = App \Func::randomkeys (6 );
365
- $ this ->model ->UserInfo ->set ($ ul [0 ]['id ' ],array ('password ' =>Auth::mkpasswd ($ gets ['username ' ],$ password )));
366
- App \Func::success ('找回成功! ' ,'您的新密码是 <span style="color:#fe7e00;"> ' .$ password .'</a> ' );
367
- }
356
+ {
357
+ if ($ _POST )
358
+ {
359
+ $ gets ['realname ' ] = $ _POST ['realname ' ];
360
+ $ gets ['username ' ] = $ _POST ['email ' ];
361
+ $ gets ['mobile ' ] = $ _POST ['mobile ' ];
362
+ $ gets ['select ' ] = 'id ' ;
363
+ $ ul = $ this ->model ->UserInfo ->gets ($ gets );
364
+ if (count ($ ul ) != 0 )
365
+ {
366
+ $ password = App \Func::randomkeys (6 );
367
+ $ this ->model ->UserInfo ->set ($ ul [0 ]['id ' ],
368
+ array ('password ' => Auth::mkpasswd ($ gets ['username ' ], $ password )));
369
+ App \Func::success ('找回成功! ' , '您的新密码是 <span style="color:#fe7e00;"> ' . $ password . '</a> ' );
370
+ }
368
371
}
369
372
else
370
373
{
0 commit comments