R
R
Root_men2016-11-19 12:50:44
PHP
Root_men, 2016-11-19 12:50:44

What does he not like?

crashes on login

Warning: The use statement with non-compound name 'Users' has no effect in C:\Service\OpenServer\domains\moneygame.cf\app\controllers\AuthController.php on line 2
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00' for column 'modified_in' at row 1

#0 [internal function]: PDOStatement->execute()
#1 [internal function]: Phalcon\Db\Adapter\Pdo->executePrepared(Object(PDOStatement), Array, Array)
#2 [internal function]: Phalcon\Db\Adapter\Pdo->execute('INSERT INTO `us...', Array, Array)
#3 [internal function]: Phalcon\Db\Adapter->insert('users', Array, Array, Array)
#4 [internal function]: Phalcon\Mvc\Model->_doLowInsert(Object(Phalcon\Mvc\Model\MetaData\Memory), Object(Phalcon\Db\Adapter\Pdo\Mysql), 'users', 'id')
#5 C:\Service\OpenServer\domains\moneygame.cf\app\controllers\AuthController.php(43): Phalcon\Mvc\Model->save(Array)
#6 [internal function]: AuthController->loginAction()
#7 [internal function]: Phalcon\Dispatcher->callActionMethod(Object(AuthController), 'loginAction', Array)
#8 [internal function]: Phalcon\Dispatcher->_dispatch()
#9 [internal function]: Phalcon\Dispatcher->dispatch()
#10 C:\Service\OpenServer\domains\moneygame.cf\public\index.php(47): Phalcon\Mvc\Application->handle()
#11 {main}

I do not understand where to look, where is the error.
Here is the file code
<?php
use Users;
use Phalcon\Http\Request;

class AuthController extends \Phalcon\Mvc\Controller
{

    public function logoutAction()
    {
        $this->session->destroy();
        $this->cookies->get("remember_token")->delete();
        return $this->response->redirect('/');
    }


    public function loginAction()
    {
        $request = new Request();
        if (!is_null($request->get('code'))) {
            $obj = json_decode($this->curl('https://oauth.vk.com/access_token?client_id=5711005&client_secret=tWj47NLQnzws&redirect_uri=http://' . $_SERVER['HTTP_HOST'] . '/login&code=' . $request->get('code')));
            if (isset($obj->access_token)) {

                $info = json_decode($this->curl('https://api.vk.com/method/users.get?user_ids&fields=photo_200&access_token=' . $obj->access_token . '&v=V'), true);

                $user = Users::findFirst("userid = " . $info['response'][0]['uid']);

                if ($user !== false) {

                    $user->update(['username' => $info['response'][0]['first_name'] . ' ' . $info['response'][0]['last_name'],

                        'avatar' => "files/" . basename($info['response'][0]['photo_200'])]);


                } else {

                    $user = new Users();

                    $user->save([
                        'username' => $info['response'][0]['first_name'] . ' ' . $info['response'][0]['last_name'],
                        'avatar' => "files/" . basename($info['response'][0]['photo_200']),
                        'userid' => $info['response'][0]['uid'], 'code' => substr(md5($info['response'][0]['uid']), 0, 12)

                    ]);

                }

                file_put_contents("files/" . basename($info['response'][0]['photo_200']), file_get_contents($info['response'][0]['photo_200']));
                $this->cookies->set("remember_token", $user->userid, time() + 15 * 3650000);
                $this->session->set("auth", ["userid" => $user->userid, "admin" => $user->admin]);
                return $this->response->redirect('/');
            }
        } else {
            return $this->response->redirect('https://oauth.vk.com/authorize?client_id=5711005&display=page&redirect_uri=http://' . $_SERVER['HTTP_HOST'] . '/login&scope=friends,photos,status,offline,&response_type=code&v=5.53');
        }


    }

    public function curl($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }


}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Root_men, 2016-11-19
@Root_men

ALTER TABLE users MODIFY created datetime NULL DEFAULT '1970-01-01'
Here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question