/
firstLogin.php
122 lines (113 loc) · 3.68 KB
/
firstLogin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* TestLink Open Source Project - http://testlink.sourceforge.net/
* This script is distributed under the GNU General Public License 2 or later.
*
* @filesource firstLogin.php
* @package TestLink
* @copyright 2004-2014, TestLink community
* @link http://www.testlink.org
*
* @internal revisions
* @since 1.9.9
* 20130914 - franciscom - TICKET 5895: New Account Created notification is sent to wrong destinations
*
*/
require_once('config.inc.php');
require_once('common.php');
require_once('users.inc.php');
require_once('email_api.php');
$templateCfg = templateConfiguration();
if (!config_get('user_self_signup'))
{
$smarty = new TLSmarty();
$smarty->assign('title', lang_get('fatal_page_title'));
$smarty->assign('content', lang_get('error_self_signup_disabled'));
$smarty->assign('link_to_op', "login.php");
$smarty->assign('hint_text', lang_get('link_back_to_login'));
$smarty->display('workAreaSimple.tpl');
exit();
}
$args = init_args();
doDBConnect($db,database::ONERROREXIT);
$message = lang_get('your_info_please');
if($args->doEditUser)
{
if(strcmp($args->password,$args->password2))
{
$message = lang_get('passwd_dont_match');
}
else
{
$user = new tlUser();
$result = $user->setPassword($args->password);
if ($result >= tl::OK)
{
$user->login = $args->login;
$user->emailAddress = $args->email;
$user->firstName = $args->firstName;
$user->lastName = $args->lastName;
$result = $user->writeToDB($db);
}
if ($result >= tl::OK)
{
notifyGlobalAdmins($db,$user);
logAuditEvent(TLS("audit_users_self_signup",$args->login),"CREATE",$user->dbID,"users");
redirect(TL_BASE_HREF . "login.php?note=first");
exit();
}
else
{
$message = getUserErrorMessage($result);
}
}
}
$smarty = new TLSmarty();
$gui = $args;
// we get info about THE DEFAULT AUTHENTICATION METHOD
$gui->external_password_mgmt = tlUser::isPasswordMgtExternal();
$gui->message = $message;
$smarty->assign('gui',$gui);
$smarty->display($templateCfg->default_template);
/**
* get input from user and return it in some sort of namespace
*
*/
function init_args()
{
$iParams = array("doEditUser" => array(tlInputParameter::STRING_N,0,1),
"login" => array(tlInputParameter::STRING_N,0,30),
"password" => array(tlInputParameter::STRING_N,0,32),
"password2" => array(tlInputParameter::STRING_N,0,32),
"firstName" => array(tlInputParameter::STRING_N,0,30),
"lastName" => array(tlInputParameter::STRING_N,0,30),
"email" => array(tlInputParameter::STRING_N,0,100));
$args = new stdClass();
P_PARAMS($iParams,$args);
return $args;
}
/**
* send mail to administrators (users that have default role = administrator)
* to warn about new user created.
*
*/
function notifyGlobalAdmins(&$dbHandler,&$userObj)
{
// Get email addresses for all users that have default role = administrator
$roleMgr = new tlRole(TL_ROLES_ADMIN);
$userSet = $roleMgr->getUsersWithGlobalRole($dbHandler);
$mail['subject'] = lang_get('new_account');
$key2loop = array_keys($userSet);
foreach($key2loop as $userID)
{
$mail['to'][$userID] = $userSet[$userID]->emailAddress;
}
// email_api uses ',' as list separator
$mail['to'] = implode(',',$mail['to']);
$mail['body'] = lang_get('new_account') . "\n";
$mail['body'] .= " user:$userObj->login\n";
$mail['body'] .= " first name:$userObj->firstName surname:$userObj->lastName\n";
$mail['body'] .= " email:{$userObj->emailAddress}\n";
// silence errors
@email_send(config_get('from_email'), $mail['to'], $mail['subject'], $mail['body']);
}