Auth::attempt() does not return anything - authentication

I'm using laravel 4.
This is my Seeder
User::create(array(
'name' => 'Rubber Gajulu',
'username' => 'awesome',
'email' => 'awesome#awe.com',
'password' => Hash::make('awesome'),
));
And this is where I am testing the Auth::attempt() function
Route::get('testlogin',function(){
$userdata = ['email'=> 'awesome#awe.com','password'=> 'awesome'];
echo Auth::attempt($userdata);
if (Auth::attempt($userdata))
echo 'SUCCESS!';
else
echo 'FAILURE!';
});
It just returns FAILURE. The first echo does not return anything.

Your controller code is wrong. It should be this:
Route::get('testlogin',function(){
$userdata = ['email'=> 'awesome#awe.com','password'=> 'awesome'];
if (Auth::attempt($userdata))
echo 'SUCCESS!';
else
echo 'FAILURE!';
});
Otherwise in your current code you are trying to login the user twice, so the second one fails.

Check if logs/laravel.log shows any error on hitting this url.
Share that.

Okay I found my mistake
Thanks to Isabell Knauers answer
My model had
$table->string('password',32)
Data was being truncated to 32 characters. Now I changed it to
$table->string('password',100)
and everything works as intended

Related

phpbb 3.2.x user_add including custom Profile field

This has been driving me nuts for 2 days and I can't find an answer anywhere on Google so would really appreciate a little help..
I have a custom registration form on my website, which sends the data to a fairly standard PHPBB3 user_add process as follows:
$user_row = array(
'username' => request_var('createUsername',''),
'user_password' => phpbb_hash(request_var('createPassword','')),
'user_email' => request_var('createEmail',''),
'group_id' => '2',
'user_timezone' => '1.00',
// 'user_dst' => '0',
'user_lang' => 'en',
'user_type' => $user_type,
'user_actkey' => $user_actkey,
'user_ip' => $user->ip,
'user_regdate' => time(),
'user_inactive_reason' => $user_inactive_reason,
'user_inactive_time' => $user_inactive_time,
);
// Register user...
$user_id = user_add($user_row, $cp_data);
// If creating the user failed, display an error
if ($user_id === false)
{
trigger_error('NO_USER', E_USER_ERROR);
}
That works fine and I'm happy with it, however, I have created a custom profile field in the Admin Control Panel called 'ea_real_name' which I want to hold the user's real name. This corresponds to a field on the registration form called 'createRealName' (sent through as $_POST['createRealName'])
I know that user_add takes an optional field called 'cp_data', but I can't for the life of me work out how to format this data... Should it be an array (something like 'ea_real_name' => request_var('createRealName','') or something else?
PHPBB's wiki for the field is empty (https://wiki.phpbb.com/Custom_profile::submit_cp_field) so not much help...
Thanks! :-)
I was right in my assumption! It's an array with the field name prefixed by pf_.
Finally found an answer here: https://www.phpbb.com/community/viewtopic.php?f=71&t=1638905
$cp_data = array(
'pf_ea_real_name' => request_var('createRealName','')
);
Is the correct way to do it...

laravel 5.1 auth login returns an error

I'm trying to use auth()->login() in laravel 5.1 but it returns an error. Please see my code below:
$user = User::where('username', $username)->where('activation_code', $activation_code);
$not_activated_user = $user->where('status', 0)->where('confirmed', 0);
if($not_activated_user->count() == 1){
$not_activated_user->update([
'status' => 1,
'confirmed' => 1
]);
auth()->login($user->where('status', 1)->where('confirmed', 1));
}
I've also import use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; and implements AuthenticatableContract in my User model, but it still returns the same error. Why is that? I also tried to use ->get() in ->login(....->get()) to get the current user, but still same error.
Error:
Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, instance of Illuminate\Database\Eloquent\Builder given
Try
$user = User::where('username', $username)->where('activation_code', $activation_code)->firstOrFail();
$user->update([
'status' => 1,
'confirmed' => 1
]);
auth()->login($user);
}
It's working now, I just called the User model again to select the current user :)

Bigcommerce API getOrders() returns empty array

There is already a question posted on this topic, but no answer that works for me.
Bigcommerce PHP API - No data returned
I can connect to the online store from my PHP code, but GetOrders() returns an empty array
A json_encode gives me [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]
getOrdersCount() returns 47317, so I know there are orders in there.
Any ideas?
Thanks. Here's my code:
<?php
require '...../bigcommerce.php';
use Bigcommerce\Api\Client as Bigcommerce;
Bigcommerce::configure(array(
'store_url' => 'https://store-xxxx.mybigcommerce.com',
'username' => 'xxxxx',
'api_key' => 'xxxxx'
));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);
$count = Bigcommerce::getOrdersCount();
echo 'number of orders:' . $count;
$orders = Bigcommerce::getOrders();
foreach($orders as $order) {
echo $order->name;
echo $order->price;
}
?>
Your problem is that "name" and "price" are not fields that belong to orders. That is why it is returning that data. For each order it is echoing empty (non existent) fields,
Instead try:
$orders = Bigcommerce::getOrders();
foreach($orders as $order) {
echo $order->id;
echo $order->total_inc_tax;
}

cakephp see the compiled SQL Query before execution

My query gets the timeout error on each run. Its a pagination with joins.
I want to debug the SQL, but since I get a timeout, I can't see it.
How can I see the compiled SQL Query before execution?
Some cake code:
$this -> paginate = array(
'limit' => '16',
'joins' => array( array(
'table' => 'products',
'alias' => 'Product',
'type' => 'LEFT',
'conditions' => array('ProductModel.id = Product.product_model_id')
)),
'fields' => array(
'COUNT(Product.product_model_id) as Counter',
'ProductModel.name'
),
'conditions' => array(
'ProductModel.category_id' => $category_id,
),
'group' => array('ProductModel.id')
);
First off, set the debug variable to 2 in app/config/config.php.
Then add:
<?php echo $this->element('sql_dump');?>
at the end of your layout. This should actually be commented out in your default cake layout.
You will now be able see all SQL queries that go to the database.
Now copy the query and use the SQL EXPLAIN command (link is for MySQL) over the database to see what the query does in the DBMS. For more on CakePHP debugging check here.
Since your script doesn't even render you can try to get the latest log directly from the datasource with:
function getLastQuery()
{
$dbo = $this->getDatasource();
$logs = $dbo->getLog();
$lastLog = end($logs['log']);
return $lastLog['query'];
}
This needs to be in a model since the getDatasource() function is defined in a model.
Inspect the whole $logs variable and see what's in there.
One more thing you can do is ....
Go to Cake/Model/DataSource/DboSource.php and locate function execute() and print $sql variable.
That should print the sql.
This certainly is not be the cleanest way (as you are changing Cake directory) .. but certainly would be quickest just to debug if something is not working with sql.
Try...
function getLastQuery($model) {
$dbo = $model->getDatasource();
$logData = $dbo->getLog();
$getLog = end($logData['log']);
echo $getLog['query'];
}
Simple way to show all executed query of your given model:
$sqllog = $this->ModelName->getDataSource()->getLog(false, false);
debug($sqllog);
class YourController extends AppController {
function testfunc(){
$this->Model->find('all', $options);
echo 'SQL: '.$this->getLastQuery();
}
function getLastQuery()
{
$dbo = ConnectionManager::getDataSource('default');
$logs = $dbo->getLog();
$lastLog = end($logs['log']);
return $lastLog['query'];
}
}
or you can get all the query by adding following line in to the function execute() in lib/Cake/Model/DataSource.php
Debugger::dump($sql);
set the debug variable to 2 in app/config/config.php.
echo $this->Payment->save();
Out put like =>SQL Query: INSERT INTO photoora_photoorange.payments VALUES (*******)
[insert query][2]
set the debug variable to 2 in app/config/config.php.
And

pdo connection error

<?php
$config['db'] = array (
'host' => 'localhost'
'username' => 'root'
'password' => ''
'dbname' => 'phplogin'
);
$db = new PDO("mysql:host={$config['db']['host']};dbname={$config['db']['dbname']}",
$config['db']['username'], $config['db']['password']);
?>
receives error: "Parse error: syntax error, unexpected ''username'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in C:\webroot\wamp\www\index.php on line 4"
My question is:
Can you highlight or comment on the lines I have to insert my information such as localhost, databasename, table, root, "", etc. Also if you see any changes that need to be made.
When you get errors, you can find the mistake by looking in the error message
The T_CONSTANT_ENCAPSED_STRING parser token error occurs due to an unexpected quote, so all you had to do is look at your code to notice that you don't have commas in the array declaration as stated by Johnny000. You always have to look the error messages and interpret their meaning. That's coding 101 in my opinion.
The error is because you forget to seperate the arrayvalues with ,
Here the right code
<?php
$config['db'] = array (
'host' => 'YOURHOST',
'username' => 'YOURUSERNAME',
'password' => 'YOURPASSWORD',
'dbname' => 'YOURTABLE'
);
$db = new PDO("mysql:host={$config['db']['host']};dbname={$config['db']['dbname']}",
$config['db']['username'], $config['db']['password']);
?>