本文整理汇总了PHP中Member::write方法的典型用法代码示例。如果您正苦于以下问题:PHP Member::write方法的具体用法?PHP Member::write怎么用?PHP Member::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Member
的用法示例。
在下文中一共展示了Member::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doApprove
public function doApprove()
{
$exist = Member::get()->filter(array('Email' => $this->Email))->first();
if ($exist) {
return false;
}
$member = new Member();
$data = $this->toMap();
unset($data['ID']);
unset($data['ClassName']);
unset($data['UnapprovedMember']);
$member->update($data);
$member->write();
if ($this->MemberType === 'Organization') {
$member->addToGroupByCode('organization');
$organization = new Organization();
$organization->AccountID = $member->ID;
$organization->company_name = $this->OrganizationName;
$organizationID = $organization->write();
$member->OrganizationID = $organizationID;
$member->write();
} else {
$member->addToGroupByCode('personal');
}
$this->setField('Approved', true);
$this->write();
return true;
}
示例2: Member
function testDefaultPasswordEncryptionDoesntChangeExistingMembers()
{
$member = new Member();
$member->Password = 'mypassword';
$member->PasswordEncryption = 'sha1_v2.4';
$member->write();
$origAlgo = Security::get_password_encryption_algorithm();
Security::set_password_encryption_algorithm('none');
$member->Password = 'mynewpassword';
$member->write();
$this->assertEquals($member->PasswordEncryption, 'sha1_v2.4');
$result = $member->checkPassword('mynewpassword');
$this->assertTrue($result->valid());
Security::set_password_encryption_algorithm($origAlgo);
}
示例3: onAfterInit
/**
* If the REMOTE_USER is set and is in the Member table, log that member in. If
* not, and Config::inst()->get('AuthRemoteUserExtension', 'auto_create_user') is set, add that
* Member to the configured group, and log the new user in. Otherwise, do nothing.
*/
public function onAfterInit()
{
if (isset($_SERVER['REMOTE_USER'])) {
$unique_identifier = $_SERVER['REMOTE_USER'];
} elseif (isset($_SERVER['REDIRECT_REMOTE_USER'])) {
$unique_identifier = $_SERVER['REDIRECT_REMOTE_USER'];
}
if (isset($unique_identifier)) {
$unique_identifier_field = Member::config()->unique_identifier_field;
$member = Member::get()->filter($unique_identifier_field, $unique_identifier)->first();
if ($member) {
$member->logIn();
$this->owner->redirectBack();
} elseif (Config::inst()->get('AuthRemoteUserExtension', 'auto_create_user') && strlen(Config::inst()->get('AuthRemoteUserExtension', 'auto_user_group'))) {
$group = Group::get()->filter('Title', Config::inst()->get('AuthRemoteUserExtension', 'auto_user_group'))->first();
if ($group) {
$member = new Member();
$member->{$unique_identifier_field} = $unique_identifier;
$member->write();
$member->Groups()->add($group);
$member->logIn();
}
}
}
}
开发者ID:helpfulrobot,项目名称:quinninteractive-silverstripe-auth-remote-user,代码行数:30,代码来源:AuthRemoteUserExtension.php
示例4: createAndLoginUser
/**
* creates and logs in a temporary user.
*
*/
private function createAndLoginUser()
{
$this->username = "TEMPLATEOVERVIEW_URLCHECKER___";
$this->password = rand(1000000000, 9999999999);
//Make temporary admin member
$adminMember = Member::get()->filter(array("Email" => $this->username))->first();
if ($adminMember != NULL) {
$adminMember->delete();
}
$this->member = new Member();
$this->member->Email = $this->username;
$this->member->Password = $this->password;
$this->member->write();
$adminGroup = Group::get()->filter(array("code" => "administrators"))->first();
if (!$adminGroup) {
user_error("No admin group exists");
}
$this->member->Groups()->add($adminGroup);
curl_setopt($this->ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
$loginUrl = Director::absoluteURL('/Security/LoginForm');
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($this->ch, CURLOPT_URL, $loginUrl);
curl_setopt($this->ch, CURLOPT_POST, 1);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, 'Email=' . $this->username . '&Password=' . $this->password);
//execute the request (the login)
$loginContent = curl_exec($this->ch);
$httpCode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
$err = curl_errno($this->ch);
$errmsg = curl_error($this->ch);
$header = curl_getinfo($this->ch);
if ($httpCode != 200) {
echo "<span style='color:red'>There was an error logging in!</span><br />";
}
}
示例5: authenticate
/**
* Performs the login, but will also create and sync the Member record on-the-fly, if not found.
*
* @param array $data
* @param Form $form
* @return bool|Member|void
* @throws SS_HTTPResponse_Exception
*/
public static function authenticate($data, Form $form = null)
{
$service = Injector::inst()->get('LDAPService');
$result = $service->authenticate($data['Username'], $data['Password']);
$success = $result['success'] === true;
if (!$success) {
if ($form) {
$form->sessionMessage($result['message'], 'bad');
}
return;
}
$data = $service->getUserByUsername($result['identity']);
if (!$data) {
if ($form) {
$form->sessionMessage(_t('LDAPAuthenticator.PROBLEMFINDINGDATA', 'There was a problem retrieving your user data'), 'bad');
}
return;
}
// LDAPMemberExtension::memberLoggedIn() will update any other AD attributes mapped to Member fields
$member = Member::get()->filter('GUID', $data['objectguid'])->limit(1)->first();
if (!($member && $member->exists())) {
$member = new Member();
$member->GUID = $data['objectguid'];
$member->write();
}
Session::clear('BackURL');
return $member;
}
示例6: finish
public function finish($data, $form)
{
parent::finish($data, $form);
$steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");
if ($steps) {
foreach ($steps as $step) {
if ($step->class == 'Page2PersonalDetailsFormStep') {
$member = new Member();
$data = $step->loadData();
if ($data) {
$member->update($data);
$member->write();
}
}
if ($step->class == 'Page2OrganisationDetailsFormStep') {
$organisation = new Organisation();
$data = $step->loadData();
if ($data) {
$organisation->update($data);
if ($member && $member->ID) {
$organisation->MemberID = $member->ID;
}
$organisation->write();
}
}
// Debug::show($step->loadData()); // Shows the step data (unserialized by loadData)
}
}
$controller = $this->getController();
$controller->redirect($controller->Link() . 'finished');
}
示例7: testAuthenticateByTempID
/**
* Test that a member can be authenticated via their temp id
*/
public function testAuthenticateByTempID()
{
$member = new Member();
$member->Email = 'test1@test.com';
$member->PasswordEncryption = "sha1";
$member->Password = "mypassword";
$member->write();
// Make form
$controller = new Security();
$form = new Form($controller, 'Form', new FieldList(), new FieldList());
// If the user has never logged in, then the tempid should be empty
$tempID = $member->TempIDHash;
$this->assertEmpty($tempID);
// If the user logs in then they have a temp id
$member->logIn(true);
$tempID = $member->TempIDHash;
$this->assertNotEmpty($tempID);
// Test correct login
$result = MemberAuthenticator::authenticate(array('tempid' => $tempID, 'Password' => 'mypassword'), $form);
$this->assertNotEmpty($result);
$this->assertEquals($result->ID, $member->ID);
$this->assertEmpty($form->Message());
// Test incorrect login
$form->clearMessage();
$result = MemberAuthenticator::authenticate(array('tempid' => $tempID, 'Password' => 'notmypassword'), $form);
$this->assertEmpty($result);
$this->assertEquals('The provided details don't seem to be correct. Please try again.', $form->Message());
$this->assertEquals('bad', $form->MessageType());
}
示例8: doSave
function doSave($data, $form)
{
if (isset($data['Password']) && is_array($data['Password'])) {
$data['Password'] = $data['Password']['_Password'];
}
// We need to ensure that the unique field is never overwritten
$uniqueField = Member::get_unique_identifier_field();
if (isset($data[$uniqueField])) {
$SQL_unique = Convert::raw2sql($data[$uniqueField]);
$existingUniqueMember = Member::get()->filter(array($uniqueField => $SQL_unique))->first();
if ($existingUniqueMember && $existingUniqueMember->exists()) {
if (Member::currentUserID() != $existingUniqueMember->ID) {
die("current member does not match enrolled member.");
return false;
}
}
}
$member = Member::currentUser();
if (!$member) {
$member = new Member();
}
$member->update($data);
$member->write();
$arrayExtraFields = array();
if (isset($data["SelectedOption"])) {
$arrayExtraFields["SelectedOption"] = $data["SelectedOption"];
}
if (isset($data["BookingCode"])) {
$arrayExtraFields["BookingCode"] = $data["BookingCode"];
}
$this->controller->addAttendee($member, $arrayExtraFields);
$this->redirect($this->getController()->Link("thankyou"));
return;
}
示例9: createUser
private function createUser()
{
// create user
$u = new Member();
$u->write();
$s = new \Ntb\SocialIdentity(['UserID' => 'foo_user', 'AuthService' => 'facebook', 'MemberID' => $u->ID]);
$s->write();
}
示例10: acs
/**
* Assertion Consumer Service
*
* The user gets sent back here after authenticating with the IdP, off-site.
* The earlier redirection to the IdP can be found in the SAMLAuthenticator::authenticate.
*
* After this handler completes, we end up with a rudimentary Member record (which will be created on-the-fly
* if not existent), with the user already logged in. Login triggers memberLoggedIn hooks, which allows
* LDAP side of this module to finish off loading Member data.
*
* @throws OneLogin_Saml2_Error
*/
public function acs()
{
$auth = Injector::inst()->get('SAMLHelper')->getSAMLAuth();
$auth->processResponse();
$error = $auth->getLastErrorReason();
if (!empty($error)) {
SS_Log::log($error, SS_Log::ERR);
Form::messageForForm("SAMLLoginForm_LoginForm", "Authentication error: '{$error}'", 'bad');
Session::save();
return $this->getRedirect();
}
if (!$auth->isAuthenticated()) {
Form::messageForForm("SAMLLoginForm_LoginForm", _t('Member.ERRORWRONGCRED'), 'bad');
Session::save();
return $this->getRedirect();
}
$decodedNameId = base64_decode($auth->getNameId());
// check that the NameID is a binary string (which signals that it is a guid
if (ctype_print($decodedNameId)) {
Form::messageForForm("SAMLLoginForm_LoginForm", "Name ID provided by IdP is not a binary GUID.", 'bad');
Session::save();
return $this->getRedirect();
}
// transform the NameId to guid
$guid = LDAPUtil::bin_to_str_guid($decodedNameId);
if (!LDAPUtil::validGuid($guid)) {
$errorMessage = "Not a valid GUID '{$guid}' recieved from server.";
SS_Log::log($errorMessage, SS_Log::ERR);
Form::messageForForm("SAMLLoginForm_LoginForm", $errorMessage, 'bad');
Session::save();
return $this->getRedirect();
}
// Write a rudimentary member with basic fields on every login, so that we at least have something
// if LDAP synchronisation fails.
$member = Member::get()->filter('GUID', $guid)->limit(1)->first();
if (!($member && $member->exists())) {
$member = new Member();
$member->GUID = $guid;
}
$attributes = $auth->getAttributes();
foreach ($member->config()->claims_field_mappings as $claim => $field) {
if (!isset($attributes[$claim][0])) {
SS_Log::log(sprintf('Claim rule \'%s\' configured in LDAPMember.claims_field_mappings, but wasn\'t passed through. Please check IdP claim rules.', $claim), SS_Log::WARN);
continue;
}
$member->{$field} = $attributes[$claim][0];
}
$member->SAMLSessionIndex = $auth->getSessionIndex();
// This will throw an exception if there are two distinct GUIDs with the same email address.
// We are happy with a raw 500 here at this stage.
$member->write();
// This will trigger LDAP update through LDAPMemberExtension::memberLoggedIn.
// Both SAML and LDAP identify Members by the GUID field.
$member->logIn();
return $this->getRedirect();
}
示例11: testDeletesOpauthIdentityOnDelete
public function testDeletesOpauthIdentityOnDelete()
{
$member = new Member(array('Email' => 'test@test.com'));
$member->write();
$identity = new OpauthIdentity();
$identity->write();
$member->OpauthIdentities()->add($identity);
$member->delete();
$this->assertEquals(0, $member->OpauthIdentities()->Count());
}
示例12: createMember
protected function createMember()
{
$email = $this->getValidEmailInput();
if ($email !== false) {
$member = new Member(['Email' => $email, 'Password' => $this->getPasswordFromInputOrEmail($email), 'FirstName' => $this->getFirstNameFromInputOrEmail($email), 'Surname' => $this->getLastNameInput()]);
$member->write();
return $member;
}
return false;
}
示例13: requireDefaultRecords
function requireDefaultRecords()
{
$hasTestMembers = DataObject::get('Member')->find('Email', 'hayley@test.com');
if (!$hasTestMembers) {
foreach ($this->data() as $name) {
$member = new Member(array('FirstName' => $name, 'FirstName' => 'Smith', 'Email' => "{$name}@test.com"));
$member->write();
}
DB::alteration_message("Added default records to Member table", "created");
}
}
示例14: testCMSAccess
public function testCMSAccess()
{
$members = Member::get()->byIDs($this->allFixtureIDs('Member'));
foreach ($members as $member) {
$this->assertTrue(Permission::checkMember($member, 'CMS_ACCESS'));
}
$member = new Member();
$member->update(array('FirstName' => 'No CMS', 'Surname' => 'Access', 'Email' => 'no-access@example.com'));
$member->write();
$this->assertFalse(Permission::checkMember($member, 'CMS_ACCESS'));
}
示例15: testFindOrCreateMemberOverwriteExistingFields
public function testFindOrCreateMemberOverwriteExistingFields()
{
$member = new Member(array('Email' => 'existing@test.com', 'FirstName' => 'Existing', 'Surname' => 'Existing'));
$member->write();
$identity = OpauthIdentity::factory(array('auth' => array('provider' => 'Facebook', 'uid' => 999, 'info' => array('email' => 'existing@test.com', 'first_name' => 'New', 'last_name' => 'New'))));
$member = $identity->findOrCreateMember(array('overwriteExistingFields' => false));
$this->assertEquals('Existing', $member->FirstName, 'Does not overwrite unless requested');
$identity = OpauthIdentity::factory(array('auth' => array('provider' => 'Facebook', 'uid' => 999, 'info' => array('email' => 'existing@test.com', 'first_name' => 'New', 'last_name' => 'New'))));
$member = $identity->findOrCreateMember(array('overwriteExistingFields' => array('FirstName')));
$this->assertEquals('New', $member->FirstName, 'Overwrites existing fields if requested');
$this->assertEquals('Existing', $member->Surname, 'Does not overwrite fields if not present in whitelist');
}