本文整理汇总了PHP中User::Save方法的典型用法代码示例。如果您正苦于以下问题:PHP User::Save方法的具体用法?PHP User::Save怎么用?PHP User::Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User::Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUser
function testUser()
{
$this->startCodeCoverage();
$user = new User();
$user->Id = "non_numeric";
if (!($user->SetPassword("blah") === false)) {
$this->fail("User::SetPassword didn't return false for non-numeric user id");
return 1;
}
if (!($user->IsAdmin() === false)) {
$this->fail("User::IsAdmin didn't return false for non-numeric user id");
return 1;
}
$user->Id = "";
$user->Email = "";
if (!($user->GetName() === false)) {
$this->fail("User::GetName didn't return false when given no user id");
return 1;
}
if (!($user->IsAdmin() === false)) {
$this->fail("User::Exists didn't return false for no user id and no email");
return 1;
}
$user->Email = "simpletest@localhost";
if ($user->Exists() === false) {
$this->fail("User::Exists returned false even though user exists");
return 1;
}
$id = $user->GetIdFromEmail("simpletest@localhost");
if ($id === false) {
$this->fail("User::GetIdFromEmail returned false for a valid user");
return 1;
}
$user->Id = $id;
$user->Admin = "1";
$user->FirstName = "administrator";
$user->Institution = "Kitware Inc.";
if ($user->Exists() != true) {
$this->fail("User::Exists failed given a valid user id");
return 1;
}
$user->Password = md5("simpletest");
// Coverage for update save
$user->Save();
// Coverage for SetPassword
$user->SetPassword(md5("simpletest"));
$this->stopCodeCoverage();
return 0;
}
示例2: testUser
public function testUser()
{
$this->startCodeCoverage();
$user = new User();
$user->Id = 'non_numeric';
if (!($user->SetPassword('blah') === false)) {
$this->fail("User::SetPassword didn't return false for non-numeric user id");
return 1;
}
if (!($user->IsAdmin() === false)) {
$this->fail("User::IsAdmin didn't return false for non-numeric user id");
return 1;
}
$user->Id = '';
$user->Email = '';
if (!($user->GetName() === false)) {
$this->fail("User::GetName didn't return false when given no user id");
return 1;
}
if (!($user->IsAdmin() === false)) {
$this->fail("User::Exists didn't return false for no user id and no email");
return 1;
}
$user->Email = 'simpletest@localhost';
if ($user->Exists() === false) {
$this->fail('User::Exists returned false even though user exists');
return 1;
}
$id = $user->GetIdFromEmail('simpletest@localhost');
if ($id === false) {
$this->fail('User::GetIdFromEmail returned false for a valid user');
return 1;
}
$user->Id = $id;
$user->Admin = '1';
$user->FirstName = 'administrator';
$user->Institution = 'Kitware Inc.';
if ($user->Exists() != true) {
$this->fail('User::Exists failed given a valid user id');
return 1;
}
$user->Password = md5('simpletest');
// Coverage for update save
$user->Save();
// Coverage for SetPassword
$user->SetPassword(md5('simpletest'));
$this->stopCodeCoverage();
return 0;
}
示例3: saveUser
public function saveUser($req)
{
$profileVar = SIGN_IN_ELEMENT_MAPPING_FIELD_NAME;
$profileClass = ucfirst(SIGN_IN_ELEMENT_MAPPING_FIELD_NAME);
if ($this->user->user_level == 'Admin') {
$user = new User();
$user->Load("email = ?", array($req->email));
if ($user->email == $req->email) {
return new IceResponse(IceResponse::ERROR, "User with same email already exists");
}
$user->Load("username = ?", array($req->username));
if ($user->username == $req->username) {
return new IceResponse(IceResponse::ERROR, "User with same username already exists");
}
$user = new User();
$user->email = $req->email;
$user->username = $req->username;
$password = $this->generateRandomString(6);
$user->password = md5($password);
$user->profile = empty($req->profile) || $req->profile == "NULL" ? NULL : $req->profile;
$user->user_level = $req->user_level;
$user->last_login = date("Y-m-d H:i:s");
$user->last_update = date("Y-m-d H:i:s");
$user->created = date("Y-m-d H:i:s");
$profile = null;
if (!empty($user->profile)) {
$profile = $this->baseService->getElement($profileClass, $user->profile, null, true);
}
$ok = $user->Save();
if (!$ok) {
LogManager::getInstance()->info($user->ErrorMsg() . "|" . json_encode($user));
return new IceResponse(IceResponse::ERROR, "Error occured while saving the user");
}
$user->password = "";
$user = $this->baseService->cleanUpAdoDB($user);
if (!empty($this->emailSender)) {
$usersEmailSender = new UsersEmailSender($this->emailSender, $this);
$usersEmailSender->sendWelcomeUserEmail($user, $password, $profile);
}
return new IceResponse(IceResponse::SUCCESS, $user);
}
return new IceResponse(IceResponse::ERROR, "Not Allowed");
}
示例4: saveUser
public function saveUser($req)
{
if ($this->user->user_level == 'Admin') {
$user = new User();
$user->Load("email = ?", array($req->email));
if ($user->email == $req->email) {
return new IceResponse(IceResponse::ERROR, "User with same email already exists");
}
$user->Load("username = ?", array($req->username));
if ($user->username == $req->username) {
return new IceResponse(IceResponse::ERROR, "User with same username already exists");
}
$user = new User();
$user->email = $req->email;
$user->username = $req->username;
$password = $this->generateRandomString(6);
$user->password = md5($password);
$user->employee = empty($req->employee) || $req->employee == "NULL" ? NULL : $req->employee;
$user->user_level = $req->user_level;
$user->last_login = date("Y-m-d H:i:s");
$user->last_update = date("Y-m-d H:i:s");
$user->created = date("Y-m-d H:i:s");
$employee = null;
if (!empty($user->employee)) {
$employee = $this->baseService->getElement('Employee', $user->employee, null, true);
}
$ok = $user->Save();
if (!$ok) {
error_log($user->ErrorMsg() . "|" . json_encode($user));
return new IceResponse(IceResponse::ERROR, "Error occured while saving the user");
}
$user->password = "";
$user = $this->baseService->cleanUpAdoDB($user);
if (!empty($this->emailSender)) {
$usersEmailSender = new UsersEmailSender($this->emailSender, $this);
$usersEmailSender->sendWelcomeUserEmail($user, $password, $employee);
}
return new IceResponse(IceResponse::SUCCESS, $user);
}
return new IceResponse(IceResponse::ERROR, "Not Allowed");
}
示例5: createNewUsers
protected function createNewUsers()
{
$profileVar = SIGN_IN_ELEMENT_MAPPING_FIELD_NAME;
$profileClass = ucfirst(SIGN_IN_ELEMENT_MAPPING_FIELD_NAME);
$user = new User();
$user->username = 'manager';
$user->email = 'manager@icehrm-test.com';
$user->password = '21232f297a57a5a743894a0e4a801fc3';
$user->user_level = 'Manager';
$user->Save();
$this->usersArray[$user->username] = $user;
$user = new User();
$user->username = 'profile';
$user->email = 'profile@icehrm-test.com';
$user->password = '21232f297a57a5a743894a0e4a801fc3';
$user->user_level = 'Profile';
$user->Save();
$this->usersArray[$user->username] = $user;
$user = new User();
$user->Load("username = ?", array('admin'));
$this->usersArray[$user->username] = $user;
}
示例6: testSetup
public function testSetup()
{
// Create a project with GitHub credentials named CDash.
global $configure;
$settings = ['Name' => 'CDash', 'Description' => 'CDash', 'CvsUrl' => 'github.com/Kitware/CDash', 'CvsViewerType' => 'github', 'BugTrackerFileUrl' => 'http://public.kitware.com/Bug/view.php?id=', 'repositories' => [['url' => 'https://github.com/Kitware/CDash', 'branch' => 'master', 'username' => $configure['github_username'], 'password' => $configure['github_password']]]];
$this->ProjectId = $this->createProject($settings);
// Create some users for the CDash project.
$users_details = array(array('email' => 'dan.lamanna@kitware.com', 'firstname' => 'Dan', 'lastname' => 'LaManna'), array('email' => 'jamie.snape@kitware.com', 'firstname' => 'Jamie', 'lastname' => 'Snape'), array('email' => 'zack.galbreath@kitware.com', 'firstname' => 'Zack', 'lastname' => 'Galbreath'));
$userproject = new UserProject();
$userproject->ProjectId = $this->ProjectId;
foreach ($users_details as $user_details) {
$user = new User();
$user->Email = $user_details['email'];
$user->FirstName = $user_details['firstname'];
$user->LastName = $user_details['lastname'];
$user->Password = md5('12345');
$user->Institution = 'Kitware';
$user->Admin = 0;
$user->Save();
$user->AddProject($userproject);
$this->Users[] = $user;
}
}
示例7: User
$password_is_good = false;
if ($CDASH_PASSWORD_COMPLEXITY_COUNT > 1) {
$error_msg = "Your password must contain at least {$CDASH_PASSWORD_COMPLEXITY_COUNT} characters from {$CDASH_MINIMUM_PASSWORD_COMPLEXITY} of the following types: uppercase, lowercase, numbers, and symbols.";
} else {
$error_msg = "Your password must contain at least {$CDASH_MINIMUM_PASSWORD_COMPLEXITY} of the following: uppercase, lowercase, numbers, and symbols.";
}
}
}
if (!$password_is_good) {
$xml .= "<error>{$error_msg}</error>";
} else {
$user = new User();
$user->Id = $userid;
$user->Fill();
$user->Password = $md5pass;
if ($user->Save()) {
$xml .= '<error>Your password has been updated.</error>';
unset($_SESSION['cdash']['redirect']);
} else {
$xml .= '<error>Cannot update password.</error>';
}
add_last_sql_error('editUser.php');
}
}
$xml .= '<user>';
$user = pdo_query('SELECT * FROM ' . qid('user') . " WHERE id='{$userid}'");
$user_array = pdo_fetch_array($user);
$xml .= add_XML_value('id', $userid);
$xml .= add_XML_value('firstname', $user_array['firstname']);
$xml .= add_XML_value('lastname', $user_array['lastname']);
$xml .= add_XML_value('email', $user_array['email']);
示例8: endElement
/** endElement function */
public function endElement($parser, $name)
{
parent::endElement($parser, $name);
global $CDASH_DELETE_OLD_SUBPROJECTS;
if (!$this->ProjectNameMatches) {
return;
}
if ($name == 'PROJECT') {
foreach ($this->SubProjects as $subproject) {
if ($CDASH_DELETE_OLD_SUBPROJECTS) {
// Remove dependencies that do not exist anymore,
// but only for those relationships where both sides
// are present in $this->SubProjects.
//
$dependencyids = $subproject->GetDependencies();
$removeids = array_diff($dependencyids, $this->Dependencies[$subproject->GetId()]);
foreach ($removeids as $removeid) {
if (array_key_exists($removeid, $this->SubProjects)) {
$subproject->RemoveDependency($removeid);
} else {
$dep = pdo_get_field_value("SELECT name FROM subproject WHERE id='{$removeid}'", 'name', "{$removeid}");
add_log("Not removing dependency {$dep}({$removeid}) from " . $subproject->GetName() . 'because it is not a SubProject element in this Project.xml file', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid);
}
}
}
// Add dependencies that were queued up as we processed the DEPENDENCY
// elements:
//
foreach ($this->Dependencies[$subproject->GetId()] as $addid) {
if (array_key_exists($addid, $this->SubProjects)) {
$subproject->AddDependency($addid);
} else {
add_log('impossible condition: should NEVER see this: unknown DEPENDENCY clause should prevent this case', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid);
}
}
}
if ($CDASH_DELETE_OLD_SUBPROJECTS) {
// Delete old subprojects that weren't included in this file.
$previousSubProjectIds = $this->Project->GetSubProjects();
foreach ($previousSubProjectIds as $previousId) {
$found = false;
foreach ($this->SubProjects as $subproject) {
if ($subproject->GetId() == $previousId) {
$found = true;
break;
}
}
if (!$found) {
$subProjectToRemove = new SubProject();
$subProjectToRemove->SetId($previousId);
$subProjectToRemove->Delete();
add_log("Deleted " . $subProjectToRemove->GetName() . " because it was not mentioned in Project.xml", 'ProjectHandler:endElement', LOG_WARNING, $this->projectid);
}
}
}
} elseif ($name == 'SUBPROJECT') {
// Insert the SubProject.
$this->SubProject->Save();
// Insert the label.
$Label = new Label();
$Label->Text = $this->SubProject->GetName();
$Label->Insert();
$this->SubProjects[$this->SubProject->GetId()] = $this->SubProject;
// Handle dependencies here too.
$this->Dependencies[$this->SubProject->GetId()] = array();
foreach ($this->CurrentDependencies as $dependencyid) {
$added = false;
if ($dependencyid !== false && is_numeric($dependencyid)) {
if (array_key_exists($dependencyid, $this->SubProjects)) {
$this->Dependencies[$this->SubProject->GetId()][] = $dependencyid;
$added = true;
}
}
if (!$added) {
add_log('Project.xml DEPENDENCY of ' . $this->SubProject->GetName() . ' not mentioned earlier in file.', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid);
}
}
// Check if the user is in the database.
$User = new User();
$posat = strpos($this->Email, '@');
if ($posat !== false) {
$User->FirstName = substr($this->Email, 0, $posat);
$User->LastName = substr($this->Email, $posat + 1);
} else {
$User->FirstName = $this->Email;
$User->LastName = $this->Email;
}
$User->Email = $this->Email;
$User->Password = md5($this->Email);
$User->Admin = 0;
$userid = $User->GetIdFromEmail($this->Email);
if (!$userid) {
$User->Save();
$userid = $User->Id;
}
// Insert into the UserProject
$UserProject = new UserProject();
$UserProject->EmailType = 3;
// any build
//.........这里部分代码省略.........
示例9: AddUser
static function AddUser($fields, $use_captcha = false)
{
$data = array();
$validator = new Validate();
$result = $validator->AddValue('username', $fields['username'])->AddPattern('username-unique')->AddValue('email', $fields['email'])->AddPattern('email-unique')->Check();
if (isset($fields['password'])) {
$result = $validator->AddValue('password', $fields['password'])->AddPattern('password')->Check() && $result;
}
if (isset($fields['cpassword'])) {
$result = $validator->AddValue('cpassword', $fields['cpassword'])->AddRule('match', $fields['password'])->Check() && $result;
}
if ($use_captcha) {
$result = Validate::ValidCaptcha($fields['recaptcha_challenge_field'], $fields['recaptcha_response_field']) && $result;
}
if ($result) {
$data['username'] = $fields['username'];
$data['email'] = $fields['email'];
$data['password'] = isset($fields['password']) ? Validate::Encrypt($fields['password']) : '';
$data['user_type'] = isset($fields['user_type']) && $fields['user_type'] == 'admin' ? 'admin' : 'user';
$data['activation_state'] = isset($fields['activation_state']) && $fields['activation_state'] == '1' ? '1' : '0';
$info = array('phone', 'about', 'location', 'fullname', 'gender', 'social_id', 'social_type', 'activation_key', 'avatar');
foreach ($info as $value) {
$data[$value] = isset($fields[$value]) ? Validate::Escape($fields[$value]) : '';
}
$new_user = new User($data);
if ($new_user->Save()) {
return $new_user;
} else {
Error::Set("database", "databaseinsert");
}
}
return false;
}
示例10: recharge
public function recharge()
{
$curUser = $this->checkLogin('enekpani');
$user = new User($_POST['loginId']);
//crediting account
if (isset($_POST['creditaccount'])) {
$errorMsg = '';
//validation
if (trim($_POST['qnt']) == '' || $_POST['qnt'] < 1) {
$errorMsg = 'You must specify the quantity and it must not be less than one';
}
if ($errorMsg == '') {
if ($_POST['transType'] == 'credit') {
////check if admin have enogh
//if($curUser->Balance )
$user->Balance += $_POST['qnt'];
$qnt = abs($_POST['qnt']);
//$curUser->Balance -= $_POST['qnt'];
} else {
if ($user->Balance >= $_POST['qnt']) {
$user->Balance -= $_POST['qnt'];
$qnt = -abs($_POST['qnt']);
//$curUser->Balance += $_POST['qnt'];
} else {
$errorMsg = $user->Name . ' do not have up to ' . $_POST['qnt'] . ' units';
}
}
if ($errorMsg == '') {
$success = $this->deductAccount($qnt);
if ($success) {
//if($curUser->LoginId != $user->LoginId){
// $curUser->Save();
//}
$user->Save();
$errorMsg = 'Transaction saved';
} else {
$errorMsg = "Low master account balance";
}
}
}
}
$error_code = $errorMsg == 'Transaction saved' ? 0 : 1;
header('Location: ' . URL . 'users/manage/' . $_POST['loginId'] . '?notification=' . $errorMsg . '&error_code=' . $error_code);
exit;
}
示例11: Reactivate
static function Reactivate($fields)
{
$validator = new Validate();
$result = $validator->AddValue('email', $fields['email'])->AddPattern('email')->Check();
if (Config::Get("validation.use_captcha")) {
$result = Validate::ValidCaptcha($fields['recaptcha_challenge_field'], $fields['recaptcha_response_field']);
}
if ($result) {
$user = new User();
$result = $user->Load(array('email' => $fields['email']));
if ($result) {
if ($user->Get('activation_state') == '1') {
Error::Set("email", "alreadyactivated");
} else {
$key = md5(time() . $fields['email']);
$user->Set("activation_key", $key);
$user->Save();
$url = Config::Get("base_url") . "auth/activate.php?key=" . $key;
$url = '<a href="' . $url . '">' . $url . '</a>';
Email::SendEmail($fields['email'], Config::Get("success.activation_subject"), Config::Get("success.activation_message") . $url);
return true;
}
} else {
Error::Set("email", "usernotfound");
}
}
return false;
}
示例12: startElement
/** startElement function */
public function startElement($parser, $name, $attributes)
{
parent::startElement($parser, $name, $attributes);
// Check that the project name matches
if ($name == 'PROJECT') {
if (get_project_id($attributes['NAME']) != $this->projectid) {
add_log("Wrong project name: " . $attributes['NAME'], "ProjectHandler::startElement", LOG_ERR, $this->projectid);
$this->ProjectNameMatches = false;
}
}
if (!$this->ProjectNameMatches) {
return;
}
if ($name == 'PROJECT') {
$this->SubProjects = array();
$this->Dependencies = array();
} else {
if ($name == 'SUBPROJECT') {
$this->SubProject = new SubProject();
$this->SubProject->SetProjectId($this->projectid);
$this->SubProject->SetName($attributes['NAME']);
if (array_key_exists("GROUP", $attributes)) {
$this->SubProject->SetGroup($attributes['GROUP']);
}
$this->SubProject->Save();
// Insert the label
$Label = new Label();
$Label->Text = $this->SubProject->GetName();
$Label->Insert();
$this->SubProjects[$this->SubProject->GetId()] = $this->SubProject;
$this->Dependencies[$this->SubProject->GetId()] = array();
} else {
if ($name == 'DEPENDENCY') {
// A DEPENDENCY is expected to be:
//
// - another subproject that already exists (from a previous element in
// this submission)
//
$dependentProject = new SubProject();
$dependentProject->SetName($attributes['NAME']);
$dependentProject->SetProjectId($this->projectid);
// The subproject's Id is automatically loaded once its name & projectid
// are set.
$dependencyid = $dependentProject->GetId();
$added = false;
if ($dependencyid !== false && is_numeric($dependencyid)) {
if (array_key_exists($dependencyid, $this->SubProjects)) {
$this->Dependencies[$this->SubProject->GetId()][] = $dependencyid;
$added = true;
}
}
if (!$added) {
add_log("Project.xml DEPENDENCY of " . $this->SubProject->GetName() . " not mentioned earlier in file: " . $attributes['NAME'], "ProjectHandler:startElement", LOG_WARNING, $this->projectid);
}
} else {
if ($name == 'EMAIL') {
$email = $attributes['ADDRESS'];
// Check if the user is in the database
$User = new User();
$posat = strpos($email, '@');
if ($posat !== false) {
$User->FirstName = substr($email, 0, $posat);
$User->LastName = substr($email, $posat + 1);
} else {
$User->FirstName = $email;
$User->LastName = $email;
}
$User->Email = $email;
$User->Password = md5($email);
$User->Admin = 0;
$userid = $User->GetIdFromEmail($email);
if (!$userid) {
$User->Save();
$userid = $User->Id;
}
// Insert into the UserProject
$UserProject = new UserProject();
$UserProject->EmailType = 3;
// any build
$UserProject->EmailCategory = 54;
// everything except warnings
$UserProject->UserId = $userid;
$UserProject->ProjectId = $this->projectid;
$UserProject->Save();
// Insert the labels for this user
$LabelEmail = new LabelEmail();
$LabelEmail->UserId = $userid;
$LabelEmail->ProjectId = $this->projectid;
$Label = new Label();
$Label->SetText($this->SubProject->GetName());
$labelid = $Label->GetIdFromText();
if (!empty($labelid)) {
$LabelEmail->LabelId = $labelid;
$LabelEmail->Insert();
}
}
}
}
}
//.........这里部分代码省略.........
示例13: Login
public static function Login(UserCredentials $credentials)
{
//Credentials check
$res = 0;
if ($credentials->Email && $credentials->Password) {
$res = 3;
$user = new User($credentials->Email);
if ($user->mExists) {
$res = 2;
if ($user->CheckPassword($credentials->Password)) {
$res = 4;
//check if user is banned
if (!$user->IsBanned()) {
//Login :)
$user->IsOnline = true;
$user->LastLogin = date('Y-m-d H:i:s');
$user->Save();
$res = 1;
}
}
}
}
return array('res' => $res, 'userid' => $user->Id);
}
示例14: ldapAuthenticate
/** LDAP authentication */
function ldapAuthenticate($email, $password, $SessionCachePolicy, $rememberme)
{
global $loginerror;
$loginerror = '';
include dirname(__DIR__) . '/config/config.php';
include_once 'models/user.php';
$ldap = ldap_connect($CDASH_LDAP_HOSTNAME);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $CDASH_LDAP_PROTOCOL_VERSION);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, $CDASH_LDAP_OPT_REFERRALS);
// Bind as the LDAP user if authenticated ldap is enabled
if ($CDASH_LDAP_AUTHENTICATED) {
ldap_bind($ldap, $CDASH_LDAP_BIND_DN, $CDASH_LDAP_BIND_PASSWORD);
}
if (isset($ldap) && $ldap != '') {
/* search for pid dn */
$result = ldap_search($ldap, $CDASH_LDAP_BASEDN, '(&(mail=' . $email . ')' . $CDASH_LDAP_FILTER . ')', array('dn', 'cn'));
if ($result != 0) {
$entries = ldap_get_entries($ldap, $result);
@($principal = $entries[0]['dn']);
if (isset($principal)) {
// bind as this user
if (@ldap_bind($ldap, $principal, $password) and strlen(trim($password)) != 0) {
$sql = 'SELECT id,password FROM ' . qid('user') . " WHERE email='" . pdo_real_escape_string($email) . "'";
$result = pdo_query("{$sql}");
// If the user doesn't exist we add it
if (pdo_num_rows($result) == 0) {
@($givenname = $entries[0]['cn'][0]);
if (!isset($givenname)) {
$loginerror = 'No givenname (cn) set in LDAP, cannot register user into CDash';
return false;
}
$names = explode(' ', $givenname);
$User = new User();
if (count($names) > 1) {
$User->FirstName = $names[0];
$User->LastName = $names[1];
for ($i = 2; $i < count($names); $i++) {
$User->LastName .= ' ' . $names[$i];
}
} else {
$User->LastName = $names[0];
}
// Add the user in the database
$storedPassword = md5($password);
$User->Email = $email;
$User->Password = $storedPassword;
$User->Save();
$userid = $User->Id;
} else {
$user_array = pdo_fetch_array($result);
$storedPassword = $user_array['password'];
$userid = $user_array['id'];
// If the password has changed we update
if ($storedPassword != md5($password)) {
$User = new User();
$User->Id = $userid;
$User->SetPassword(md5($password));
}
}
if ($rememberme) {
$cookiename = 'CDash-' . $_SERVER['SERVER_NAME'];
$time = time() + 60 * 60 * 24 * 30;
// 30 days;
// Create a new password
$keychars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$length = 32;
$key = '';
$max = strlen($keychars) - 1;
for ($i = 0; $i <= $length; $i++) {
// random_int is available in PHP 7 and the random_compat PHP 5.x
// polyfill included in the Composer package.json dependencies.
$key .= substr($keychars, random_int(0, $max), 1);
}
$value = $userid . $key;
setcookie($cookiename, $value, $time);
// Update the user key
pdo_query('UPDATE ' . qid('user') . " SET cookiekey='" . $key . "' WHERE id=" . qnum($userid));
}
session_name('CDash');
session_cache_limiter($SessionCachePolicy);
session_set_cookie_params($CDASH_COOKIE_EXPIRATION_TIME);
@ini_set('session.gc_maxlifetime', $CDASH_COOKIE_EXPIRATION_TIME + 600);
session_start();
// create the session array
if (isset($_SESSION['cdash']['password'])) {
$password = $_SESSION['cdash']['password'];
}
$sessionArray = array('login' => $email, 'passwd' => $storedPassword, 'ID' => session_id(), 'valid' => 1, 'loginid' => $userid);
$_SESSION['cdash'] = $sessionArray;
return true;
} else {
$loginerror = 'Wrong email or password.';
return false;
}
} else {
$loginerror = 'User not found in LDAP';
}
ldap_free_result($result);
} else {
//.........这里部分代码省略.........
示例15: array
// Get the long lasting token credentials
$token_credentials = $connection->getAccessToken($_GET['oauth_verifier']);
// Grab the details of this user
$details = $connection->get("profile/details");
// Save it to the database
$myUser->ResetValues();
// Check to see if this user is already in the DB
$myUser->SetValue('username', $details->response->username);
$myUser->GetInfo(NULL, array('username'));
// Add the new token credentials
$myUser->SetValue('oauth_token', $token_credentials['oauth_token']);
$myUser->SetValue('oauth_token_secret', $token_credentials['oauth_token_secret']);
// Create a unique ID for the session
$myUser->SetValue('sessionid', uniqid());
// Update the user information if found or insert if new
if (!$myUser->Save()) {
throw new SimplException('Error Saving Formspring Client Token', 2, 'Error: Error Saving Formspring Client Token :' . $details->response->username);
}
// Set the session cookie
if (!isset($_GET['delegate'])) {
setcookie('session', $myUser->GetValue('sessionid'), time() + 3600 * 24 * 7);
} else {
// Setup the relationship
$myAccountAccess->SetValue('user_id', $_GET['delegate']);
$myAccountAccess->SetValue('delegate_id', $myUser->GetPrimary());
$myAccountAccess->SetValue('type', 'full');
if (!$myAccountAccess->Save()) {
throw new SimplException('Error Saving Delegate Information', 2, 'Error: Error Saving Delegate Information. Delegate:' . $_GET['delegate']);
}
}
// See if this user already exists in the DB