Call to undefined method App\Models\User::getAuthIdentifierName() - laravel-9

BadMethodCallException Call to undefined method
App\Models\User::getAuthIdentifierName()
I get this error after running the following command.
C:\Users\Sow Dream\Desktop\forex_shikhun>php artisan infyom:scaffold
User --fromTable --tableName=users
C:\Users\Sow
Dream\Desktop\forex_shikhun\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls
.php: 71
protected function forwardDecoratedCallTo($object, $method, $parameters)
{
$result = $this->forwardCallTo($object, $method, $parameters);
if ($result === $object) {
return $this;
}
return $result;
}
protected static function throwBadMethodCallException($method)
{
throw new BadMethodCallException(sprintf(
'Call to undefined method %s::%s()', static::class, $method
));
}

Related

signin page redirecting again to signin page in codeigniter

Controller
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Signin extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('cias');
$this->load->model('home_model');
$this->load->model('signin_model');
}
public function index(){
$this->is_signed_in();
}
function is_signed_in()
{
$is_signed_in = $this->session->userdata('is_signed_in');
if(!isset($is_signed_in) || $is_signed_in != TRUE)
{
// header
$data['logo'] = $this->home_model->get_logo_by_id();
// footer
$data['contact']=$this->home_model->get_contact();
$this->load->view('front/signin');
}
else
{
redirect('front/dashboard');
}
}
public function signinme()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|max_length[128]|trim');
$this->form_validation->set_rules('password', 'Password', 'required|max_length[32]');
if($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$email = strtolower($this->security->xss_clean($this->input->post('email')));
$password = $this->input->post('password');
$result = $this->signin_model->sign_in_me($email, $password);
if(!empty($result))
{
$session_array = array('user_id'=>$result->user_id,
'name'=>$result->name,
'email'=>$result->email,
'phone'=>$result->phone,
'is_signed_in' => TRUE );
$this->session->set_userdata('logged_in', $session_array);
redirect('./dashboard');
}
else
{
$this->session->set_flashdata('error', 'Email Address or password mismatch');
$this->index();
}
}
}
}
Model
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Signin_model extends CI_Model
{
// This function used to check the login credentials of the user
function sign_in_me($email, $password)
{
$this->db->select('*');
$this->db->from('user_login');
$this->db->where('email', $email);
$this->db->where('isdeleted', 0);
$query = $this->db->get();
$user = $query->row();
if(!empty($user)){
if(verifyHashedPassword($password, $user->password)){
return $user;
} else {
return array();
}
} else {
return array();
}
}
function get_user_info_id($user_id){
$this->db->select('*');
$this->db->from('user_login');
$this->db->where('user_id', $user_id);
$query = $this->db->get();
return $query->row();
}
}
Want to redirect
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/FrontController.php';
class Dashboard extends FrontController {
public function __construct(){
parent::__construct();
$this->load->helper('cias');
$this->load->model('home_model');
$this->load->model('signin_model');
$this->is_signed_in();
}
public function index(){
$this->load->view("front/dashboard", $data);
}
function signout() {
$this->session->sess_destroy ();
redirect ( 'signin' );
}
}

How to login using sql password() function in laravel?

I want to login using the sql password() function in laravel. This is because the master database of employee table contains password in the format insert into tbl_name(' ') values (' ', password('abc'));
So I need to use this master table for login so can anyone suggest me as to how can this be possible?
public function login(Request $request) {
// dd($request->all());
if(Auth::attempt([
'tgi' => $request->tgi,
'password' => $request->password
]))
{
// $user = \DB::where('tgi', $request->tgi)->first();
$user = MasterLogin::where('tgi', $request->tgi)->first();
if($user->is_admin() == '1') {
return redirect()->route('dashboard');
}
elseif($user->is_admin() == '0'){
return redirect()->route('home');
}
elseif($user->is_admin() == '3'){
return redirect()->route('manager');
}
}
return redirect()->back();
}
public function validateCredentials(UserContract $user, array $credentials)
{
$plain = $credentials['password'];
return $this->hasher->check($plain, $user->getAuthPassword());
}
In validateCredentials i would like to know how can I pass the password here.
As of now I tried this as said:
public function login(Request $request) {
// dd($request->all());
if(Auth::attempt([
'tgi' => $request->tgi,
'password' => sha1($request->password)
]))
{
$user = User::select("SELECT * FROM emp_username_db WHERE tgi = $request->tgi AND password = sha1('$request->password')");
if (Hash::check(sha1($request->password), $user['password'])) {
// The passwords match...
return redirect()->route('dashboard');
}
}
return redirect()->back();
}
My code that I am working on
class LoginController extends Controller
{
public function login(Request $request) {
//$user = User::where('tgi', $request->tgi)->first();
$result = User::where('tgi',$request->tgi)->where('password',\DB::raw('password("$request->password")'))->exists();
if ($result) {
if($result->is_admin() == '1'){
// Authentication passed...
return redirect()->intended('dashboard');
}elseif($result->admin == '0'){
return redirect()->route('home');
}
elseif($result->admin == '3'){
return redirect()->route('manager');
}
return redirect()->back();
}
}
As SQL default password is hashed using SHA1 so we can compare user's password by using laravel raw query like this.
$result = User::where('tgi',$request->tgi)->where('password',\DB::raw('password("$request->password")'))->exists();
if($result){
your code....
}
It's redirecting to dashboard but getting 302 found.

Laravel not inserting into table

Basically I need to have a e-mail verification system. For clarity, I will post only needed chunks of code that have impact whatsoever. When user registers, a random 40 string token is generated and sent to them, that code is appended to the route like this:
Route::get('/user/verify/{token}', 'RegisterController#verifyUser');
So when user clicks on that link supposedly route should call this:
RegisterController:
public function verifyUser($token){
$verifyUser = new VerifyUser();
$verifyUser->token = $token;
$verifyUser->getByToken();
$user = new User();
$user->id = $verifyUser->user_id;
$user->get();
if(isset($verifyUser)){
if(!$user->verified){
$user->updateVerifiedStatus();
$status = "Uspešno ste verifikovali e-mail adresu. Sada se možete ulogovati";
} else{
$status = "Već ste se verifikovali.";
}
} else{
return redirect('/')->with('error', "Vaš e-mail ne postoji");
}
return redirect('/')->with('status', $status);
}
verify_user is table which has an id of the user, and the token field, and if user is not registered, there will be no instance of that user in the table, therefore -> if(isset($verifyUser)),
also, user table has an 'verified' field, which is a boolean and stores true and false values, therefore -> if(!$user->verified).
And here are models which are used in the above mentioned controller
VerifyUser:
class VerifyUser
{
public $user_id;
public $token;
public $created_at;
public $updated_at;
public function getByToken()
{
$result =
DB::table('verify_users')
->select('*')
->where('token', $this->token)
->first();
return $result;
}
public function create()
{
$result =
DB::table('verify_users')
->insert([
'user_id' => $this->user_id,
'token' => $this->token,
]);
return $result;
}
}
User
class User
{
public function get()
{
$result =
DB::table('users')
->select('*')
->where('id', $this->id)
->first();
return $result;
}
public function updateVerifiedStatus()
{
$data = [
'verified' => true,
];
$result =
DB::table('users')
->where('id', $this->id)
->update($data);
return $result;
}
}
So, when I click the link, everything passess, I get the success status, which tells me that $user->updateVerifiedStatus() funct is returned succesfully. But, when I check the table, the field is still false, and is not updated. Any ideas?

phpunit: mock object not fooling php

I'm going through the zend tutorials and I am testing a class with a mock object with phpunit. When I pass a mock created from Zend\Db\TableGateway to my class, who's constructor expects a Zend\Db\TableGateway, I get an type error:
"...Argument 1 passed to Album\Model\AlbumTable::__construct() must be an instance of Zend\Db\TableGateway\TableGateway, instance of Mock_TableGateway_65b55cb0 given..."
Is this supposed happen? Are phpunit mock objects supposed to be able to "fool" the class?
Here is the real class:
class AlbumTable {
protected $tableGateway;
public function __construct(TableGateway $tableGateway) {
$this->tableGateway = $tableGateway;
}
public function fetchAll() {
$resultSet = $this->tableGateway->select();
return $resultSet;
}
public function getAlbum($id){
$id = (int) $id;
$rowset = $this->tableGateway->select(array('id' => $id));
$row = $rowset->current();
if(!$row) {
throw new \Exception("Couldn't find row: $id");
}
return $row;
}
public function saveAlbum(Album $album) {
$data = array(
'artist' => $album->artist,
'title' => $album->title,
);
$id = (int)$album->id;
if ($id == 0) {
$this->tableGateway->insert($data);
} else {
if ($this->getAlbum($id)) {
$this->tableGateway->update($data, array('id' => $id));
} else {
throw new \Exception('Form id does not exist');
}
}
}
public function deleteAlbum($id) {
$this->tableGateway->delete(array('id' => $id));
}
}
and the test:
class AlbumTableTest extends PHPUnit_Framework_TestCase {
public function testFetchAllReturnsAllAlbums() {
$resultSet = new ResultSet();
$mockTableGateway = $this->getMock('Zend\Db\TableGateway',
array('select'), array(), '', false);
$mockTableGateway->expects($this->once())
->method('select')
->with()
->will($this->returnValue($resultSet));
$albumTable = new AlbumTable($mockTableGateway);
$this->assertSame($resultSet, $albumTable->fechAll());
}
}
and the error:
Time: 102 ms, Memory: 5.00Mb
There was 1 error:
1) AlbumTest\Model\AlbumTableTest::testFetchAllReturnsAllAlbums
Argument 1 passed to Album\Model\AlbumTable::__construct() must be an instance of Zend\Db\TableGateway\TableGateway, instance of Mock_TableGateway_65b55cb0 given, called in C:\Users\MEEE\Google Drive\code\iis\www\CommunicationApp\module\Album\test\AlbumTest\Model\AlbumTableTest.php on line 20 and defined
C:\Users\MEEE\Google Drive\code\iis\www\CommunicationApp\module\Album\src\Album\Model\AlbumTable.php:9
C:\Users\MEEE\Google Drive\code\iis\www\CommunicationApp\module\Album\test\AlbumTest\Model\AlbumTableTest.php:20
FAILURES!
Tests: 4, Assertions: 9, Errors: 1.
You are not mocking the correct class. You are creating a mock of a Zend\Db\TableGateway and you need to actually mock Zend\Db\TableGateway\TableGateway
Change you test code to:
$mockTableGateway = $this->getMock('Zend\Db\TableGateway\TableGateway',
array('select'), array(), '', false);
Your mock was failing a type-hint because your not mocking the correct class.
Mock objects will extend the class that you are mocking, so they will be an instance of the class being mocked.

yii if condition within query builder

class Retailjob extends CFormModel {
public function getReatilProducts() {
$condition=false;
$user = Yii::app()->db->createCommand()
->select('tbl_retailjob.retailjobmaster_id, tbl_retailjob.joborderflag, tbl_retailjoborder.retailjob_id, tbl_retailjoborder.retailjobsub_id, tbl_retailjoborder.filename,tbl_retailpostpressjoborder.retailpostpressjo_id,tbl_retailpostpressjoborder.retailjobsub_id,tbl_retailpostpressjoborder.retailpostpresssub_id')
->from('tbl_retailjob')
->join('tbl_retailjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailjoborder.retailjobmaster_id')
->join('tbl_retailpostpressjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailpostpressjoborder.retailjobmaster_id')
->where('tbl_retailjob.retailjobmaster_id=:id', array(':id' => 7))
->queryAll();
return $user;
}
}
this is my model file
what i want to achieve is if $condition is truethen the where condition should be avoide and if it is false it should be included
can i achieve it like this
public function getReatilProducts() {
$condition=true;
$user = Yii::app()->db->createCommand()
->select('tbl_retailjob.retailjobmaster_id, tbl_retailjob.joborderflag, tbl_retailjoborder.retailjob_id, tbl_retailjoborder.retailjobsub_id, tbl_retailjoborder.filename,tbl_retailpostpressjoborder.retailpostpressjo_id,tbl_retailpostpressjoborder.retailjobsub_id,tbl_retailpostpressjoborder.retailpostpresssub_id')
->from('tbl_retailjob')
->join('tbl_retailjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailjoborder.retailjobmaster_id')
->join('tbl_retailpostpressjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailpostpressjoborder.retailjobmaster_id')
if ($condition !=true) {
->where('tbl_retailjob.retailjobmaster_id=:id', array(':id' => 7))
}
->queryAll();
return $user;
}
}
Try this:
public function getReatilProducts() {
$condition=true;
$command = Yii::app()->db->createCommand()
->select('tbl_retailjob.retailjobmaster_id, tbl_retailjob.joborderflag, tbl_retailjoborder.retailjob_id, tbl_retailjoborder.retailjobsub_id, tbl_retailjoborder.filename,tbl_retailpostpressjoborder.retailpostpressjo_id,tbl_retailpostpressjoborder.retailjobsub_id,tbl_retailpostpressjoborder.retailpostpresssub_id')
->from('tbl_retailjob')
->join('tbl_retailjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailjoborder.retailjobmaster_id')
->join('tbl_retailpostpressjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailpostpressjoborder.retailjobmaster_id');
if ($condition !=true) {
$command->where('tbl_retailjob.retailjobmaster_id=:id', array(':id' => 7));
}
$user = $command->queryAll();
return $user;
}