Skip to content

Member::currentUser()->Email problem #4

@ghost

Description

Hi!

In certain circumstances Member::CurrentUser() no returns an object, so Member::CurrentUser()->Email fails.
It is desirable to control this situation.
The correct code can be:
EmailVerifiedMember.php

    function onBeforeWrite() {
        if (!$this->owner->VerificationString) {
            $this->owner->VerificationString = MD5(rand());
        }
        if (!$this->owner->Verified) {
            if ((!$this->owner->VerificationEmailSent)) {
                $this->owner->sendemail($this->owner, false);
            }
            $uid = Member::currentUserID();  // <<<<
            $oemail = $this->owner->Email;  // <<<<
            $cuser = Member::currentUser();  // <<<<
            if ($uid && $cuser && ($oemail == $cuser->Email)) {  // <<<<
            //if (Member::currentUserID() && ($this->owner->Email == Member::currentUser()->Email)) {
                parent::onBeforeWrite();

                Security::logout(false);

                if (Director::redirected_to() == null) {
                    $messageSet = array(
                        'default' => _t('EmailVerifiedMember.EMAILVERIFY','Please verify your email address by clicking on the link in the email before logging in.'),
                    );
                }
                Session::set("Security.Message.type", 'bad');
                Security::permissionFailure($this->owner, $messageSet);
            } else return;
        }

        parent::onBeforeWrite();
    }

Regards,
Jose

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions