GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 278e53...818459 )
by gyeong-won
39:17 queued 30:14
created

memberController::procMemberInsertImageName()   D

Complexity

Conditions 9
Paths 7

Size

Total Lines 25
Code Lines 14

Duplication

Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
cc 9
eloc 14
nc 7
nop 0
dl 25
loc 25
rs 4.909
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  memberController
5
 * @author NAVER ([email protected])
6
 * Controller class of member module
7
 */
8
class memberController extends member
9
{
10
	/**
11
	 * Info of selected member
12
	 *
13
	 * @var object
14
	 */
15
	var $memberInfo;
16
17
	/**
18
	 * Initialization
19
	 *
20
	 * @return void
21
	 */
22
	function init()
23
	{
24
	}
25
26
	/**
27
	 * Log-in by checking user_id and password
28
	 *
29
	 * @param string $user_id
30
	 * @param string $password
31
	 * @param string $keep_signed
32
	 *
33
	 * @return void|BaseObject (void : success, BaseObject : fail)
34
	 */
35
	function procMemberLogin($user_id = null, $password = null, $keep_signed = null)
36
	{
37
		if(!$user_id && !$password && Context::getRequestMethod() == 'GET')
0 ignored issues
show
Bug Best Practice introduced by
The expression $user_id of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $password of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
38
		{
39
			$this->setRedirectUrl(getNotEncodedUrl(''));
40
			return new BaseObject(-1, 'null_user_id');
41
		}
42
43
		// Variables
44
		if(!$user_id) $user_id = Context::get('user_id');
0 ignored issues
show
Bug Best Practice introduced by
The expression $user_id of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
45
		$user_id = trim($user_id);
46
47
		if(!$password) $password = Context::get('password');
0 ignored issues
show
Bug Best Practice introduced by
The expression $password of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
48
		$password = trim($password);
49
50
		if(!$keep_signed) $keep_signed = Context::get('keep_signed');
0 ignored issues
show
Bug Best Practice introduced by
The expression $keep_signed of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
51
		// Return an error when id and password doesn't exist
52
		if(!$user_id) return new BaseObject(-1,'null_user_id');
53
		if(!$password) return new BaseObject(-1,'null_password');
54
55
		$output = $this->doLogin($user_id, $password, $keep_signed=='Y'?true:false);
56
		if (!$output->toBool()) return $output;
57
58
		$oModuleModel = getModel('module');
59
		$config = $oModuleModel->getModuleConfig('member');
60
61
		// Check change_password_date
62
		$limit_date = $config->change_password_date;
63
64
		// Check if change_password_date is set
65
		if($limit_date > 0)
66
		{
67
			$oMemberModel = getModel('member');
0 ignored issues
show
Unused Code introduced by
$oMemberModel is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
68
			if($this->memberInfo->change_password_date < date ('YmdHis', strtotime ('-' . $limit_date . ' day')))
69
			{
70
				$msg = sprintf(Context::getLang('msg_change_password_date'), $limit_date);
71
				return $this->setRedirectUrl(getNotEncodedUrl('','vid',Context::get('vid'),'mid',Context::get('mid'),'act','dispMemberModifyPassword'), new BaseObject(-1, $msg));
72
			}
73
		}
74
75
		// Delete all previous authmail if login is successful
76
		$args = new stdClass();
77
		$args->member_srl = $this->memberInfo->member_srl;
78
		executeQuery('member.deleteAuthMail', $args);
79
80
		if(!$config->after_login_url)
81
		{
82
			$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
83
		}
84
		else
85
		{
86
			$returnUrl = $config->after_login_url;
87
		}
88
		return $this->setRedirectUrl($returnUrl, $output);
89
	}
90
91
	/**
92
	 * Log-out
93
	 *
94
	 * @return BaseObject
95
	 */
96
	function procMemberLogout()
97
	{
98
		// Call a trigger before log-out (before)
99
		$logged_info = Context::get('logged_info');
100
		$trigger_output = ModuleHandler::triggerCall('member.doLogout', 'before', $logged_info);
0 ignored issues
show
Documentation introduced by
$logged_info is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
101
		if(!$trigger_output->toBool()) return $trigger_output;
102
		// Destroy session information
103
		$this->destroySessionInfo();
104
		// Call a trigger after log-out (after)
105
		$trigger_output = ModuleHandler::triggerCall('member.doLogout', 'after', $logged_info);
106
		if(!$trigger_output->toBool()) return $trigger_output;
107
108
		$output = new BaseObject();
109
110
		$oModuleModel = getModel('module');
111
		$config = $oModuleModel->getModuleConfig('member');
112
		if($config->after_logout_url)
113
			$output->redirect_url = $config->after_logout_url;
0 ignored issues
show
Bug introduced by
The property redirect_url does not seem to exist in BaseObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
114
115
		$this->_clearMemberCache($logged_info->member_srl);
116
117
		return $output;
118
	}
119
120
	/**
121
	 * Scrap document
122
	 *
123
	 * @return void|BaseObject (void : success, BaseObject : fail)
124
	 */
125
	function procMemberScrapDocument()
126
	{
127
		$oModuleModel = &getModel('module');
128
129
		// Check login information
130
		if(!Context::get('is_logged')) return new BaseObject(-1, 'msg_not_logged');
131
		$logged_info = Context::get('logged_info');
132
133
		$document_srl = (int)Context::get('document_srl');
134
		if(!$document_srl) $document_srl = (int)Context::get('target_srl');
135
		if(!$document_srl) return new BaseObject(-1,'msg_invalid_request');
136
137
		// Get document
138
		$oDocumentModel = getModel('document');
139
		$oDocument = $oDocumentModel->getDocument($document_srl);
140
141
		if($oDocument->isSecret() && !$oDocument->isGranted())
142
		{
143
			return new BaseObject(-1, 'msg_is_secret');
144
		}
145
146
		// 모듈 권한 확인
147
		$module_info = $oModuleModel->getModuleInfoByModuleSrl($oDocument->get('module_srl'));
148
		$grant = $oModuleModel->getGrant($module_info, $logged_info);
149
150
		if(!$grant->access)
151
		{
152
			return new BaseObject(-1, 'msg_not_permitted');
153
		}
154
155
		// 게시판 모듈에서 글 목록 보기 권한이 없으면 스크랩 제한
156
		if($module_info->module === 'board' && isset($grant->list) && !$grant->list)
157
		{
158
			return new BaseObject(-1, 'msg_not_permitted');
159
		}
160
161
		// 게시판 모듈에서 상담 기능 사용 시 권한이 없는 게시물(타인의 게시물) 스크랩 제한
162
		if($module_info->module === 'board' &&
163
			$module_info->consultation === 'Y' &&
164
			isset($grant->consultation_read) &&
165
			!$grant->consultation_read && !$oDocument->isGranted()
166
		)
167
		{
168
			return new BaseObject(-1, 'msg_not_permitted');
169
		}
170
171
		// Variables
172
		$args = new stdClass();
173
		$args->document_srl = $document_srl;
174
		$args->member_srl = $logged_info->member_srl;
175
		$args->user_id = $oDocument->get('user_id');
176
		$args->user_name = $oDocument->get('user_name');
177
		$args->nick_name = $oDocument->get('nick_name');
178
		$args->target_member_srl = $oDocument->get('member_srl');
179
		$args->title = $oDocument->get('title');
180
181
		// Check if already scrapped
182
		$output = executeQuery('member.getScrapDocument', $args);
183
		if($output->data->count) return new BaseObject(-1, 'msg_alreay_scrapped');
184
185
		// Insert
186
		$output = executeQuery('member.addScrapDocument', $args);
187
		if(!$output->toBool()) return $output;
188
189
		$this->setError(-1);
190
		$this->setMessage('success_registed');
191
	}
192
193
	/**
194
	 * Delete a scrap
195
	 *
196
	 * @return void|BaseObject (void : success, BaseObject : fail)
197
	 */
198
	function procMemberDeleteScrap()
199
	{
200
		// Check login information
201
		if(!Context::get('is_logged')) return new BaseObject(-1, 'msg_not_logged');
202
		$logged_info = Context::get('logged_info');
203
204
		$document_srl = (int)Context::get('document_srl');
205
		if(!$document_srl) return new BaseObject(-1,'msg_invalid_request');
206
		// Variables
207
		$args = new stdClass;
208
		$args->member_srl = $logged_info->member_srl;
209
		$args->document_srl = $document_srl;
210
		return executeQuery('member.deleteScrapDocument', $args);
211
	}
212
213
	/**
214
	 * Save posts
215
	 * @deprecated - instead Document Controller - procDocumentTempSave method use
216
	 * @return BaseObject
217
	 */
218
	function procMemberSaveDocument()
219
	{
220
		return new BaseObject(0, 'Deprecated method');
221
	}
222
223
	/**
224
	 * Delete the post
225
	 *
226
	 * @return void|BaseObject (void : success, BaseObject : fail)
227
	 */
228
	function procMemberDeleteSavedDocument()
229
	{
230
		// Check login information
231
		if(!Context::get('is_logged')) return new BaseObject(-1, 'msg_not_logged');
232
		$logged_info = Context::get('logged_info');
233
234
		$document_srl = (int)Context::get('document_srl');
235
		if(!$document_srl) return new BaseObject(-1,'msg_invalid_request');
236
237
		$oDocumentModel = getModel('document');
238
		$oDocument = $oDocumentModel->getDocument($document_srl);
239
		if ($oDocument->get('member_srl') != $logged_info->member_srl)
240
		{
241
			return new BaseObject(-1,'msg_invalid_request');
242
		}
243
244
		$configStatusList = $oDocumentModel->getStatusList();
245
		if ($oDocument->get('status') != $configStatusList['temp'])
246
		{
247
			return new BaseObject(-1,'msg_invalid_request');
248
		}
249
250
		$oDocumentController = getController('document');
251
		$oDocumentController->deleteDocument($document_srl);
252
	}
253
254
	/**
255
	 * Check values when member joining
256
	 *
257
	 * @return void|BaseObject (void : success, BaseObject : fail)
258
	 */
259
	function procMemberCheckValue()
260
	{
261
		$name = Context::get('name');
262
		$value = Context::get('value');
263
		if(!$value) return;
264
265
		$oMemberModel = getModel('member');
266
		// Check if logged-in
267
		$logged_info = Context::get('logged_info');
268
269
270
		switch($name)
271
		{
272
			case 'user_id' :
273
				// Check denied ID
274
				if($oMemberModel->isDeniedID($value)) return new BaseObject(0,'denied_user_id');
275
				// Check if duplicated
276
				$member_srl = $oMemberModel->getMemberSrlByUserID($value);
277
				if($member_srl && $logged_info->member_srl != $member_srl ) return new BaseObject(0,'msg_exists_user_id');
278
				break;
279
			case 'nick_name' :
280
				// Check denied ID
281
				if($oMemberModel->isDeniedNickName($value))
282
				{
283
					return new BaseObject(0,'denied_nick_name');
284
				}
285
				// Check if duplicated
286
				$member_srl = $oMemberModel->getMemberSrlByNickName($value);
287
				if($member_srl && $logged_info->member_srl != $member_srl ) return new BaseObject(0,'msg_exists_nick_name');
288
289
				break;
290
			case 'email_address' :
291
				// Check if duplicated
292
				$member_srl = $oMemberModel->getMemberSrlByEmailAddress($value);
293
				if($member_srl && $logged_info->member_srl != $member_srl ) return new BaseObject(0,'msg_exists_email_address');
294
				break;
295
		}
296
	}
297
298
	/**
299
	 * Join Membership
300
	 *
301
	 * @return void|BaseObject (void : success, BaseObject : fail)
302
	 */
303
	function procMemberInsert()
304
	{
305
		if (Context::getRequestMethod () == "GET") return new BaseObject(-1, "msg_invalid_request");
306
		$oMemberModel = &getModel ('member');
307
		$config = $oMemberModel->getMemberConfig();
308
309
		// call a trigger (before)
310
		$trigger_output = ModuleHandler::triggerCall ('member.procMemberInsert', 'before', $config);
311
		if(!$trigger_output->toBool ()) return $trigger_output;
312
		// Check if an administrator allows a membership
313
		if($config->enable_join != 'Y') return $this->stop ('msg_signup_disabled');
314
		// Check if the user accept the license terms (only if terms exist)
315
		if($config->agreement && Context::get('accept_agreement')!='Y') return $this->stop('msg_accept_agreement');
316
317
		// Extract the necessary information in advance
318
		$getVars = array();
319 View Code Duplication
		if($config->signupForm)
320
		{
321
			foreach($config->signupForm as $formInfo)
322
			{
323
				if($formInfo->isDefaultForm && ($formInfo->isUse || $formInfo->required || $formInfo->mustRequired))
324
				{
325
					$getVars[] = $formInfo->name;
326
				}
327
			}
328
		}
329
330
		$args = new stdClass;
331
		foreach($getVars as $val)
332
		{
333
			$args->{$val} = Context::get($val);
334
			if($val == 'birthday') $args->birthday_ui = Context::get('birthday_ui');
335
		}
336
		$args->birthday = intval(strtr($args->birthday, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
337 View Code Duplication
		if(!$args->birthday && $args->birthday_ui) $args->birthday = intval(strtr($args->birthday_ui, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
338
339
		$args->find_account_answer = Context::get('find_account_answer');
340
		$args->allow_mailing = Context::get('allow_mailing');
341
		$args->allow_message = Context::get('allow_message');
342
343
		if($args->password1) $args->password = $args->password1;
344
345
		// check password strength
346 View Code Duplication
		if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
347
		{
348
			$message = Context::getLang('about_password_strength');
349
			return new BaseObject(-1, $message[$config->password_strength]);
350
		}
351
352
		// Remove some unnecessary variables from all the vars
353
		$all_args = Context::getRequestVars();
354
		unset($all_args->module);
355
		unset($all_args->act);
356
		unset($all_args->is_admin);
357
		unset($all_args->member_srl);
358
		unset($all_args->description);
359
		unset($all_args->group_srl_list);
360
		unset($all_args->body);
361
		unset($all_args->accept_agreement);
362
		unset($all_args->signature);
363
		unset($all_args->password);
364
		unset($all_args->password2);
365
		unset($all_args->mid);
366
		unset($all_args->error_return_url);
367
		unset($all_args->ruleset);
368
		unset($all_args->captchaType);
369
		unset($all_args->secret_text);
370
371
		// Set the user state as "denied" when using mail authentication
372
		if($config->enable_confirm == 'Y') $args->denied = 'Y';
373
		// Add extra vars after excluding necessary information from all the requested arguments
374
		$extra_vars = delObjectVars($all_args, $args);
375
		$args->extra_vars = serialize($extra_vars);
376
377
		// remove whitespace
378
		$checkInfos = array('user_id', 'user_name', 'nick_name', 'email_address');
379 View Code Duplication
		foreach($checkInfos as $val)
380
		{
381
			if(isset($args->{$val}))
382
			{
383
				$args->{$val} = preg_replace('/[\pZ\pC]+/u', '', $args->{$val});
384
			}
385
		}
386
		$output = $this->insertMember($args);
387
		if(!$output->toBool()) return $output;
388
389
		// insert ProfileImage, ImageName, ImageMark
390
		$profile_image = $_FILES['profile_image'];
391
		if(is_uploaded_file($profile_image['tmp_name']))
392
		{
393
			$this->insertProfileImage($args->member_srl, $profile_image['tmp_name']);
394
		}
395
396
		$image_mark = $_FILES['image_mark'];
397
		if(is_uploaded_file($image_mark['tmp_name']))
398
		{
399
			$this->insertImageMark($args->member_srl, $image_mark['tmp_name']);
400
		}
401
402
		$image_name = $_FILES['image_name'];
403
		if(is_uploaded_file($image_name['tmp_name']))
404
		{
405
			$this->insertImageName($args->member_srl, $image_name['tmp_name']);
406
		}
407
408
		// If a virtual site, join the site
409
		$site_module_info = Context::get('site_module_info');
410
		if($site_module_info->site_srl > 0)
411
		{
412
			$columnList = array('site_srl', 'group_srl');
413
			$default_group = $oMemberModel->getDefaultGroup($site_module_info->site_srl, $columnList);
414
			if($default_group->group_srl)
415
			{
416
				$this->addMemberToGroup($args->member_srl, $default_group->group_srl, $site_module_info->site_srl);
417
			}
418
419
		}
420
		// Log-in
421
		if($config->enable_confirm != 'Y')
422
		{
423
			if($config->identifier == 'email_address')
424
			{
425
				$output = $this->doLogin($args->email_address);
426
			}
427
			else
428
			{
429
				$output = $this->doLogin($args->user_id);
430
			}
431
			if(!$output->toBool()) {
432
				if($output->error == -9)
433
					$output->error = -11;
434
				return $this->setRedirectUrl(getUrl('', 'act', 'dispMemberLoginForm'), $output);
435
			}
436
		}
437
438
		// Results
439
		$this->add('member_srl', $args->member_srl);
440
		if($config->redirect_url) $this->add('redirect_url', $config->redirect_url);
441
		if($config->enable_confirm == 'Y')
442
		{
443
			$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $args->email_address);
444
			$this->setMessage($msg);
445
			return $this->setRedirectUrl(getUrl('', 'act', 'dispMemberLoginForm'), new BaseObject(-12, $msg));
446
		}
447
		else $this->setMessage('success_registed');
448
		// Call a trigger (after)
449
		$trigger_output = ModuleHandler::triggerCall('member.procMemberInsert', 'after', $config);
450
		if(!$trigger_output->toBool()) return $trigger_output;
451
452
		if($config->redirect_url)
453
		{
454
			$returnUrl = $config->redirect_url;
455
		}
456
		else
457
		{
458
			if(Context::get('success_return_url'))
459
			{
460
				$returnUrl = Context::get('success_return_url');
461
			}
462
			else if($_COOKIE['XE_REDIRECT_URL'])
463
			{
464
				$returnUrl = $_COOKIE['XE_REDIRECT_URL'];
465
				setcookie("XE_REDIRECT_URL", '', 1);
466
			}
467
		}
468
469
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
470
471
		$this->setRedirectUrl($returnUrl);
0 ignored issues
show
Bug introduced by
The variable $returnUrl does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
472
	}
473
474
	function procMemberModifyInfoBefore()
475
	{
476
		if($_SESSION['rechecked_password_step'] != 'INPUT_PASSWORD')
477
		{
478
			return $this->stop('msg_invalid_request');
479
		}
480
481
		if(!Context::get('is_logged'))
482
		{
483
			return $this->stop('msg_not_logged');
484
		}
485
486
		$password = Context::get('password');
487
488
		if(!$password)
489
		{
490
			return $this->stop('msg_invalid_request');
491
		}
492
493
		$oMemberModel = getModel('member');
494
495
		if(!$this->memberInfo->password)
496
		{
497
			// Get information of logged-in user
498
			$logged_info = Context::get('logged_info');
499
			$member_srl = $logged_info->member_srl;
500
501
			$columnList = array('member_srl', 'password');
502
			$memberInfo = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
503
			$this->memberInfo->password = $memberInfo->password;
504
		}
505
		// Verify the current password
506
		if(!$oMemberModel->isValidPassword($this->memberInfo->password, $password))
507
		{
508
			return new BaseObject(-1, 'invalid_password');
509
		}
510
511
		$_SESSION['rechecked_password_step'] = 'VALIDATE_PASSWORD';
512
513
		if(Context::get('success_return_url'))
514
		{
515
			$redirectUrl = Context::get('success_return_url');
516
		}
517
		else
518
		{
519
			$redirectUrl = getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
520
		}
521
		$this->setRedirectUrl($redirectUrl);
522
	}
523
524
	/**
525
	 * Edit member profile
526
	 *
527
	 * @return void|BaseObject (void : success, BaseObject : fail)
528
	 */
529
	function procMemberModifyInfo()
530
	{
531
		if(!Context::get('is_logged'))
532
		{
533
			return $this->stop('msg_not_logged');
534
		}
535
536
		if($_SESSION['rechecked_password_step'] != 'INPUT_DATA')
537
		{
538
			return $this->stop('msg_invalid_request');
539
		}
540
		unset($_SESSION['rechecked_password_step']);
541
542
		// Extract the necessary information in advance
543
		$oMemberModel = getModel('member');
544
		$config = $oMemberModel->getMemberConfig ();
545
		$getVars = array('find_account_answer','allow_mailing','allow_message');
546 View Code Duplication
		if($config->signupForm)
547
		{
548
			foreach($config->signupForm as $formInfo)
549
			{
550
				if($formInfo->isDefaultForm && ($formInfo->isUse || $formInfo->required || $formInfo->mustRequired))
551
				{
552
					$getVars[] = $formInfo->name;
553
				}
554
			}
555
		}
556
557
		$args = new stdClass;
558
		foreach($getVars as $val)
559
		{
560
			$args->{$val} = Context::get($val);
561
			if($val == 'birthday') $args->birthday_ui = Context::get('birthday_ui');
562
			if($val == 'find_account_answer' && !Context::get($val)) {
563
				unset($args->{$val});
564
			}
565
		}
566
567
		// Login Information
568
		$logged_info = Context::get('logged_info');
569
		$args->member_srl = $logged_info->member_srl;
570
		$args->birthday = intval(strtr($args->birthday, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
571 View Code Duplication
		if(!$args->birthday && $args->birthday_ui) $args->birthday = intval(strtr($args->birthday_ui, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
572
573
		// Remove some unnecessary variables from all the vars
574
		$all_args = Context::getRequestVars();
575
		unset($all_args->module);
576
		unset($all_args->act);
577
		unset($all_args->member_srl);
578
		unset($all_args->is_admin);
579
		unset($all_args->description);
580
		unset($all_args->group_srl_list);
581
		unset($all_args->body);
582
		unset($all_args->accept_agreement);
583
		unset($all_args->signature);
584
		unset($all_args->_filter);
585
		unset($all_args->mid);
586
		unset($all_args->error_return_url);
587
		unset($all_args->ruleset);
588
		unset($all_args->password);
589
590
		// Add extra vars after excluding necessary information from all the requested arguments
591
		$extra_vars = delObjectVars($all_args, $args);
592
		$args->extra_vars = serialize($extra_vars);
593
594
		// remove whitespace
595
		$checkInfos = array('user_id', 'user_name', 'nick_name', 'email_address');
596 View Code Duplication
		foreach($checkInfos as $val)
597
		{
598
			if(isset($args->{$val}))
599
			{
600
				$args->{$val} = preg_replace('/[\pZ\pC]+/u', '', $args->{$val});
601
			}
602
		}
603
604
		// Execute insert or update depending on the value of member_srl
605
		$output = $this->updateMember($args);
606
		if(!$output->toBool()) return $output;
607
608
		$profile_image = $_FILES['profile_image'];
609
		if(is_uploaded_file($profile_image['tmp_name']))
610
		{
611
			$this->insertProfileImage($args->member_srl, $profile_image['tmp_name']);
612
		}
613
614
		$image_mark = $_FILES['image_mark'];
615
		if(is_uploaded_file($image_mark['tmp_name']))
616
		{
617
			$this->insertImageMark($args->member_srl, $image_mark['tmp_name']);
618
		}
619
620
		$image_name = $_FILES['image_name'];
621
		if(is_uploaded_file($image_name['tmp_name']))
622
		{
623
			$this->insertImageName($args->member_srl, $image_name['tmp_name']);
624
		}
625
626
		// Save Signature
627
		$signature = Context::get('signature');
628
		$this->putSignature($args->member_srl, $signature);
629
630
		// Get user_id information
631
		$this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($args->member_srl);
632
633
634
		// Call a trigger after successfully log-in (after)
635
		$trigger_output = ModuleHandler::triggerCall('member.procMemberModifyInfo', 'after', $this->memberInfo);
636
		if(!$trigger_output->toBool()) return $trigger_output;
637
638
		$this->setSessionInfo();
639
		// Return result
640
		$this->add('member_srl', $args->member_srl);
641
		$this->setMessage('success_updated');
642
643
		$site_module_info = Context::get('site_module_info');
644
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
645
646
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberInfo');
647
		$this->setRedirectUrl($returnUrl);
648
	}
649
650
	/**
651
	 * Change the user password
652
	 *
653
	 * @return void|BaseObject (void : success, BaseObject : fail)
654
	 */
655
	function procMemberModifyPassword()
656
	{
657
		if(!Context::get('is_logged')) return $this->stop('msg_not_logged');
658
		// Extract the necessary information in advance
659
		$current_password = trim(Context::get('current_password'));
660
		$password = trim(Context::get('password1'));
661
		// Get information of logged-in user
662
		$logged_info = Context::get('logged_info');
663
		$member_srl = $logged_info->member_srl;
664
		// Create a member model object
665
		$oMemberModel = getModel('member');
666
		// Get information of member_srl
667
		$columnList = array('member_srl', 'password');
668
669
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
670
		// Verify the cuttent password
671
		if(!$oMemberModel->isValidPassword($member_info->password, $current_password, $member_srl)) return new BaseObject(-1, 'invalid_password');
672
673
		// Check if a new password is as same as the previous password
674
		if($current_password == $password) return new BaseObject(-1, 'invalid_new_password');
675
676
		// Execute insert or update depending on the value of member_srl
677
		$args = new stdClass;
678
		$args->member_srl = $member_srl;
679
		$args->password = $password;
680
		$output = $this->updateMemberPassword($args);
681
		if(!$output->toBool()) return $output;
682
683
		$this->add('member_srl', $args->member_srl);
684
		$this->setMessage('success_updated');
685
686
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberInfo');
687
		$this->setRedirectUrl($returnUrl);
688
	}
689
690
	/**
691
	 * Membership withdrawal
692
	 *
693
	 * @return void|BaseObject (void : success, BaseObject : fail)
694
	 */
695
	function procMemberLeave()
696
	{
697
		if(!Context::get('is_logged')) return $this->stop('msg_not_logged');
698
		// Extract the necessary information in advance
699
		$password = trim(Context::get('password'));
700
		// Get information of logged-in user
701
		$logged_info = Context::get('logged_info');
702
		$member_srl = $logged_info->member_srl;
703
		// Create a member model object
704
		$oMemberModel = getModel('member');
705
		// Get information of member_srl
706
		if(!$this->memberInfo->password)
707
		{
708
			$columnList = array('member_srl', 'password');
709
			$memberInfo = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
710
			$this->memberInfo->password = $memberInfo->password;
711
		}
712
		// Verify the cuttent password
713
		if(!$oMemberModel->isValidPassword($this->memberInfo->password, $password)) return new BaseObject(-1, 'invalid_password');
714
715
		$output = $this->deleteMember($member_srl);
716
		if(!$output->toBool()) return $output;
717
		// Destroy all session information
718
		$this->destroySessionInfo();
719
		// Return success message
720
		$this->setMessage('success_leaved');
721
722
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
723
		$this->setRedirectUrl($returnUrl);
724
	}
725
726
	/**
727
	 * Add a profile image
728
	 *
729
	 * @return void|BaseObject (void : success, BaseObject : fail)
730
	 */
731 View Code Duplication
	function procMemberInsertProfileImage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
732
	{
733
		// Check if the file is successfully uploaded
734
		$file = $_FILES['profile_image'];
735
		if(!is_uploaded_file($file['tmp_name'])) return $this->stop('msg_not_uploaded_profile_image');
736
		// Ignore if member_srl is invalid or doesn't exist.
737
		$member_srl = Context::get('member_srl');
738
		if(!$member_srl) return $this->stop('msg_not_uploaded_profile_image');
739
740
		$logged_info = Context::get('logged_info');
741
		if($logged_info->is_admin != 'Y' && $logged_info->member_srl != $member_srl) return $this->stop('msg_not_uploaded_profile_image');
742
		// Return if member module is set not to use an image name or the user is not an administrator ;
743
		$oMemberModel = getModel('member');
744
		$config = $oMemberModel->getMemberConfig();
745
		if($logged_info->is_admin != 'Y' && $config->profile_image != 'Y') return $this->stop('msg_not_uploaded_profile_image');
746
747
		$output = $this->insertProfileImage($member_srl, $file['tmp_name']);
748
		if(!$output->toBool()) return $output;
749
750
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
751
		$this->setRedirectUrl($returnUrl);
752
	}
753
754
	/**
755
	 * Insert a profile image
756
	 *
757
	 * @param int $member_srl
758
	 * @param object $target_file
759
	 *
760
	 * @return void
761
	 */
762
	function insertProfileImage($member_srl, $target_file)
763
	{
764
		$oMemberModel = getModel('member');
765
		$config = $oMemberModel->getMemberConfig();
766
		$max_width = $config->profile_image_max_width;
767
		$max_height = $config->profile_image_max_height;
768
		$max_filesize = $config->profile_image_max_filesize;
769
770
		Context::loadLang(_XE_PATH_ . 'modules/file/lang');
771
772
		// Get file information
773
		FileHandler::clearStatCache($target_file);
0 ignored issues
show
Documentation introduced by
$target_file is of type object, but the function expects a string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
774
		list($width, $height, $type) = @getimagesize($target_file);
775
		if(IMAGETYPE_PNG == $type) $ext = 'png';
776
		elseif(IMAGETYPE_JPEG == $type) $ext = 'jpg';
777
		elseif(IMAGETYPE_GIF == $type) $ext = 'gif';
778
		else
779
		{
780
			return $this->stop('msg_not_uploaded_profile_image');
781
		}
782
783
		$target_path = sprintf('files/member_extra_info/profile_image/%s', getNumberingPath($member_srl));
784
		FileHandler::makeDir($target_path);
785
786
		$target_filename = sprintf('%s%d.%s', $target_path, $member_srl, $ext);
787
788
		// Convert if the image size is larger than a given size or if the format is not a gif
789
		if(($width > $max_width || $height > $max_height ) && $type != 1)
790
		{
791
			$temp_filename = sprintf('files/cache/tmp/profile_image_%d.%s', $member_srl, $ext);
792
			FileHandler::createImageFile($target_file, $temp_filename, $max_width, $max_height, $ext);
0 ignored issues
show
Documentation introduced by
$target_file is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
793
794
			// 파일 용량 제한
795
			FileHandler::clearStatCache($temp_filename);
796
			$filesize = filesize($temp_filename);
797
			if($max_filesize && $filesize > ($max_filesize * 1024))
798
			{
799
				FileHandler::removeFile($temp_filename);
800
				return $this->stop(implode(' ' , array(
801
					Context::getLang('msg_not_uploaded_profile_image'),
802
					Context::getLang('msg_exceeds_limit_size')
803
				)));
804
			}
805
806
			FileHandler::removeFilesInDir($target_path);
807
			FileHandler::moveFile($temp_filename, $target_filename);
808
			FileHandler::clearStatCache($target_filename);
809
		}
810
		else
811
		{
812
			// 파일 용량 제한
813
			$filesize = filesize($target_file);
814
			if($max_filesize && $filesize > ($max_filesize * 1024))
815
			{
816
				return $this->stop(implode(' ' , array(
817
					Context::getLang('msg_not_uploaded_profile_image'),
818
					Context::getLang('msg_exceeds_limit_size')
819
				)));
820
			}
821
822
			FileHandler::removeFilesInDir($target_path);
823
			@copy($target_file, $target_filename);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
824
			FileHandler::clearStatCache($target_filename);
825
		}
826
827
		return new BaseObject(0, 'success');
828
	}
829
830
	/**
831
	 * Add an image name
832
	 *
833
	 * @return void|BaseObject (void : success, BaseObject : fail)
834
	 */
835 View Code Duplication
	function procMemberInsertImageName()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
836
	{
837
		// Check if the file is successfully uploaded
838
		$file = $_FILES['image_name'];
839
		if(!is_uploaded_file($file['tmp_name'])) return $this->stop('msg_not_uploaded_image_name');
840
		// Ignore if member_srl is invalid or doesn't exist.
841
		$member_srl = Context::get('member_srl');
842
		if(!$member_srl) return $this->stop('msg_not_uploaded_image_name');
843
844
		$logged_info = Context::get('logged_info');
845
		if($logged_info->is_admin != 'Y' && $logged_info->member_srl != $member_srl) return $this->stop('msg_not_uploaded_image_name');
846
		// Return if member module is set not to use an image name or the user is not an administrator ;
847
		$oMemberModel = getModel('member');
848
		$config = $oMemberModel->getMemberConfig();
849
		if($logged_info->is_admin != 'Y' && $config->image_name != 'Y') return $this->stop('msg_not_uploaded_image_name');
850
851
		$output = $this->insertImageName($member_srl, $file['tmp_name']);
852
		if(!$output->toBool()) return $output;
853
854
		// Page refresh
855
		//$this->setRefreshPage();
856
857
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
858
		$this->setRedirectUrl($returnUrl);
859
	}
860
861
	/**
862
	 * Insert a image name
863
	 *
864
	 * @param int $member_srl
865
	 * @param object $target_file
866
	 *
867
	 * @return void
868
	 */
869 View Code Duplication
	function insertImageName($member_srl, $target_file)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
870
	{
871
		$oMemberModel = getModel('member');
872
		$config = $oMemberModel->getMemberConfig();
873
		$max_width = $config->image_name_max_width;
874
		$max_height = $config->image_name_max_height;
875
		$max_filesize = $config->image_name_max_filesize;
876
877
		Context::loadLang(_XE_PATH_ . 'modules/file/lang');
878
879
		// Get a target path to save
880
		$target_path = sprintf('files/member_extra_info/image_name/%s/', getNumberingPath($member_srl));
881
		FileHandler::makeDir($target_path);
882
883
		$target_filename = sprintf('%s%d.gif', $target_path, $member_srl);
884
		// Get file information
885
		list($width, $height, $type) = @getimagesize($target_file);
886
		// Convert if the image size is larger than a given size or if the format is not a gif
887
		if($width > $max_width || $height > $max_height || $type!=1)
888
		{
889
			$temp_filename = sprintf('files/cache/tmp/image_name_%d.gif', $member_srl, $ext);
0 ignored issues
show
Bug introduced by
The variable $ext does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
890
			FileHandler::createImageFile($target_file, $temp_filename, $max_width, $max_height, 'gif');
0 ignored issues
show
Documentation introduced by
$target_file is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
891
892
			// 파일 용량 제한
893
			FileHandler::clearStatCache($temp_filename);
894
			$filesize = filesize($temp_filename);
895
			if($max_filesize && $filesize > ($max_filesize * 1024))
896
			{
897
				FileHandler::removeFile($temp_filename);
898
				return $this->stop(implode(' ' , array(
899
					Context::getLang('msg_not_uploaded_image_name'),
900
					Context::getLang('msg_exceeds_limit_size')
901
				)));
902
			}
903
904
			FileHandler::removeFilesInDir($target_path);
905
			FileHandler::moveFile($temp_filename, $target_filename);
906
			FileHandler::clearStatCache($target_filename);
907
		}
908
		else
909
		{
910
			// 파일 용량 제한
911
			$filesize = filesize($target_file);
912
			if($max_filesize && $filesize > ($max_filesize * 1024))
913
			{
914
				return $this->stop(implode(' ' , array(
915
					Context::getLang('msg_not_uploaded_image_name'),
916
					Context::getLang('msg_exceeds_limit_size')
917
				)));
918
			}
919
920
			FileHandler::removeFilesInDir($target_path);
921
			@copy($target_file, $target_filename);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
922
			FileHandler::clearStatCache($target_filename);
923
		}
924
925
		return new BaseObject(0, 'success');
926
	}
927
928
	/**
929
	 * Delete profile image
930
	 *
931
	 * @return BaseObject
932
	 */
933 View Code Duplication
	function procMemberDeleteProfileImage($_memberSrl = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
934
	{
935
		$member_srl = ($_memberSrl) ? $_memberSrl : Context::get('member_srl');
936
		if(!$member_srl)
937
		{
938
			return new BaseObject(0,'success');
939
		}
940
941
		$logged_info = Context::get('logged_info');
942
943
		if($logged_info && ($logged_info->is_admin == 'Y' || $logged_info->member_srl == $member_srl))
944
		{
945
			$oMemberModel = getModel('member');
946
			$profile_image = $oMemberModel->getProfileImage($member_srl);
947
			FileHandler::removeFile($profile_image->file);
948
		}
949
		return new BaseObject(0,'success');
950
	}
951
952
	/**
953
	 * Delete Image name
954
	 *
955
	 * @return void
956
	 */
957 View Code Duplication
	function procMemberDeleteImageName($_memberSrl = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
958
	{
959
		$member_srl = ($_memberSrl) ? $_memberSrl : Context::get('member_srl');
960
		if(!$member_srl)
961
		{
962
			return new BaseObject(0,'success');
963
		}
964
965
		$logged_info = Context::get('logged_info');
966
967
		if($logged_info && ($logged_info->is_admin == 'Y' || $logged_info->member_srl == $member_srl))
968
		{
969
			$oMemberModel = getModel('member');
970
			$image_name = $oMemberModel->getImageName($member_srl);
971
			FileHandler::removeFile($image_name->file);
972
		}
973
		return new BaseObject(0,'success');
974
	}
975
976
	/**
977
	 * Add an image to mark
978
	 *
979
	 * @return void|BaseObject (void : success, BaseObject : fail)
980
	 */
981 View Code Duplication
	function procMemberInsertImageMark()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
982
	{
983
		// Check if the file is successfully uploaded
984
		$file = $_FILES['image_mark'];
985
		if(!is_uploaded_file($file['tmp_name'])) return $this->stop('msg_not_uploaded_image_mark');
986
		// Ignore if member_srl is invalid or doesn't exist.
987
		$member_srl = Context::get('member_srl');
988
		if(!$member_srl) return $this->stop('msg_not_uploaded_image_mark');
989
990
		$logged_info = Context::get('logged_info');
991
		if($logged_info->is_admin != 'Y' && $logged_info->member_srl != $member_srl) return $this->stop('msg_not_uploaded_image_mark');
992
		// Membership in the images mark the module using the ban was set by an administrator or return;
993
		$oMemberModel = getModel('member');
994
		$config = $oMemberModel->getMemberConfig();
995
		if($logged_info->is_admin != 'Y' && $config->image_mark != 'Y') return $this->stop('msg_not_uploaded_image_mark');
996
997
		$this->insertImageMark($member_srl, $file['tmp_name']);
998
		if(!$output->toBool()) return $output;
0 ignored issues
show
Bug introduced by
The variable $output does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
999
1000
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
1001
		$this->setRedirectUrl($returnUrl);
1002
	}
1003
1004
	/**
1005
	 * Insert a image mark
1006
	 *
1007
	 * @param int $member_srl
1008
	 * @param object $target_file
1009
	 *
1010
	 * @return void
1011
	 */
1012 View Code Duplication
	function insertImageMark($member_srl, $target_file)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1013
	{
1014
		$oMemberModel = getModel('member');
1015
		$config = $oMemberModel->getMemberConfig();
1016
		$max_width = $config->image_mark_max_width;
1017
		$max_height = $config->image_mark_max_height;
1018
		$max_filesize = $config->image_mark_max_filesize;
1019
1020
		Context::loadLang(_XE_PATH_ . 'modules/file/lang');
1021
1022
		$target_path = sprintf('files/member_extra_info/image_mark/%s/', getNumberingPath($member_srl));
1023
		FileHandler::makeDir($target_path);
1024
1025
		$target_filename = sprintf('%s%d.gif', $target_path, $member_srl);
1026
		// Get file information
1027
		list($width, $height, $type, $attrs) = @getimagesize($target_file);
0 ignored issues
show
Unused Code introduced by
The assignment to $attrs is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1028
1029
		if($width > $max_width || $height > $max_height || $type!=1)
1030
		{
1031
			$temp_filename = sprintf('files/cache/tmp/image_mark_%d.gif', $member_srl);
1032
			FileHandler::createImageFile($target_file, $temp_filename, $max_width, $max_height, 'gif');
0 ignored issues
show
Documentation introduced by
$target_file is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1033
1034
			// 파일 용량 제한
1035
			FileHandler::clearStatCache($temp_filename);
1036
			$filesize = filesize($temp_filename);
1037
			if($max_filesize && $filesize > ($max_filesize * 1024))
1038
			{
1039
				FileHandler::removeFile($temp_filename);
1040
				return $this->stop(implode(' ' , array(
1041
					Context::getLang('msg_not_uploaded_group_image_mark'),
1042
					Context::getLang('msg_exceeds_limit_size')
1043
				)));
1044
			}
1045
1046
			FileHandler::removeFilesInDir($target_path);
1047
			FileHandler::moveFile($temp_filename, $target_filename);
1048
			FileHandler::clearStatCache($target_filename);
1049
		}
1050
		else
1051
		{
1052
			$filesize = filesize($target_file);
1053
			if($max_filesize && $filesize > ($max_filesize * 1024))
1054
			{
1055
				FileHandler::removeFile($target_file);
0 ignored issues
show
Documentation introduced by
$target_file is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1056
				return $this->stop(implode(' ' , array(
1057
					Context::getLang('msg_not_uploaded_group_image_mark'),
1058
					Context::getLang('msg_exceeds_limit_size')
1059
				)));
1060
			}
1061
1062
			FileHandler::removeFilesInDir($target_path);
1063
			@copy($target_file, $target_filename);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1064
			FileHandler::clearStatCache($target_filename);
1065
		}
1066
1067
		return new BaseObject(0, 'success');
1068
	}
1069
1070
	/**
1071
	 * Delete Image Mark
1072
	 *
1073
	 * @return BaseObject
1074
	 */
1075 View Code Duplication
	function procMemberDeleteImageMark($_memberSrl = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1076
	{
1077
		$member_srl = ($_memberSrl) ? $_memberSrl : Context::get('member_srl');
1078
		if(!$member_srl)
1079
		{
1080
			return new BaseObject(0,'success');
1081
		}
1082
1083
		$logged_info = Context::get('logged_info');
1084
1085
		if($logged_info && ($logged_info->is_admin == 'Y' || $logged_info->member_srl == $member_srl))
1086
		{
1087
			$oMemberModel = getModel('member');
1088
			$image_mark = $oMemberModel->getImageMark($member_srl);
1089
			FileHandler::removeFile($image_mark->file);
1090
		}
1091
		return new BaseObject(0,'success');
1092
	}
1093
1094
	/**
1095
	 * Find ID/Password
1096
	 *
1097
	 * @return BaseObject
1098
	 */
1099
	function procMemberFindAccount()
1100
	{
1101
		$email_address = Context::get('email_address');
1102
		if(!$email_address) return new BaseObject(-1, 'msg_invalid_request');
1103
1104
		$oMemberModel = getModel('member');
1105
		$oModuleModel = getModel('module');
1106
1107
		// Check if a member having the same email address exists
1108
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($email_address);
1109
		if(!$member_srl) return new BaseObject(-1, 'msg_email_not_exists');
1110
1111
		// Get information of the member
1112
		$columnList = array('denied', 'member_srl', 'user_id', 'user_name', 'email_address', 'nick_name');
1113
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
1114
1115
		// Check if possible to find member's ID and password
1116
		if($member_info->denied == 'Y')
1117
		{
1118
			$chk_args = new stdClass;
1119
			$chk_args->member_srl = $member_info->member_srl;
1120
			$output = executeQuery('member.chkAuthMail', $chk_args);
1121
			if($output->toBool() && $output->data->count != '0') return new BaseObject(-1, 'msg_user_not_confirmed');
1122
		}
1123
1124
		// Insert data into the authentication DB
1125
		$oPassword = new Password();
1126
		$args = new stdClass();
1127
		$args->user_id = $member_info->user_id;
1128
		$args->member_srl = $member_info->member_srl;
1129
		$args->new_password = $oPassword->createTemporaryPassword(8);
1130
		$args->auth_key = $oPassword->createSecureSalt(40);
1131
		$args->is_register = 'N';
1132
1133
		$output = executeQuery('member.insertAuthMail', $args);
1134
		if(!$output->toBool()) return $output;
1135
		// Get content of the email to send a member
1136
		Context::set('auth_args', $args);
1137
1138
		$member_config = $oModuleModel->getModuleConfig('member');
1139
		$memberInfo = array();
1140
		global $lang;
1141 View Code Duplication
		if(is_array($member_config->signupForm))
1142
		{
1143
			$exceptForm=array('password', 'find_account_question');
1144
			foreach($member_config->signupForm as $form)
1145
			{
1146
				if(!in_array($form->name, $exceptForm) && $form->isDefaultForm && ($form->required || $form->mustRequired))
1147
				{
1148
					$memberInfo[$lang->{$form->name}] = $member_info->{$form->name};
1149
				}
1150
			}
1151
		}
1152
		else
1153
		{
1154
			$memberInfo[$lang->user_id] = $args->user_id;
1155
			$memberInfo[$lang->user_name] = $args->user_name;
1156
			$memberInfo[$lang->nick_name] = $args->nick_name;
1157
			$memberInfo[$lang->email_address] = $args->email_address;
1158
		}
1159
		Context::set('memberInfo', $memberInfo);
1160
1161
		if(!$member_config->skin) $member_config->skin = "default";
1162
		if(!$member_config->colorset) $member_config->colorset = "white";
1163
1164
		Context::set('member_config', $member_config);
1165
1166
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
1167
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
1168
1169
		$find_url = getFullUrl ('', 'module', 'member', 'act', 'procMemberAuthAccount', 'member_srl', $member_info->member_srl, 'auth_key', $args->auth_key);
1170
		Context::set('find_url', $find_url);
1171
1172
		$oTemplate = &TemplateHandler::getInstance();
1173
		$content = $oTemplate->compile($tpl_path, 'find_member_account_mail');
1174
		// Get information of the Webmaster
1175
		$oModuleModel = getModel('module');
1176
		$member_config = $oModuleModel->getModuleConfig('member');
1177
		// Send a mail
1178
		$oMail = new Mail();
1179
		$oMail->setTitle( Context::getLang('msg_find_account_title') );
1180
		$oMail->setContent($content);
1181
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
1182
		$oMail->setReceiptor( $member_info->user_name, $member_info->email_address );
1183
		$oMail->send();
1184
		// Return message
1185
		$msg = sprintf(Context::getLang('msg_auth_mail_sent'), $member_info->email_address);
1186 View Code Duplication
		if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON')))
1187
		{
1188
			$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberFindAccount');
1189
			$this->setRedirectUrl($returnUrl);
1190
		}
1191
		return new BaseObject(0,$msg);
1192
	}
1193
1194
	/**
1195
	 * Generate a temp password by answering to the pre-determined question
1196
	 *
1197
	 * @return void|BaseObject (void : success, BaseObject : fail)
1198
	 */
1199
	function procMemberFindAccountByQuestion()
1200
	{
1201
		$oMemberModel = getModel('member');
1202
		$oPassword =  new Password();
1203
		$config = $oMemberModel->getMemberConfig();
1204
1205
		$email_address = Context::get('email_address');
1206
		$user_id = Context::get('user_id');
1207
		$find_account_question = trim(Context::get('find_account_question'));
1208
		$find_account_answer = trim(Context::get('find_account_answer'));
1209
1210
		if(($config->identifier == 'user_id' && !$user_id) || !$email_address || !$find_account_question || !$find_account_answer) return new BaseObject(-1, 'msg_invalid_request');
1211
1212
		$oModuleModel = getModel('module');
0 ignored issues
show
Unused Code introduced by
$oModuleModel is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1213
		// Check if a member having the same email address exists
1214
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($email_address);
1215
		if(!$member_srl) return new BaseObject(-1, 'msg_email_not_exists');
1216
1217
		// Get information of the member
1218
		$columnList = array('member_srl', 'find_account_question', 'find_account_answer');
1219
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
1220
1221
		// Display a message if no answer is entered
1222
		if(!$member_info->find_account_question || !$member_info->find_account_answer) return new BaseObject(-1, 'msg_question_not_exists');
1223
1224
		// 답변 확인
1225
		$hashed = $oPassword->checkAlgorithm($member_info->find_account_answer);
1226
		$authed = true;
1227
		$member_info->find_account_question = trim($member_info->find_account_question);
1228
		if($member_info->find_account_question != $find_account_question)
1229
		{
1230
			$authed = false;
1231
		}
1232
		else if($hashed && !$oPassword->checkPassword($find_account_answer, $member_info->find_account_answer))
0 ignored issues
show
Bug Best Practice introduced by
The expression $hashed of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1233
		{
1234
			$authed = false;
1235
		}
1236
		else if(!$hashed && $find_account_answer != $member_info->find_account_answer)
0 ignored issues
show
Bug Best Practice introduced by
The expression $hashed of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1237
		{
1238
			$authed = false;
1239
		}
1240
1241
		if(!$authed)
1242
		{
1243
			return new BaseObject(-1, 'msg_answer_not_matches');
1244
		}
1245
1246
		// answer가 동일하고 hash 되지 않았으면 hash 값으로 저장
1247
		if($authed && !$hashed)
0 ignored issues
show
Bug Best Practice introduced by
The expression $hashed of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1248
		{
1249
			$this->updateFindAccountAnswer($member_srl, $find_account_answer);
1250
		}
1251
1252
		if($config->identifier == 'email_address')
1253
		{
1254
			$user_id = $email_address;
1255
		}
1256
1257
		// Update to a temporary password and set change_password_date to 1
1258
		$temp_password = $oPassword->createTemporaryPassword(8);
1259
1260
		$args = new stdClass();
1261
		$args->member_srl = $member_srl;
1262
		$args->password = $temp_password;
1263
		$args->change_password_date = '1';
1264
		$output = $this->updateMemberPassword($args);
1265
		if(!$output->toBool()) return $output;
1266
1267
		$_SESSION['xe_temp_password_' . $user_id] = $temp_password;
1268
1269
		$this->add('user_id',$user_id);
1270
1271
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
1272
		$this->setRedirectUrl($returnUrl.'&user_id='.$user_id);
1273
	}
1274
1275
	/**
1276
	 * Execute finding ID/Passoword
1277
	 * When clicking the link in the verification email, a method is called to change the old password and to authenticate it
1278
	 *
1279
	 * @return void|BaseObject (void : success, BaseObject : fail)
1280
	 */
1281
	function procMemberAuthAccount()
1282
	{
1283
		$oMemberModel = getModel('member');
1284
1285
		// Test user_id and authkey
1286
		$member_srl = Context::get('member_srl');
1287
		$auth_key = Context::get('auth_key');
1288
1289
		if(!$member_srl || !$auth_key)
1290
		{
1291
			return $this->stop('msg_invalid_request');
1292
		}
1293
1294
		// Test logs for finding password by user_id and authkey
1295
		$args = new stdClass;
1296
		$args->member_srl = $member_srl;
1297
		$args->auth_key = $auth_key;
1298
		$output = executeQuery('member.getAuthMail', $args);
1299
1300 View Code Duplication
		if(!$output->toBool() || $output->data->auth_key != $auth_key)
1301
		{
1302
			if(strlen($output->data->auth_key) !== strlen($auth_key))
1303
			{
1304
				executeQuery('member.deleteAuthMail', $args);
1305
			}
1306
1307
			return $this->stop('msg_invalid_auth_key');
1308
		}
1309
1310
		if(ztime($output->data->regdate) < $_SERVER['REQUEST_TIME'] + zgap() - 86400)
1311
		{
1312
			executeQuery('member.deleteAuthMail', $args);
1313
			return $this->stop('msg_invalid_auth_key');
1314
		}
1315
1316
		$args->password = $output->data->new_password;
1317
1318
		// If credentials are correct, change the password to a new one
1319
		if($output->data->is_register == 'Y')
1320
		{
1321
			$args->denied = 'N';
1322
		}
1323
		else
1324
		{
1325
			$args->password = $oMemberModel->hashPassword($args->password);
1326
		}
1327
1328
		// Back up the value of $Output->data->is_register
1329
		$is_register = $output->data->is_register;
1330
1331
		$output = executeQuery('member.updateMemberPassword', $args);
1332
		if(!$output->toBool())
1333
		{
1334
			return $this->stop($output->getMessage());
1335
		}
1336
1337
		// Remove all values having the member_srl from authentication table
1338
		executeQuery('member.deleteAuthMail',$args);
1339
1340
		$this->_clearMemberCache($args->member_srl);
1341
1342
		// Notify the result
1343
		Context::set('is_register', $is_register);
1344
		$this->setTemplatePath($this->module_path.'tpl');
1345
		$this->setTemplateFile('msg_success_authed');
1346
	}
1347
1348
	/**
1349
	 * Request to re-send the authentication mail
1350
	 *
1351
	 * @return void|BaseObject (void : success, BaseObject : fail)
1352
	 */
1353
	function procMemberResendAuthMail()
1354
	{
1355
		// Get an email_address
1356
		$email_address = Context::get('email_address');
1357
		if(!$email_address) return new BaseObject(-1, 'msg_invalid_request');
1358
		// Log test by using email_address
1359
		$oMemberModel = getModel('member');
1360
1361
		$args = new stdClass;
1362
		$args->email_address = $email_address;
1363
		$memberSrl = $oMemberModel->getMemberSrlByEmailAddress($email_address);
1364
		if(!$memberSrl) return new BaseObject(-1, 'msg_not_exists_member');
1365
1366
		$columnList = array('member_srl', 'user_id', 'user_name', 'nick_name', 'email_address');
1367
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($memberSrl, 0, $columnList);
1368
1369
		$oModuleModel = getModel('module');
1370
		$member_config = $oModuleModel->getModuleConfig('member');
1371
		if(!$member_config->skin) $member_config->skin = "default";
1372
		if(!$member_config->colorset) $member_config->colorset = "white";
1373
1374
		// Check if a authentication mail has been sent previously
1375
		$chk_args = new stdClass;
1376
		$chk_args->member_srl = $member_info->member_srl;
1377
		$output = executeQuery('member.chkAuthMail', $chk_args);
1378
		if($output->toBool() && $output->data->count == '0') return new BaseObject(-1, 'msg_invalid_request');
1379
1380
		$auth_args = new stdClass;
1381
		$auth_args->member_srl = $member_info->member_srl;
1382
		$output = executeQueryArray('member.getAuthMailInfo', $auth_args);
1383
		if(!$output->data || !$output->data[0]->auth_key)  return new BaseObject(-1, 'msg_invalid_request');
1384
		$auth_info = $output->data[0];
1385
1386
		// Update the regdate of authmail entry
1387
		$renewal_args = new stdClass;
1388
		$renewal_args->member_srl = $member_info->member_srl;
1389
		$renewal_args->auth_key = $auth_info->auth_key;
1390
		$output = executeQuery('member.updateAuthMail', $renewal_args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1391
1392
		$memberInfo = array();
1393
		global $lang;
1394 View Code Duplication
		if(is_array($member_config->signupForm))
1395
		{
1396
			$exceptForm=array('password', 'find_account_question');
1397
			foreach($member_config->signupForm as $form)
1398
			{
1399
				if(!in_array($form->name, $exceptForm) && $form->isDefaultForm && ($form->required || $form->mustRequired))
1400
				{
1401
					$memberInfo[$lang->{$form->name}] = $member_info->{$form->name};
1402
				}
1403
			}
1404
		}
1405
		else
1406
		{
1407
			$memberInfo[$lang->user_id] = $member_info->user_id;
1408
			$memberInfo[$lang->user_name] = $member_info->user_name;
1409
			$memberInfo[$lang->nick_name] = $member_info->nick_name;
1410
			$memberInfo[$lang->email_address] = $member_info->email_address;
1411
		}
1412
1413
		// Get content of the email to send a member
1414
		Context::set('memberInfo', $memberInfo);
1415
		Context::set('member_config', $member_config);
1416
1417
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
1418
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
1419
1420
		$auth_url = getFullUrl('','module','member','act','procMemberAuthAccount','member_srl',$member_info->member_srl, 'auth_key',$auth_info->auth_key);
1421
		Context::set('auth_url', $auth_url);
1422
1423
		$oTemplate = &TemplateHandler::getInstance();
1424
		$content = $oTemplate->compile($tpl_path, 'confirm_member_account_mail');
1425
		// Send a mail
1426
		$oMail = new Mail();
1427
		$oMail->setTitle( Context::getLang('msg_confirm_account_title') );
1428
		$oMail->setContent($content);
1429
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
1430
		$oMail->setReceiptor( $args->user_name, $args->email_address );
1431
		$oMail->send();
1432
1433
		$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $args->email_address);
1434
		$this->setMessage($msg);
1435
1436
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
1437
		$this->setRedirectUrl($returnUrl);
1438
	}
1439
1440
	function procMemberResetAuthMail()
1441
	{
1442
		$memberInfo = $_SESSION['auth_member_info'];
1443
		unset($_SESSION['auth_member_info']);
1444
1445
		if(!$memberInfo)
1446
		{
1447
			return $this->stop('msg_invalid_request');
1448
		}
1449
1450
		$newEmail = Context::get('email_address');
1451
1452
		if(!$newEmail)
1453
		{
1454
			return $this->stop('msg_invalid_request');
1455
		}
1456
1457
		$oMemberModel = getModel('member');
1458
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($newEmail);
1459
		if($member_srl)
1460
		{
1461
			return new BaseObject(-1,'msg_exists_email_address');
1462
		}
1463
1464
		// remove all key by member_srl
1465
		$args = new stdClass;
1466
		$args->member_srl = $memberInfo->member_srl;
1467
		$output = executeQuery('member.deleteAuthMail', $args);
1468
1469
		if(!$output->toBool())
1470
		{
1471
			return $output;
1472
		}
1473
1474
		// update member info
1475
		$args->email_address = $newEmail;
1476
		list($args->email_id, $args->email_host) = explode('@', $newEmail);
1477
1478
		$output = executeQuery('member.updateMemberEmailAddress', $args);
1479
		if(!$output->toBool())
1480
		{
1481
			return $this->stop($output->getMessage());
1482
		}
1483
1484
		$this->_clearMemberCache($args->member_srl);
1485
1486
		// generate new auth key
1487
		$oPassword = new Password();
1488
		$auth_args = new stdClass();
1489
		$auth_args->user_id = $memberInfo->user_id;
1490
		$auth_args->member_srl = $memberInfo->member_srl;
1491
		$auth_args->new_password = $memberInfo->password;
1492
		$auth_args->auth_key = $oPassword->createSecureSalt(40);
1493
		$auth_args->is_register = 'Y';
1494
1495
		$output = executeQuery('member.insertAuthMail', $auth_args);
1496
		if(!$output->toBool()) return $output;
1497
1498
		$memberInfo->email_address = $newEmail;
1499
1500
		// resend auth mail.
1501
		$this->_sendAuthMail($auth_args, $memberInfo);
1502
1503
		$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $memberInfo->email_address);
1504
		$this->setMessage($msg);
1505
1506
		$returnUrl = getUrl('');
1507
		$this->setRedirectUrl($returnUrl);
1508
	}
1509
1510
	function _sendAuthMail($auth_args, $member_info)
1511
	{
1512
		$oMemberModel = getModel('member');
1513
		$member_config = $oMemberModel->getMemberConfig();
1514
		// Get content of the email to send a member
1515
		Context::set('auth_args', $auth_args);
1516
1517
		$memberInfo = array();
1518
1519
		global $lang;
1520 View Code Duplication
		if(is_array($member_config->signupForm))
1521
		{
1522
			$exceptForm=array('password', 'find_account_question');
1523
			foreach($member_config->signupForm as $form)
1524
			{
1525
				if(!in_array($form->name, $exceptForm) && $form->isDefaultForm && ($form->required || $form->mustRequired))
1526
				{
1527
					$memberInfo[$lang->{$form->name}] = $member_info->{$form->name};
1528
				}
1529
			}
1530
		}
1531
		else
1532
		{
1533
			$memberInfo[$lang->user_id] = $member_info->user_id;
1534
			$memberInfo[$lang->user_name] = $member_info->user_name;
1535
			$memberInfo[$lang->nick_name] = $member_info->nick_name;
1536
			$memberInfo[$lang->email_address] = $member_info->email_address;
1537
		}
1538
		Context::set('memberInfo', $memberInfo);
1539
1540
		if(!$member_config->skin) $member_config->skin = "default";
1541
		if(!$member_config->colorset) $member_config->colorset = "white";
1542
1543
		Context::set('member_config', $member_config);
1544
1545
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
1546
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
1547
1548
		$auth_url = getFullUrl('','module','member','act','procMemberAuthAccount','member_srl',$member_info->member_srl, 'auth_key',$auth_args->auth_key);
1549
		Context::set('auth_url', $auth_url);
1550
1551
		$oTemplate = &TemplateHandler::getInstance();
1552
		$content = $oTemplate->compile($tpl_path, 'confirm_member_account_mail');
1553
		// Send a mail
1554
		$oMail = new Mail();
1555
		$oMail->setTitle( Context::getLang('msg_confirm_account_title') );
1556
		$oMail->setContent($content);
1557
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
1558
		$oMail->setReceiptor( $member_info->user_name, $member_info->email_address );
1559
		$oMail->send();
1560
	}
1561
1562
	/**
1563
	 * Join a virtual site
1564
	 *
1565
	 * @return void|BaseObject (void : success, BaseObject : fail)
1566
	 */
1567
	function procMemberSiteSignUp()
1568
	{
1569
		$site_module_info = Context::get('site_module_info');
1570
		$logged_info = Context::get('logged_info');
1571 View Code Duplication
		if(!$site_module_info->site_srl || !Context::get('is_logged') || count($logged_info->group_srl_list) ) return new BaseObject(-1,'msg_invalid_request');
1572
1573
		$oMemberModel = getModel('member');
1574
		$columnList = array('site_srl', 'group_srl', 'title');
1575
		$default_group = $oMemberModel->getDefaultGroup($site_module_info->site_srl, $columnList);
1576
		$this->addMemberToGroup($logged_info->member_srl, $default_group->group_srl, $site_module_info->site_srl);
1577
		$groups[$default_group->group_srl] = $default_group->title;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$groups was never initialized. Although not strictly required by PHP, it is generally a good practice to add $groups = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1578
		$logged_info->group_list = $groups;
1579
	}
1580
1581
	/**
1582
	 * Leave the virtual site
1583
	 *
1584
	 * @return void|BaseObject (void : success, BaseObject : fail)
1585
	 */
1586
	function procMemberSiteLeave()
1587
	{
1588
		$site_module_info = Context::get('site_module_info');
1589
		$logged_info = Context::get('logged_info');
1590 View Code Duplication
		if(!$site_module_info->site_srl || !Context::get('is_logged') || count($logged_info->group_srl_list) ) return new BaseObject(-1,'msg_invalid_request');
1591
1592
		$args = new stdClass;
1593
		$args->site_srl= $site_module_info->site_srl;
1594
		$args->member_srl = $logged_info->member_srl;
1595
		$output = executeQuery('member.deleteMembersGroup', $args);
1596
		if(!$output->toBool()) return $output;
1597
		$this->setMessage('success_deleted');
1598
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
1599
	}
1600
1601
	/**
1602
	 * Save the member configurations
1603
	 *
1604
	 * @param object $args
1605
	 *
1606
	 * @return void
1607
	 */
1608
	function setMemberConfig($args)
1609
	{
1610
		if(!$args->skin) $args->skin = "default";
1611
		if(!$args->colorset) $args->colorset = "white";
1612
		if(!$args->editor_skin) $args->editor_skin= "ckeditor";
1613
		if(!$args->editor_colorset) $args->editor_colorset = "moono";
1614
		if($args->enable_join!='Y') $args->enable_join = 'N';
1615
		$args->enable_openid= 'N';
1616
		if($args->profile_image !='Y') $args->profile_image = 'N';
1617
		if($args->image_name!='Y') $args->image_name = 'N';
1618
		if($args->image_mark!='Y') $args->image_mark = 'N';
1619
		if($args->group_image_mark!='Y') $args->group_image_mark = 'N';
1620
		if(!trim(strip_tags($args->agreement))) $args->agreement = null;
1621
		$args->limit_day = (int)$args->limit_day;
1622
1623
		$agreement = trim($args->agreement);
1624
		unset($args->agreement);
1625
1626
		$oModuleController = getController('module');
1627
		$output = $oModuleController->insertModuleConfig('member',$args);
1628
		if(!$output->toBool()) return $output;
1629
1630
		$agreement_file = _XE_PATH_.'files/member_extra_info/agreement.txt';
1631
		FileHandler::writeFile($agreement_file, $agreement);
1632
1633
		return new BaseObject();
1634
	}
1635
1636
	/**
1637
	 * Save the signature as a file
1638
	 *
1639
	 * @param int $member_srl
1640
	 * @param string $signature
1641
	 *
1642
	 * @return void
1643
	 */
1644
	function putSignature($member_srl, $signature)
1645
	{
1646
		$signature = trim(removeHackTag($signature));
1647
		$signature = preg_replace('/<(\/?)(embed|object|param)/is', '&lt;$1$2', $signature);
1648
1649
		$check_signature = trim(str_replace(array('&nbsp;',"\n","\r"), '', strip_tags($signature, '<img><object>')));
1650
		$path = sprintf('files/member_extra_info/signature/%s/', getNumberingPath($member_srl));
1651
		$filename = sprintf('%s%d.signature.php', $path, $member_srl);
1652
1653
		if(!$check_signature) return FileHandler::removeFile($filename);
1654
1655
		$buff = sprintf('<?php if(!defined("__XE__")) exit();?>%s', $signature);
1656
		FileHandler::makeDir($path);
1657
		FileHandler::writeFile($filename, $buff);
1658
	}
1659
1660
	/**
1661
	 * Delete the signature file
1662
	 *
1663
	 * @param string $member_srl
1664
	 *
1665
	 * @return void
1666
	 */
1667
	function delSignature($member_srl)
1668
	{
1669
		$filename = sprintf('files/member_extra_info/signature/%s%d.gif', getNumberingPath($member_srl), $member_srl);
1670
		FileHandler::removeFile($filename);
1671
	}
1672
1673
	/**
1674
	 * Add group_srl to member_srl
1675
	 *
1676
	 * @param int $member_srl
1677
	 * @param int $group_srl
1678
	 * @param int $site_srl
1679
	 *
1680
	 * @return BaseObject
1681
	 */
1682
	function addMemberToGroup($member_srl, $group_srl, $site_srl=0)
1683
	{
1684
		$args = new stdClass();
1685
		$args->member_srl = $member_srl;
1686
		$args->group_srl = $group_srl;
1687
		if($site_srl) $args->site_srl = $site_srl;
1688
1689
		// Add
1690
		$output = executeQuery('member.addMemberToGroup',$args);
1691
		$output2 = ModuleHandler::triggerCall('member.addMemberToGroup', 'after', $args);
0 ignored issues
show
Unused Code introduced by
$output2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1692
1693
		$this->_clearMemberCache($member_srl, $site_srl);
1694
1695
		return $output;
1696
	}
1697
1698
	/**
1699
	 * Change a group of certain members
1700
	 * Available only when a member has a single group
1701
	 *
1702
	 * @param object $args
1703
	 *
1704
	 * @return BaseObject
1705
	 */
1706
	function replaceMemberGroup($args)
1707
	{
1708
		$obj = new stdClass;
1709
		$obj->site_srl = $args->site_srl;
1710
		$obj->member_srl = implode(',',$args->member_srl);
1711
1712
		$output = executeQueryArray('member.getMembersGroup', $obj);
1713
		if($output->data) foreach($output->data as $key => $val) $date[$val->member_srl] = $val->regdate;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$date was never initialized. Although not strictly required by PHP, it is generally a good practice to add $date = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1714
1715
		$output = executeQuery('member.deleteMembersGroup', $obj);
1716
		if(!$output->toBool()) return $output;
1717
1718
		$inserted_members = array();
1719
		foreach($args->member_srl as $key => $val)
1720
		{
1721
			if($inserted_members[$val]) continue;
1722
			$inserted_members[$val] = true;
1723
1724
			unset($obj);
1725
			$obj = new stdClass;
1726
			$obj->member_srl = $val;
1727
			$obj->group_srl = $args->group_srl;
1728
			$obj->site_srl = $args->site_srl;
1729
			$obj->regdate = $date[$obj->member_srl];
0 ignored issues
show
Bug introduced by
The variable $date does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1730
			$output = executeQuery('member.addMemberToGroup', $obj);
1731
			if(!$output->toBool()) return $output;
1732
1733
			$this->_clearMemberCache($obj->member_srl, $args->site_srl);
1734
		}
1735
1736
		return new BaseObject();
1737
	}
1738
1739
1740
	/**
1741
	 * Auto-login
1742
	 *
1743
	 * @return void
1744
	 */
1745
	function doAutologin()
1746
	{
1747
		// Get a key value of auto log-in
1748
		$args = new stdClass;
1749
		$args->autologin_key = $_COOKIE['xeak'];
1750
		// Get information of the key
1751
		$output = executeQuery('member.getAutologin', $args);
1752
		// If no information exists, delete a cookie
1753 View Code Duplication
		if(!$output->toBool() || !$output->data)
1754
		{
1755
			setCookie('xeak',null,$_SERVER['REQUEST_TIME']+60*60*24*365);
1756
			return;
1757
		}
1758
1759
		$oMemberModel = getModel('member');
1760
		$config = $oMemberModel->getMemberConfig();
1761
1762
		$user_id = ($config->identifier == 'user_id') ? $output->data->user_id : $output->data->email_address;
1763
		$password = $output->data->password;
1764
1765 View Code Duplication
		if(!$user_id || !$password)
1766
		{
1767
			setCookie('xeak',null,$_SERVER['REQUEST_TIME']+60*60*24*365);
1768
			return;
1769
		}
1770
1771
		$do_auto_login = false;
1772
1773
		// Compare key values based on the information
1774
		$check_key = strtolower($user_id).$password.$_SERVER['HTTP_USER_AGENT'];
1775
		$check_key = substr(hash_hmac('sha256', $check_key, substr($args->autologin_key, 0, 32)), 0, 32);
1776
1777
		if($check_key === substr($args->autologin_key, 32))
1778
		{
1779
			// Check change_password_date
1780
			$oModuleModel = getModel('module');
1781
			$member_config = $oModuleModel->getModuleConfig('member');
1782
			$limit_date = $member_config->change_password_date;
1783
1784
			// Check if change_password_date is set
1785
			if($limit_date > 0)
1786
			{
1787
				$oMemberModel = getModel('member');
1788
				$columnList = array('member_srl', 'change_password_date');
1789
1790
				if($config->identifier == 'user_id')
1791
				{
1792
					$member_info = $oMemberModel->getMemberInfoByUserID($user_id, $columnList);
1793
				}
1794
				else
1795
				{
1796
					$member_info = $oMemberModel->getMemberInfoByEmailAddress($user_id, $columnList);
1797
				}
1798
1799
				if($member_info->change_password_date >= date('YmdHis', strtotime('-'.$limit_date.' day')) ){
1800
					$do_auto_login = true;
1801
				}
1802
1803
			}
1804
			else
1805
			{
1806
				$do_auto_login = true;
1807
			}
1808
		}
1809
1810
		if($do_auto_login)
1811
		{
1812
			$output = $this->doLogin($user_id);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1813
		}
1814
		else
1815
		{
1816
			executeQuery('member.deleteAutologin', $args);
1817
			setCookie('xeak',null,$_SERVER['REQUEST_TIME']+60*60*24*365);
1818
		}
1819
	}
1820
1821
	/**
1822
	 * Log-in
1823
	 *
1824
	 * @param string $user_id
1825
	 * @param string $password
1826
	 * @param boolean $keep_signed
1827
	 *
1828
	 * @return BaseObject
1829
	 */
1830
	function doLogin($user_id, $password = '', $keep_signed = false)
1831
	{
1832
		$user_id = strtolower($user_id);
1833
		if(!$user_id) return new BaseObject(-1, 'null_user_id');
1834
		// Call a trigger before log-in (before)
1835
		$trigger_obj = new stdClass();
1836
		$trigger_obj->user_id = $user_id;
1837
		$trigger_obj->password = $password;
1838
		$trigger_output = ModuleHandler::triggerCall('member.doLogin', 'before', $trigger_obj);
1839
		if(!$trigger_output->toBool()) return $trigger_output;
1840
		// Create a member model object
1841
		$oMemberModel = getModel('member');
1842
1843
		// check IP access count.
1844
		$config = $oMemberModel->getMemberConfig();
1845
		$args = new stdClass();
1846
		$args->ipaddress = $_SERVER['REMOTE_ADDR'];
1847
1848
		// check identifier
1849
		if($config->identifier == 'email_address')
1850
		{
1851
			// Get user_id information
1852
			$this->memberInfo = $oMemberModel->getMemberInfoByEmailAddress($user_id);
1853
			// Set an invalid user if no value returned
1854
			if(!$user_id || strtolower($this->memberInfo->email_address) != strtolower($user_id)) return $this->recordLoginError(-1, 'invalid_email_address');
1855
1856
		}
1857
		else
1858
		{
1859
			// Get user_id information
1860
			$this->memberInfo = $oMemberModel->getMemberInfoByUserID($user_id);
1861
			// Set an invalid user if no value returned
1862
			if(!$user_id || strtolower($this->memberInfo->user_id) != strtolower($user_id)) return $this->recordLoginError(-1, 'invalid_user_id');
1863
		}
1864
1865
		$output = executeQuery('member.getLoginCountByIp', $args);
1866
		$errorCount = $output->data->count;
1867
		if($errorCount >= $config->max_error_count)
1868
		{
1869
			$last_update = strtotime($output->data->last_update);
1870
			$term = intval($_SERVER['REQUEST_TIME']-$last_update);
1871
			if($term < $config->max_error_count_time)
1872
			{
1873
				$term = $config->max_error_count_time - $term;
1874
				if($term < 60) $term = intval($term).Context::getLang('unit_sec');
1875
				elseif(60 <= $term && $term < 3600) $term = intval($term/60).Context::getLang('unit_min');
1876
				elseif(3600 <= $term && $term < 86400) $term = intval($term/3600).Context::getLang('unit_hour');
1877
				else $term = intval($term/86400).Context::getLang('unit_day');
1878
1879
				return new BaseObject(-1, sprintf(Context::getLang('excess_ip_access_count'),$term));
1880
			}
1881
			else
1882
			{
1883
				$args->ipaddress = $_SERVER['REMOTE_ADDR'];
1884
				$output = executeQuery('member.deleteLoginCountByIp', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1885
			}
1886
		}
1887
1888
		// Password Check
1889
		if($password && !$oMemberModel->isValidPassword($this->memberInfo->password, $password, $this->memberInfo->member_srl))
1890
		{
1891
			return $this->recordMemberLoginError(-1, 'invalid_password',$this->memberInfo);
1892
		}
1893
1894
		// If denied == 'Y', notify
1895
		if($this->memberInfo->denied == 'Y')
1896
		{
1897
			$args->member_srl = $this->memberInfo->member_srl;
1898
			$output = executeQuery('member.chkAuthMail', $args);
1899
			if ($output->toBool() && $output->data->count != '0')
1900
			{
1901
				$_SESSION['auth_member_srl'] = $this->memberInfo->member_srl;
1902
				$redirectUrl = getUrl('', 'act', 'dispMemberResendAuthMail');
1903
				return $this->setRedirectUrl($redirectUrl, new BaseObject(-1,'msg_user_not_confirmed'));
1904
			}
1905
			return new BaseObject(-1,'msg_user_denied');
1906
		}
1907
		// Notify if denied_date is less than the current time
1908
		if($this->memberInfo->limit_date && substr($this->memberInfo->limit_date,0,8) >= date("Ymd")) return new BaseObject(-9,sprintf(Context::getLang('msg_user_limited'),zdate($this->memberInfo->limit_date,"Y-m-d")));
1909
		// Update the latest login time
1910
		$args->member_srl = $this->memberInfo->member_srl;
1911
		$output = executeQuery('member.updateLastLogin', $args);
1912
1913
		$site_module_info = Context::get('site_module_info');
1914
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
1915
1916
		// Check if there is recoding table.
1917
		$oDB = &DB::getInstance();
1918
		if($oDB->isTableExists('member_count_history') && $config->enable_login_fail_report != 'N')
1919
		{
1920
			// check if there is login fail records.
1921
			$output = executeQuery('member.getLoginCountHistoryByMemberSrl', $args);
1922
			if($output->data && $output->data->content)
1923
			{
1924
				$title = Context::getLang('login_fail_report');
1925
				$message = '<ul>';
1926
				$content = unserialize($output->data->content);
1927
				if(count($content) > $config->max_error_count)
1928
				{
1929
					foreach($content as $val)
1930
					{
1931
						$message .= '<li>'.Context::getLang('regdate').': '.date('Y-m-d h:i:sa',$val[2]).'<ul><li>'.Context::getLang('ipaddress').': '.$val[0].'</li><li>'.Context::getLang('message').': '.$val[1].'</li></ul></li>';
1932
					}
1933
					$message .= '</ul>';
1934
					$content = sprintf(Context::getLang('login_fail_report_contents'),$message,date('Y-m-d h:i:sa'));
1935
1936
					//send message
1937
					$oCommunicationController = getController('communication');
1938
					$oCommunicationController->sendMessage($args->member_srl, $args->member_srl, $title, $content, true);
1939
1940
					if($this->memberInfo->email_address && $this->memberInfo->allow_mailing == 'Y')
1941
					{
1942
						$view_url = Context::getRequestUri();
1943
						$content = sprintf("%s<hr /><p>From: <a href=\"%s\" target=\"_blank\">%s</a><br />To: %s(%s)</p>",$content, $view_url, $view_url, $this->memberInfo->nick_name, $this->memberInfo->email_id);
1944
						$oMail = new Mail();
1945
						$oMail->setTitle($title);
1946
						$oMail->setContent($content);
1947
						$oMail->setSender($config->webmaster_name?$config->webmaster_name:'webmaster', $config->webmaster_email);
1948
						$oMail->setReceiptor($this->memberInfo->email_id.'('.$this->memberInfo->nick_name.')', $this->memberInfo->email_address);
1949
						$oMail->send();
1950
					}
1951
					$output = executeQuery('member.deleteLoginCountHistoryByMemberSrl', $args);
1952
				}
1953
			}
1954
		}
1955
		// Call a trigger after successfully log-in (after)
1956
		$trigger_output = ModuleHandler::triggerCall('member.doLogin', 'after', $this->memberInfo);
1957
		if(!$trigger_output->toBool()) return $trigger_output;
1958
		// When user checked to use auto-login
1959
		if($keep_signed)
1960
		{
1961
			// Key generate for auto login
1962
			$oPassword = new Password();
1963
			$random_key = $oPassword->createSecureSalt(32, 'hex');
1964
			$extra_key = strtolower($user_id).$this->memberInfo->password.$_SERVER['HTTP_USER_AGENT'];
1965
			$extra_key = substr(hash_hmac('sha256', $extra_key, $random_key), 0, 32);
1966
			$autologin_args = new stdClass;
1967
			$autologin_args->autologin_key = $random_key.$extra_key;
1968
			$autologin_args->member_srl = $this->memberInfo->member_srl;
1969
			executeQuery('member.deleteAutologin', $autologin_args);
1970
			$autologin_output = executeQuery('member.insertAutologin', $autologin_args);
1971
			if($autologin_output->toBool()) setCookie('xeak',$autologin_args->autologin_key, $_SERVER['REQUEST_TIME']+31536000);
1972
		}
1973
		if($this->memberInfo->is_admin == 'Y')
1974
		{
1975
			$oMemberAdminModel = getAdminModel('member');
1976
			if(!$oMemberAdminModel->getMemberAdminIPCheck())
1977
			{
1978
				$_SESSION['denied_admin'] = 'Y';
1979
			}
1980
		}
1981
1982
		$this->setSessionInfo();
1983
1984
		return $output;
1985
	}
1986
1987
	/**
1988
	 * Update or create session information
1989
	 */
1990
	function setSessionInfo()
1991
	{
1992
		$oMemberModel = getModel('member');
1993
		// If your information came through the current session information to extract information from the users
1994
		if(!$this->memberInfo && $_SESSION['member_srl'] && $oMemberModel->isLogged() )
1995
		{
1996
			$this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($_SESSION['member_srl']);
1997
			// If you do not destroy the session Profile
1998
			if($this->memberInfo->member_srl != $_SESSION['member_srl'])
1999
			{
2000
				$this->destroySessionInfo();
2001
				return;
2002
			}
2003
		}
2004
		// Stop using the session id is destroyed
2005
		if($this->memberInfo->denied=='Y')
2006
		{
2007
			$this->destroySessionInfo();
2008
			return;
2009
		}
2010
		// Log in for treatment sessions set
2011
		$_SESSION['is_logged'] = true;
2012
		$_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR'];
2013
		$_SESSION['member_srl'] = $this->memberInfo->member_srl;
2014
		$_SESSION['is_admin'] = '';
2015
		setcookie('xe_logged', 'true');
2016
		// Do not save your password in the session jiwojum;;
2017
		//unset($this->memberInfo->password);
2018
		// User Group Settings
2019
		/*
2020
		   if($this->memberInfo->group_list) {
2021
		   $group_srl_list = array_keys($this->memberInfo->group_list);
2022
		   $_SESSION['group_srls'] = $group_srl_list;
2023
		// If the group is designated as an administrator administrator
2024
		$oMemberModel = getModel('member');
2025
		$admin_group = $oMemberModel->getAdminGroup();
2026
		if($admin_group->group_srl && in_array($admin_group->group_srl, $group_srl_list)) $_SESSION['is_admin'] = 'Y';
2027
		}
2028
		 */
2029
2030
		// Information stored in the session login user
2031
		Context::set('is_logged', true);
2032
		Context::set('logged_info', $this->memberInfo);
2033
2034
		// Only the menu configuration of the user (such as an add-on to the menu can be changed)
2035
		$this->addMemberMenu( 'dispMemberInfo', 'cmd_view_member_info');
2036
		$this->addMemberMenu( 'dispMemberScrappedDocument', 'cmd_view_scrapped_document');
2037
		$this->addMemberMenu( 'dispMemberSavedDocument', 'cmd_view_saved_document');
2038
		$this->addMemberMenu( 'dispMemberOwnDocument', 'cmd_view_own_document');
2039
	}
2040
2041
	/**
2042
	 * Logged method for providing a personalized menu
2043
	 * Login information is used in the output widget, or personalized page
2044
	 */
2045
	function addMemberMenu($act, $str)
2046
	{
2047
		$logged_info = Context::get('logged_info');
2048
2049
		$logged_info->menu_list[$act] = Context::getLang($str);
2050
2051
		Context::set('logged_info', $logged_info);
2052
	}
2053
2054
	/**
2055
	 * Nickname and click Log In to add a pop-up menu that appears when the method
2056
	 */
2057 View Code Duplication
	function addMemberPopupMenu($url, $str, $icon = '', $target = 'self')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2058
	{
2059
		$member_popup_menu_list = Context::get('member_popup_menu_list');
2060
		if(!is_array($member_popup_menu_list)) $member_popup_menu_list = array();
2061
2062
		$obj = new stdClass;
2063
		$obj->url = $url;
2064
		$obj->str = $str;
2065
		$obj->icon = $icon;
2066
		$obj->target = $target;
2067
		$member_popup_menu_list[] = $obj;
2068
2069
		Context::set('member_popup_menu_list', $member_popup_menu_list);
2070
	}
2071
2072
	/**
2073
	 * Add users to the member table
2074
	 */
2075
	function insertMember(&$args, $password_is_hashed = false)
2076
	{
2077
		// Call a trigger (before)
2078
		$output = ModuleHandler::triggerCall('member.insertMember', 'before', $args);
2079
		if(!$output->toBool()) return $output;
2080
		// Terms and Conditions portion of the information set up by members reaffirmed
2081
		$oModuleModel = getModel('module');
2082
		$config = $oModuleModel->getModuleConfig('member');
2083
2084
		$logged_info = Context::get('logged_info');
2085
		// If the date of the temporary restrictions limit further information on the date of
2086
		if($config->limit_day) $args->limit_date = date("YmdHis", $_SERVER['REQUEST_TIME']+$config->limit_day*60*60*24);
2087
2088
		$args->member_srl = getNextSequence();
2089
		$args->list_order = -1 * $args->member_srl;
2090
2091
		// Execute insert or update depending on the value of member_srl
2092
		if(!$args->user_id) $args->user_id = 't'.$args->member_srl;
2093
		// Enter the user's identity changed to lowercase
2094
		else $args->user_id = strtolower($args->user_id);
2095
		if(!$args->user_name) $args->user_name = $args->member_srl;
2096
		if(!$args->nick_name) $args->nick_name = $args->member_srl;
2097
2098
		// Control of essential parameters
2099
		if($args->allow_mailing!='Y') $args->allow_mailing = 'N';
2100
		if($args->denied!='Y') $args->denied = 'N';
2101 View Code Duplication
		if(!$args->allow_message || ($args->allow_message && !in_array($args->allow_message, array('Y','N','F')))) $args->allow_message = 'Y';
2102
2103
		if($logged_info->is_admin == 'Y')
2104
		{
2105
			if($args->is_admin!='Y') $args->is_admin = 'N';
2106
		}
2107
		else
2108
		{
2109
			unset($args->is_admin);
2110
		}
2111
2112
		list($args->email_id, $args->email_host) = explode('@', $args->email_address);
2113
2114
		// Sanitize user ID, username, nickname, homepage, blog
2115
		$args->user_id = htmlspecialchars($args->user_id, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2116
		$args->user_name = htmlspecialchars($args->user_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2117
		$args->nick_name = htmlspecialchars($args->nick_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2118
		$args->homepage = htmlspecialchars($args->homepage, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2119
		$args->blog = htmlspecialchars($args->blog, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2120 View Code Duplication
		if($args->homepage && !preg_match("/^[a-z]+:\/\//i",$args->homepage)) $args->homepage = 'http://'.$args->homepage;
2121 View Code Duplication
		if($args->blog && !preg_match("/^[a-z]+:\/\//i",$args->blog)) $args->blog = 'http://'.$args->blog;
2122
2123
		// Create a model object
2124
		$oMemberModel = getModel('member');
2125
2126
		// Check password strength
2127
		if($args->password && !$password_is_hashed)
2128
		{
2129 View Code Duplication
			if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
2130
			{
2131
				$message = Context::getLang('about_password_strength');
2132
				return new BaseObject(-1, $message[$config->password_strength]);
2133
			}
2134
			$args->password = $oMemberModel->hashPassword($args->password);
2135
		}
2136
		elseif(!$args->password)
2137
		{
2138
			unset($args->password);
2139
		}
2140
2141
		if($args->find_account_answer && !$password_is_hashed)
2142
		{
2143
			$args->find_account_answer = $oMemberModel->hashPassword($args->find_account_answer);
2144
		}
2145
		elseif(!$args->find_account_answer)
2146
		{
2147
			unset($args->find_account_answer);
2148
		}
2149
2150
		// Check if ID is prohibited
2151
		if($oMemberModel->isDeniedID($args->user_id))
2152
		{
2153
			return new BaseObject(-1,'denied_user_id');
2154
		}
2155
2156
		// Check if ID is duplicate
2157
		$member_srl = $oMemberModel->getMemberSrlByUserID($args->user_id);
2158
		if($member_srl)
2159
		{
2160
			return new BaseObject(-1,'msg_exists_user_id');
2161
		}
2162
2163
		// Check if nickname is prohibited
2164
		if($oMemberModel->isDeniedNickName($args->nick_name))
2165
		{
2166
			return new BaseObject(-1,'denied_nick_name');
2167
		}
2168
2169
		// Check if nickname is duplicate
2170
		$member_srl = $oMemberModel->getMemberSrlByNickName($args->nick_name);
2171
		if($member_srl)
2172
		{
2173
			return new BaseObject(-1,'msg_exists_nick_name');
2174
		}
2175
2176
		// Check if email address is duplicate
2177
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($args->email_address);
2178
		if($member_srl)
2179
		{
2180
			return new BaseObject(-1,'msg_exists_email_address');
2181
		}
2182
2183
		// Insert data into the DB
2184
		$args->list_order = -1 * $args->member_srl;
2185
2186
		if(!$args->user_id) $args->user_id = 't'.$args->member_srl;
2187
		if(!$args->user_name) $args->user_name = $args->member_srl;
2188
2189
		$oDB = &DB::getInstance();
2190
		$oDB->begin();
2191
2192
		$output = executeQuery('member.insertMember', $args);
2193
		if(!$output->toBool())
2194
		{
2195
			$oDB->rollback();
2196
			return $output;
2197
		}
2198
2199 View Code Duplication
		if(is_array($args->group_srl_list)) $group_srl_list = $args->group_srl_list;
2200
		else $group_srl_list = explode('|@|', $args->group_srl_list);
2201
		// If no value is entered the default group, the value of group registration
2202
		if(!$args->group_srl_list)
2203
		{
2204
			$columnList = array('site_srl', 'group_srl');
2205
			$default_group = $oMemberModel->getDefaultGroup(0, $columnList);
2206
			if($default_group)
2207
			{
2208
				// Add to the default group
2209
				$output = $this->addMemberToGroup($args->member_srl,$default_group->group_srl);
2210
				if(!$output->toBool())
2211
				{
2212
					$oDB->rollback();
2213
					return $output;
2214
				}
2215
			}
2216
			// If the value is the value of the group entered the group registration
2217
		}
2218
		else
2219
		{
2220 View Code Duplication
			for($i=0;$i<count($group_srl_list);$i++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2221
			{
2222
				$output = $this->addMemberToGroup($args->member_srl,$group_srl_list[$i]);
2223
2224
				if(!$output->toBool())
2225
				{
2226
					$oDB->rollback();
2227
					return $output;
2228
				}
2229
			}
2230
		}
2231
2232
		$member_config = $oModuleModel->getModuleConfig('member');
0 ignored issues
show
Unused Code introduced by
$member_config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2233
		// When using email authentication mode (when you subscribed members denied a) certified mail sent
2234
		if($args->denied == 'Y')
2235
		{
2236
			// Insert data into the authentication DB
2237
			$oPassword = new Password();
2238
			$auth_args = new stdClass();
2239
			$auth_args->user_id = $args->user_id;
2240
			$auth_args->member_srl = $args->member_srl;
2241
			$auth_args->new_password = $args->password;
2242
			$auth_args->auth_key = $oPassword->createSecureSalt(40);
2243
			$auth_args->is_register = 'Y';
2244
2245
			$output = executeQuery('member.insertAuthMail', $auth_args);
2246
			if(!$output->toBool())
2247
			{
2248
				$oDB->rollback();
2249
				return $output;
2250
			}
2251
			$this->_sendAuthMail($auth_args, $args);
2252
		}
2253
		// Call a trigger (after)
2254 View Code Duplication
		if($output->toBool())
2255
		{
2256
			$trigger_output = ModuleHandler::triggerCall('member.insertMember', 'after', $args);
2257
			if(!$trigger_output->toBool())
2258
			{
2259
				$oDB->rollback();
2260
				return $trigger_output;
2261
			}
2262
		}
2263
2264
		$oDB->commit(true);
2265
2266
		$output->add('member_srl', $args->member_srl);
2267
		return $output;
2268
	}
2269
2270
	/**
2271
	 * Modify member information
2272
	 *
2273
	 * @param bool $is_admin , modified 2013-11-22
2274
	 */
2275
	function updateMember($args, $is_admin = FALSE)
2276
	{
2277
		// Call a trigger (before)
2278
		$output = ModuleHandler::triggerCall('member.updateMember', 'before', $args);
2279
		if(!$output->toBool()) return $output;
2280
		// Create a model object
2281
		$oMemberModel = getModel('member');
2282
2283
		$logged_info = Context::get('logged_info');
2284
		// Get what you want to modify the original information
2285
		if(!$this->memberInfo) $this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($args->member_srl);
2286
		// Control of essential parameters
2287
		if($args->allow_mailing!='Y') $args->allow_mailing = 'N';
2288 View Code Duplication
		if($args->allow_message && !in_array($args->allow_message, array('Y','N','F'))) $args->allow_message = 'Y';
2289
2290
		if($logged_info->is_admin == 'Y')
2291
		{
2292
			if($args->denied!='Y') $args->denied = 'N';
2293
			if($args->is_admin!='Y' && $logged_info->member_srl != $args->member_srl) $args->is_admin = 'N';
2294
		}
2295
		else
2296
		{
2297
			unset($args->is_admin);
2298
			if($is_admin == false)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
2299
				unset($args->denied);
2300
			if($logged_info->member_srl != $args->member_srl && $is_admin == false)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
2301
			{
2302
				return $this->stop('msg_invalid_request');
2303
			}
2304
		}
2305
2306
		// Sanitize user ID, username, nickname, homepage, blog
2307
		if($args->user_id) $args->user_id = htmlspecialchars($args->user_id, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2308
		$args->user_name = htmlspecialchars($args->user_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2309
		$args->nick_name = htmlspecialchars($args->nick_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2310
		$args->homepage = htmlspecialchars($args->homepage, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2311
		$args->blog = htmlspecialchars($args->blog, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2312 View Code Duplication
		if($args->homepage && !preg_match("/^[a-z]+:\/\//is",$args->homepage)) $args->homepage = 'http://'.$args->homepage;
2313 View Code Duplication
		if($args->blog && !preg_match("/^[a-z]+:\/\//is",$args->blog)) $args->blog = 'http://'.$args->blog;
2314
2315
		// check member identifier form
2316
		$config = $oMemberModel->getMemberConfig();
2317
2318
		$output = executeQuery('member.getMemberInfoByMemberSrl', $args);
2319
		$orgMemberInfo = $output->data;
2320
2321
		// Check if email address or user ID is duplicate
2322
		if($config->identifier == 'email_address')
2323
		{
2324
			$member_srl = $oMemberModel->getMemberSrlByEmailAddress($args->email_address);
2325
			if($member_srl && $args->member_srl != $member_srl)
2326
			{
2327
				return new BaseObject(-1,'msg_exists_email_address');
2328
			}
2329
			$args->email_address = $orgMemberInfo->email_address;
2330
		}
2331 View Code Duplication
		else
2332
		{
2333
			$member_srl = $oMemberModel->getMemberSrlByUserID($args->user_id);
2334
			if($member_srl && $args->member_srl != $member_srl)
2335
			{
2336
				return new BaseObject(-1,'msg_exists_user_id');
2337
			}
2338
2339
			$args->user_id = $orgMemberInfo->user_id;
2340
		}
2341
2342
		if($logged_info->is_admin !== 'Y')
2343
		{
2344
			// Check if ID is prohibited
2345
			if($args->user_id && $oMemberModel->isDeniedID($args->user_id))
2346
			{
2347
				return new BaseObject(-1,'denied_user_id');
2348
			}
2349
2350
			// Check if nickname is prohibited
2351
			if($args->nick_name && $oMemberModel->isDeniedNickName($args->nick_name))
2352
			{
2353
				return new BaseObject(-1, 'denied_nick_name');
2354
			}
2355
		}
2356
2357
		// Check if ID is duplicate
2358 View Code Duplication
		if($args->user_id)
2359
		{
2360
			$member_srl = $oMemberModel->getMemberSrlByUserID($args->user_id);
2361
			if($member_srl && $args->member_srl != $member_srl)
2362
			{
2363
				return new BaseObject(-1,'msg_exists_user_id');
2364
			}
2365
		}
2366
2367
		// Check if nickname is duplicate
2368
		$member_srl = $oMemberModel->getMemberSrlByNickName($args->nick_name);
2369
 		if($member_srl && $args->member_srl != $member_srl)
2370
 		{
2371
 			return new BaseObject(-1,'msg_exists_nick_name');
2372
 		}
2373
2374
		list($args->email_id, $args->email_host) = explode('@', $args->email_address);
2375
2376
		$oDB = &DB::getInstance();
2377
		$oDB->begin();
2378
2379
		// Check password strength
2380
		if($args->password)
2381
		{
2382 View Code Duplication
			if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
2383
			{
2384
				$message = Context::getLang('about_password_strength');
2385
				return new BaseObject(-1, $message[$config->password_strength]);
2386
			}
2387
			$args->password = $oMemberModel->hashPassword($args->password);
2388
		}
2389
		else
2390
		{
2391
			$args->password = $orgMemberInfo->password;
2392
		}
2393
2394
		if($args->find_account_answer) {
2395
			$args->find_account_answer = $oMemberModel->hashPassword($args->find_account_answer);
2396
		}
2397
		else
2398
		{
2399
			$oPassword =  new Password();
2400
			$hashed = $oPassword->checkAlgorithm($orgMemberInfo->find_account_answer);
2401
2402
			if($hashed) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $hashed of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
2403
				$args->find_account_answer = $orgMemberInfo->find_account_answer;
2404
			} else {
2405
				$args->find_account_answer = $oPassword->createHash($orgMemberInfo->find_account_answer);
2406
			}
2407
		}
2408
2409
		if(!$args->user_name) $args->user_name = $orgMemberInfo->user_name;
2410
		if(!$args->user_id) $args->user_id = $orgMemberInfo->user_id;
2411
		if(!$args->nick_name) $args->nick_name = $orgMemberInfo->nick_name;
2412
		if(!$args->description) $args->description = $orgMemberInfo->description;
2413
		if(!$args->birthday) $args->birthday = '';
2414
2415
		$output = executeQuery('member.updateMember', $args);
2416
2417
		if(!$output->toBool())
2418
		{
2419
			$oDB->rollback();
2420
			return $output;
2421
		}
2422
2423
		if($args->group_srl_list)
2424
		{
2425 View Code Duplication
			if(is_array($args->group_srl_list)) $group_srl_list = $args->group_srl_list;
2426
			else $group_srl_list = explode('|@|', $args->group_srl_list);
2427
			// If the group information, group information changes
2428
			if(count($group_srl_list) > 0)
2429
			{
2430
				$args->site_srl = 0;
2431
				// One of its members to delete all the group
2432
				$output = executeQuery('member.deleteMemberGroupMember', $args);
2433
				if(!$output->toBool())
2434
				{
2435
					$oDB->rollback();
2436
					return $output;
2437
				}
2438
				// Enter one of the loop a
2439 View Code Duplication
				for($i=0;$i<count($group_srl_list);$i++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2440
				{
2441
					$output = $this->addMemberToGroup($args->member_srl,$group_srl_list[$i]);
2442
					if(!$output->toBool())
2443
					{
2444
						$oDB->rollback();
2445
						return $output;
2446
					}
2447
				}
2448
2449
				// if group is changed, point changed too.
2450
				$this->_updatePointByGroup($orgMemberInfo->member_srl, $group_srl_list);
2451
			}
2452
		}
2453
		// Call a trigger (after)
2454 View Code Duplication
		if($output->toBool()) {
2455
			$trigger_output = ModuleHandler::triggerCall('member.updateMember', 'after', $args);
2456
			if(!$trigger_output->toBool())
2457
			{
2458
				$oDB->rollback();
2459
				return $trigger_output;
2460
			}
2461
		}
2462
2463
		$oDB->commit();
2464
2465
		//remove from cache
2466
		$this->_clearMemberCache($args->member_srl, $args->site_srl);
2467
2468
		// Save Session
2469
		if(!$this->memberInfo) $this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($args->member_srl);
2470
		$logged_info = Context::get('logged_info');
0 ignored issues
show
Unused Code introduced by
$logged_info is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2471
2472
		$output->add('member_srl', $args->member_srl);
2473
		return $output;
2474
	}
2475
2476
	/**
2477
	 * Modify member password
2478
	 */
2479
	function updateMemberPassword($args)
2480
	{
2481
		if($args->password)
2482
		{
2483
2484
			// check password strength
2485
			$oMemberModel = getModel('member');
2486
			$config = $oMemberModel->getMemberConfig();
2487
2488 View Code Duplication
			if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
2489
			{
2490
				$message = Context::getLang('about_password_strength');
2491
				return new BaseObject(-1, $message[$config->password_strength]);
2492
			}
2493
2494
			$args->password = $oMemberModel->hashPassword($args->password);
2495
		}
2496
		else if($args->hashed_password)
2497
		{
2498
			$args->password = $args->hashed_password;
2499
		}
2500
2501
		$output = executeQuery('member.updateMemberPassword', $args);
2502
		if($output->toBool())
2503
		{
2504
			$result = executeQuery('member.updateChangePasswordDate', $args);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2505
		}
2506
2507
		$this->_clearMemberCache($args->member_srl);
2508
2509
		return $output;
2510
	}
2511
2512
	function updateFindAccountAnswer($member_srl, $answer)
2513
	{
2514
		$oPassword =  new Password();
2515
2516
		$args = new stdClass();
2517
		$args->member_srl = $member_srl;
2518
		$args->find_account_answer = $oPassword->createHash($answer);
2519
		$output = executeQuery('member.updateFindAccountAnswer', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2520
	}
2521
2522
	/**
2523
	 * Delete User
2524
	 */
2525
	function deleteMember($member_srl)
2526
	{
2527
		// Call a trigger (before)
2528
		$trigger_obj = new stdClass();
2529
		$trigger_obj->member_srl = $member_srl;
2530
		$output = ModuleHandler::triggerCall('member.deleteMember', 'before', $trigger_obj);
2531
		if(!$output->toBool()) return $output;
2532
		// Create a model object
2533
		$oMemberModel = getModel('member');
2534
		// Bringing the user's information
2535
		if(!$this->memberInfo || $this->memberInfo->member_srl != $member_srl || !isset($this->memberInfo->is_admin))
2536
		{
2537
			$columnList = array('member_srl', 'is_admin');
2538
			$this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
2539
		}
2540
		if(!$this->memberInfo) return new BaseObject(-1, 'msg_not_exists_member');
2541
		// If managers can not be deleted
2542
		if($this->memberInfo->is_admin == 'Y') return new BaseObject(-1, 'msg_cannot_delete_admin');
2543
2544
		$oDB = &DB::getInstance();
2545
		$oDB->begin();
2546
2547
		$args = new stdClass();
2548
		$args->member_srl = $member_srl;
2549
		// Delete the entries in member_auth_mail
2550
		$output = executeQuery('member.deleteAuthMail', $args);
2551
		if(!$output->toBool())
2552
		{
2553
			$oDB->rollback();
2554
			return $output;
2555
		}
2556
2557
		// TODO: If the table is not an upgrade may fail.
2558
		/*
2559
		   if(!$output->toBool()) {
2560
		   $oDB->rollback();
2561
		   return $output;
2562
		   }
2563
		 */
2564
		// Delete the entries in member_group_member
2565
		$output = executeQuery('member.deleteMemberGroupMember', $args);
2566
		if(!$output->toBool())
2567
		{
2568
			$oDB->rollback();
2569
			return $output;
2570
		}
2571
		// member removed from the table
2572
		$output = executeQuery('member.deleteMember', $args);
2573
		if(!$output->toBool())
2574
		{
2575
			$oDB->rollback();
2576
			return $output;
2577
		}
2578
		// Call a trigger (after)
2579 View Code Duplication
		if($output->toBool())
2580
		{
2581
			$trigger_output = ModuleHandler::triggerCall('member.deleteMember', 'after', $trigger_obj);
2582
			if(!$trigger_output->toBool())
2583
			{
2584
				$oDB->rollback();
2585
				return $trigger_output;
2586
			}
2587
		}
2588
2589
		$oDB->commit();
2590
		// Name, image, image, mark, sign, delete
2591
		$this->procMemberDeleteImageName($member_srl);
2592
		$this->procMemberDeleteImageMark($member_srl);
2593
		$this->procMemberDeleteProfileImage($member_srl);
2594
		$this->delSignature($member_srl);
2595
2596
		$this->_clearMemberCache($member_srl);
2597
2598
		return $output;
2599
	}
2600
2601
	/**
2602
	 * Destroy all session information
2603
	 */
2604
	function destroySessionInfo()
2605
	{
2606
		if(!$_SESSION || !is_array($_SESSION)) return;
2607
2608
		$memberInfo = Context::get('logged_info');
2609
		$memberSrl = $memberInfo->member_srl;
2610
2611
		foreach($_SESSION as $key => $val)
2612
		{
2613
			$_SESSION[$key] = '';
2614
		}
2615
2616
		session_destroy();
2617
		setcookie(session_name(), '', $_SERVER['REQUEST_TIME']-42000);
2618
		setcookie('sso','',$_SERVER['REQUEST_TIME']-42000);
2619
		setcookie('xeak','',$_SERVER['REQUEST_TIME']-42000);
2620
		setcookie('xe_logged', 'false', $_SERVER['REQUEST_TIME'] - 42000);
2621
2622
		if($memberSrl || $_COOKIE['xeak'])
2623
		{
2624
			$args = new stdClass();
2625
			$args->member_srl = $memberSrl;
2626
			$args->autologin_key = $_COOKIE['xeak'];
2627
			$output = executeQuery('member.deleteAutologin', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2628
		}
2629
	}
2630
2631
	function _updatePointByGroup($memberSrl, $groupSrlList)
2632
	{
2633
		$oModuleModel = getModel('module');
2634
		$pointModuleConfig = $oModuleModel->getModuleConfig('point');
2635
		$pointGroup = $pointModuleConfig->point_group;
2636
2637
		$levelGroup = array();
2638
		if(is_array($pointGroup) && count($pointGroup)>0)
2639
		{
2640
			$levelGroup = array_flip($pointGroup);
2641
			ksort($levelGroup);
2642
		}
2643
		$maxLevel = 0;
2644
		$resultGroup = array_intersect($levelGroup, $groupSrlList);
2645
		if(count($resultGroup) > 0)
2646
			$maxLevel = max(array_flip($resultGroup));
2647
2648
		if($maxLevel > 0)
2649
		{
2650
			$oPointModel = getModel('point');
2651
			$originPoint = $oPointModel->getPoint($memberSrl);
2652
2653
			if($pointModuleConfig->level_step[$maxLevel] > $originPoint)
2654
			{
2655
				$oPointController = getController('point');
2656
				$oPointController->setPoint($memberSrl, $pointModuleConfig->level_step[$maxLevel], 'update');
2657
			}
2658
		}
2659
	}
2660
2661
	function procMemberModifyEmailAddress()
2662
	{
2663
		if(!Context::get('is_logged')) return $this->stop('msg_not_logged');
2664
2665
		$member_info = Context::get('logged_info');
2666
		$newEmail = Context::get('email_address');
2667
2668
		if(!$newEmail) return $this->stop('msg_invalid_request');
2669
2670
		$oMemberModel = getModel('member');
2671
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($newEmail);
2672
		if($member_srl) return new BaseObject(-1,'msg_exists_email_address');
2673
2674
		if($_SESSION['rechecked_password_step'] != 'INPUT_DATA')
2675
		{
2676
			return $this->stop('msg_invalid_request');
2677
		}
2678
		unset($_SESSION['rechecked_password_step']);
2679
2680
		$oPassword = new Password();
2681
		$auth_args = new stdClass();
2682
		$auth_args->user_id = $newEmail;
2683
		$auth_args->member_srl = $member_info->member_srl;
2684
		$auth_args->auth_key = $oPassword->createSecureSalt(40);
2685
		$auth_args->new_password = 'XE_change_emaill_address';
2686
2687
		$oDB = &DB::getInstance();
2688
		$oDB->begin();
2689
		$output = executeQuery('member.insertAuthMail', $auth_args);
2690
		if(!$output->toBool())
2691
		{
2692
			$oDB->rollback();
2693
			return $output;
2694
		}
2695
2696
		$oModuleModel = getModel('module');
2697
		$member_config = $oModuleModel->getModuleConfig('member');
2698
2699
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
2700
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
2701
2702
		global $lang;
2703
2704
		$memberInfo = array();
2705
		$memberInfo[$lang->email_address] = $member_info->email_address;
2706
		$memberInfo[$lang->nick_name] = $member_info->nick_name;
2707
2708
		Context::set('memberInfo', $memberInfo);
2709
2710
		Context::set('newEmail', $newEmail);
2711
2712
		$auth_url = getFullUrl('','module','member','act','procMemberAuthEmailAddress','member_srl',$member_info->member_srl, 'auth_key',$auth_args->auth_key);
2713
		Context::set('auth_url', $auth_url);
2714
2715
		$oTemplate = &TemplateHandler::getInstance();
2716
		$content = $oTemplate->compile($tpl_path, 'confirm_member_new_email');
2717
2718
		$oMail = new Mail();
2719
		$oMail->setTitle( Context::getLang('title_modify_email_address') );
2720
		$oMail->setContent($content);
2721
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
2722
		$oMail->setReceiptor( $member_info->nick_name, $newEmail );
2723
		$result = $oMail->send();
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2724
2725
		$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $newEmail);
2726
		$this->setMessage($msg);
2727
2728
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
2729
		$this->setRedirectUrl($returnUrl);
2730
	}
2731
2732
	function procMemberAuthEmailAddress()
2733
	{
2734
		$member_srl = Context::get('member_srl');
2735
		$auth_key = Context::get('auth_key');
2736
		if(!$member_srl || !$auth_key) return $this->stop('msg_invalid_request');
2737
2738
		// Test logs for finding password by user_id and authkey
2739
		$args = new stdClass;
2740
		$args->member_srl = $member_srl;
2741
		$args->auth_key = $auth_key;
2742
		$output = executeQuery('member.getAuthMail', $args);
2743 View Code Duplication
		if(!$output->toBool() || $output->data->auth_key != $auth_key)
2744
		{
2745
			if(strlen($output->data->auth_key) !== strlen($auth_key)) executeQuery('member.deleteAuthChangeEmailAddress', $args);
2746
			return $this->stop('msg_invalid_modify_email_auth_key');
2747
		}
2748
2749
		$newEmail = $output->data->user_id;
2750
		$args->email_address = $newEmail;
2751
		list($args->email_id, $args->email_host) = explode('@', $newEmail);
2752
2753
		$output = executeQuery('member.updateMemberEmailAddress', $args);
2754
		if(!$output->toBool()) return $this->stop($output->getMessage());
2755
2756
		// Remove all values having the member_srl and new_password equal to 'XE_change_emaill_address' from authentication table
2757
		executeQuery('member.deleteAuthChangeEmailAddress',$args);
2758
2759
		$this->_clearMemberCache($args->member_srl);
2760
2761
		// Notify the result
2762
		$this->setTemplatePath($this->module_path.'tpl');
2763
		$this->setTemplateFile('msg_success_modify_email_address');
2764
	}
2765
2766
	/**
2767
	 * trigger for document.getDocumentMenu. Append to popup menu a button for procMemberSpammerManage()
2768
	 *
2769
	 * @param array &$menu_list
2770
	 *
2771
	 * @return object
2772
	**/
2773 View Code Duplication
	function triggerGetDocumentMenu(&$menu_list)
0 ignored issues
show
Unused Code introduced by
The parameter $menu_list is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2774
	{
2775
		if(!Context::get('is_logged')) return new BaseObject();
2776
2777
		$logged_info = Context::get('logged_info');
2778
		$document_srl = Context::get('target_srl');
2779
2780
		$oDocumentModel = getModel('document');
2781
		$columnList = array('document_srl', 'module_srl', 'member_srl', 'ipaddress');
2782
		$oDocument = $oDocumentModel->getDocument($document_srl, false, false, $columnList);
2783
		$member_srl = $oDocument->get('member_srl');
2784
		$module_srl = $oDocument->get('module_srl');
2785
2786
		if(!$member_srl) return new BaseObject();
2787
		if($oDocumentModel->grant->manager != 1 || $member_srl==$logged_info->member_srl) return new BaseObject();
2788
2789
		$oDocumentController = getController('document');
2790
		$url = getUrl('','module','member','act','dispMemberSpammer','member_srl',$member_srl,'module_srl',$module_srl);
2791
		$oDocumentController->addDocumentPopupMenu($url,'cmd_spammer','','popup');
2792
2793
		return new BaseObject();
2794
	}
2795
2796
	/**
2797
	 * trigger for comment.getCommentMenu. Append to popup menu a button for procMemberSpammerManage()
2798
	 *
2799
	 * @param array &$menu_list
2800
	 *
2801
	 * @return object
2802
	**/
2803 View Code Duplication
	function triggerGetCommentMenu(&$menu_list)
0 ignored issues
show
Unused Code introduced by
The parameter $menu_list is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2804
	{
2805
		if(!Context::get('is_logged')) return new BaseObject();
2806
2807
		$logged_info = Context::get('logged_info');
2808
		$comment_srl = Context::get('target_srl');
2809
2810
		$oCommentModel = getModel('comment');
2811
		$columnList = array('comment_srl', 'module_srl', 'member_srl', 'ipaddress');
2812
		$oComment = $oCommentModel->getComment($comment_srl, FALSE, $columnList);
2813
		$module_srl = $oComment->get('module_srl');
2814
		$member_srl = $oComment->get('member_srl');
2815
2816
		if(!$member_srl) return new BaseObject();
2817
		if($oCommentModel->grant->manager != 1 || $member_srl==$logged_info->member_srl) return new BaseObject();
2818
2819
		$oCommentController = getController('comment');
2820
		$url = getUrl('','module','member','act','dispMemberSpammer','member_srl',$member_srl,'module_srl',$module_srl);
2821
		$oCommentController->addCommentPopupMenu($url,'cmd_spammer','','popup');
2822
2823
		return new BaseObject();
2824
	}
2825
2826
	/**
2827
	 * Spammer manage. Denied user login. And delete or trash all documents. Response Ajax string
2828
	 *
2829
	 * @return object
2830
	**/
2831
	function procMemberSpammerManage()
2832
	{
2833
		if(!Context::get('is_logged')) return new BaseObject(-1,'msg_not_permitted');
2834
2835
		$logged_info = Context::get('logged_info');
2836
		$member_srl = Context::get('member_srl');
2837
		$module_srl = Context::get('module_srl');
2838
		$cnt_loop = Context::get('cnt_loop');
2839
		$proc_type = Context::get('proc_type');
2840
		$isMoveToTrash = true;
2841
		if($proc_type == "delete")
2842
			$isMoveToTrash = false;
2843
2844
		// check grant
2845
		$oModuleModel = getModel('module');
2846
		$columnList = array('module_srl', 'module');
2847
		$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl, $columnList);
2848
		$grant = $oModuleModel->getGrant($module_info, $logged_info);
2849
2850
		if(!$grant->manager) return new BaseObject(-1,'msg_not_permitted');
2851
2852
		$proc_msg = "";
0 ignored issues
show
Unused Code introduced by
$proc_msg is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2853
2854
		$oDocumentModel = getModel('document');
2855
		$oCommentModel = getModel('comment');
2856
2857
		// delete or trash destination
2858
		// proc member
2859
		if($cnt_loop == 1)
2860
			$this->_spammerMember($member_srl);
2861
		// proc document and comment
2862
		elseif($cnt_loop>1)
2863
			$this->_spammerDocuments($member_srl, $isMoveToTrash);
2864
2865
		// get destination count
2866
		$cnt_document = $oDocumentModel->getDocumentCountByMemberSrl($member_srl);
2867
		$cnt_comment = $oCommentModel->getCommentCountByMemberSrl($member_srl);
2868
2869
		$total_count = Context::get('total_count');
2870
		$remain_count = $cnt_document + $cnt_comment;
2871
		if($cnt_loop == 1) $total_count = $remain_count;
2872
2873
		// get progress percent
2874
		if($total_count > 0)
2875
			$progress = intval( ( ( $total_count - $remain_count ) / $total_count ) * 100 );
2876
		else
2877
			$progress = 100;
2878
2879
		$this->add('total_count', $total_count);
2880
		$this->add('remain_count', $remain_count);
2881
		$this->add('progress', $progress);
2882
		$this->add('member_srl', $member_srl);
2883
		$this->add('module_srl', $module_srl);
2884
		$this->add('cnt_loop', ++$cnt_loop);
2885
		$this->add('proc_type', $proc_type);
2886
2887
		return new BaseObject(0);
2888
	}
2889
2890
	/**
2891
	 * Denied user login and write description
2892
	 *
2893
	 * @param int $member_srl
2894
	 *
2895
	 * @return object
2896
	**/
2897
	private function _spammerMember($member_srl) {
2898
		$logged_info = Context::get('logged_info');
2899
		$spam_description = trim( Context::get('spam_description') );
2900
2901
		$oMemberModel = getModel('member');
2902
		$columnList = array('member_srl', 'email_address', 'user_id', 'nick_name', 'description');
2903
		// get member current infomation
2904
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
2905
2906
		$oDocumentModel = getModel('document');
2907
		$oCommentModel = getModel('comment');
2908
		$cnt_comment = $oCommentModel->getCommentCountByMemberSrl($member_srl);
2909
		$cnt_document = $oDocumentModel->getDocumentCountByMemberSrl($member_srl);
2910
		$total_count = $cnt_comment + $cnt_document;
2911
2912
		$args = new stdClass();
2913
		$args->member_srl = $member_info->member_srl;
2914
		$args->email_address = $member_info->email_address;
2915
		$args->user_id = $member_info->user_id;
2916
		$args->nick_name = $member_info->nick_name;
2917
		$args->denied = "Y";
2918
		$args->description = trim( $member_info->description );
2919
		if( $args->description != "" ) $args->description .= "\n";	// add new line
2920
2921
		$args->description .= Context::getLang('cmd_spammer') . "[" . date("Y-m-d H:i:s") . " from:" . $logged_info->user_id . " info:" . $spam_description . " docuemnts count:" . $total_count . "]";
2922
2923
		$output = $this->updateMember($args, true);
2924
2925
		$this->_clearMemberCache($args->member_srl);
2926
2927
		return $output;
2928
	}
2929
2930
	/**
2931
	 * Delete or trash all documents
2932
	 *
2933
	 * @param int $member_srl
2934
	 * @param bool $isMoveToTrash
2935
	 *
2936
	 * @return object
2937
	**/
2938
	private function _spammerDocuments($member_srl, $isMoveToTrash) {
2939
		$oDocumentController = getController('document');
2940
		$oDocumentModel = getModel('document');
2941
		$oCommentController = getController('comment');
2942
		$oCommentModel = getModel('comment');
2943
2944
		// delete count by one request
2945
		$getContentsCount = 10;
2946
2947
		// 1. proc comment, 2. proc document
2948
		$cnt_comment = $oCommentModel->getCommentCountByMemberSrl($member_srl);
2949
		$cnt_document = $oDocumentModel->getDocumentCountByMemberSrl($member_srl);
2950
		if($cnt_comment > 0)
2951
		{
2952
			$columnList = array();
2953
			$commentList = $oCommentModel->getCommentListByMemberSrl($member_srl, $columnList, 0, false, $getContentsCount);
2954
			if($commentList) {
2955
				foreach($commentList as $v) {
2956
					$oCommentController->deleteComment($v->comment_srl, true, $isMoveToTrash);
2957
				}
2958
			}
2959
		} elseif($cnt_document > 0) {
2960
			$columnList = array();
2961
			$documentList = $oDocumentModel->getDocumentListByMemberSrl($member_srl, $columnList, 0, false, $getContentsCount);
2962
			if($documentList) {
2963
				foreach($documentList as $v) {
2964
					if($isMoveToTrash) $oDocumentController->moveDocumentToTrash($v);
2965
					else $oDocumentController->deleteDocument($v->document_srl);
2966
				}
2967
			}
2968
		}
2969
2970
		return array();
2971
	}
2972
2973
	function _clearMemberCache($member_srl, $site_srl = 0)
2974
	{
2975
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
2976
		if($oCacheHandler->isSupport())
2977
		{
2978
			$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_' . $site_srl;
2979
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
2980
			$oCacheHandler->delete($cache_key);
2981
2982
			if($site_srl !== 0)
2983
			{
2984
				$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_0';
2985
				$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
2986
				$oCacheHandler->delete($cache_key);
2987
			}
2988
		}
2989
2990
		$oCacheHandler = CacheHandler::getInstance('object');
2991
		if($oCacheHandler->isSupport())
2992
		{
2993
			$object_key = 'member_info:' . getNumberingPath($member_srl) . $member_srl;
2994
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
2995
			$oCacheHandler->delete($cache_key);
2996
		}
2997
	}
2998
}
2999
/* End of file member.controller.php */
3000
/* Location: ./modules/member/member.controller.php */
3001