Welcome Guest, Not a member yet? Register   Sign In
Stuck on string/object error
#1

Hi,

After a few years of being away from programming im building an application right now in CI4. Haven't programmed for years and always worked with CI2/3. So let's shake things up again haha. I think this code could also be a lot shorter and some renaming. But whatever, im stuck on an 'Object of class stdClass could not be converted to string' error... (SYSTEMPATH/Database/Query.php at line 333)

AuthController.php

PHP Code:
    public function sendPasswordResetLink() {
        $isValid $this->validate(
                [
                    'email' =>
                    [
                        'rules' => 'required|valid_email',
                        'errors' =>
                        [
                            'required' => 'Voer hier jouw e-mailadres in.',
                            'valid_email' => 'Voer een geldig e-mailadres in.'
                        ]
                    ]
                ]
        );

        if (!$isValid) {
            return view('backend/pages/auth/forgot', [
                'pageTitle' => 'Wachtwoord vergeten',
                'validation' => $this->validator
            
]);
        } else {
            $user = new User();
            $userInfo $user->asObject()->where('email'$this->request->getVar('email'))->first();

            $token bin2hex(openssl_random_pseudo_bytes(65));

            $resetToken = new PasswordResetToken();
            $isOldTokenExists $resetToken->asObject()->where('email'$userInfo->email)->first();

            if ($isOldTokenExists) {
                $resetToken->where('email'$userInfo->email)->set(['token' => $token'created_at' => Time::now()])->update();
            } else {
                $resetToken->insert(['email' => $userInfo'token' => $token'created_at' => Time::now()]);
            }

            $actionLink route_to('admin.reset-password'$token);

            $mailData = array(
                'actionLink' => $actionLink,
                'user' => $userInfo
            
);

            $view = \Config\Services::renderer();

            $mailBody $view->setVar('mail_data'$mailData)->render('email-templates/forgot-email-template');

            $mailConfig = array(
                'mail_from_email' => env('EMAIL_FROM_ADDRESS'),
                'mail_from_name' => env('EMAIL_FROM_NAME'),
                'maiL_recipient_name' => $userInfo->first_name ' ' $userInfo->last_name,
                'mail_subject' => 'Wachtwoord vergeten',
                'email_body' => $mailBody
            
);

            if (sendEmail($mailConfig)) {
                return redirect()->route('admin.forgot.form')->with('success''We hebben je een e-mail gestuurd met daarin een link. Via deze link kun je een nieuw wachtwoord opgeven.');
            } else {
                return redirect()->route('admin.forgot.form')->with('fail''ERROR');
            }
        }
    


PasswordResetToken.php

PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
PasswordResetToken extends Model {
    protected $DBGroup          'default';
    protected $table            'password_reset_tokens';
    protected $allowedFields    = ['email''token''created_at'];

Thanks in advance!
Harm.
<?php echo "Programming and perfectionism sucks sometimes..."; ?>
Reply
#2

Whats on line 33 ?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 12-24-2023, 09:25 AM by HarmW94.)

(12-23-2023, 09:07 PM)InsiteFX Wrote: Whats on line 33 ?

Hi,

Thanks for your reply.

You mean line 333 in Query.php from the CI system? I don't think the problem is there.
<?php echo "Programming and perfectionism sucks sometimes..."; ?>
Reply
#4

$resetToken->insert(['email' => $userInfo, 'token' => $token, 'created_at' => Time::now()]);
Reply
#5

(12-24-2023, 05:55 AM)kenjis Wrote: $resetToken->insert(['email' => $userInfo, 'token' => $token, 'created_at' => Time::now()]);

Thanks for your answer, kenjis. But that's the exact code/line I already have?
<?php echo "Programming and perfectionism sucks sometimes..."; ?>
Reply
#6

Isn't that line the cause of the error "Object of class stdClass could not be converted to string"?
Reply
#7

You can try one of these fixes that may work for you.

Fix error “Object of class stdclass could not be converted to string”
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB