/** * @param string $uid to checking condition when authentication again * @param object $user here is oauth * @param object $toekn here it is token get by oauth * @param object $object here is it is find in database * @param string $nameOauth there are google, github, facebook... * * @return mixed */ public function commonOauthSave($uid, $user, $token, $object, $nameOauth) { if (!$object) { $object = new Users(); //setTokenGithub or setTokenGoogle $tokenName = 'setToken' . $nameOauth; $object->{$tokenName}($token->accessToken); $object->setTokenType(Users::TOKEN_TYPE); $object->setUid($uid); $object->setEmail($user->email); $object->setFirstname($user->firstName); //@ Todo later, it perfect if we do haven't delete in database $username = '******' . (Users::count() + 1); $object->setUsername($username); if (empty($user->email)) { $object->setEmail($username . '*****@*****.**'); } $object->setStatus(Users::STATUS_ACTIVE); $object->increaseKarma(Karma::LOGIN); } //Update session id session_regenerate_id(true); if (!$object->save()) { $this->displayModelErrors($object); return $this->indexRedirect(); } //Store the user data in session $this->auth->setSession($object); //Store the user data in cookies $this->auth->setRememberEnviroment($object); //Dispaly notification when user login $this->notification($object); return $this->currentRedirect(); }