Cakephp 3 Auth Component $this->Auth->password() not working - cakephp-3.0

i want to update my password with users table and in cakephp 2.0 i am using like that --
$haspass = $this->Auth->password($pass);
working fine but in cakephp3 it`s not working..

finally i have found the solution --
In Controller -- Use Like That
use Cake\Auth\DefaultPasswordHasher;
use Cake\ORM\Entity;
$password = $_POST['new_pswd'];
$hashPswdObj = new DefaultPasswordHasher;
$hashpswd = $hashPswdObj->hash($password); // it will hash the password

Related

Data is not updating in mysql through laravel

I have made a table of users and during the time of registration, i am inserting the necessary data like email password and name and marked others columns null. Everything was working fine until i tried to update the null columns as per requirement. I have tried many methods to update the data but it always says 200 OK in postman but not update the Mysql table.Here is my code
$data = $request->validate([
'dob' => 'required',
'gender'=>'required|in:male,female',
'image'=>'required|mimes:jpg,png,jped|max:5048'
]);
$newImage = time().'-'.$request->name.'.'.$request->image->extension();
$request->image->move(public_path('images'), $newImage);
$user = User::find($id);
$user->update($request->all());
return response($user);
And this my output the name id and email field were added on the time of registeration what i am trying to add is 'dob','gender' and ''profile picture
After trying the method provided i got this
The answer to this question was don't use 'PUT' request to update the data. Some times it works well and some times it will not work. Just use post method just like to create data. It solved my problem.
$user = User::find($id);
$user ->dob = $request->dob;
$user ->gender = $request->gender;
$user ->image= $newImage;
$user ->save();
try this will 100% update your users details .
I hope you got your solution .

Create a record into many2many table using Web service API in odoo 8

I need to create a record in mail_vote table(many2many) with fields message_id and user_id Using Web service API. I found a document here: https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.write . But i don't know how to use that in my code. Any solution please.
Below i am posting the code snippet for associating (6,0,[ids])] the Many2many record in product.attribute.line.
In Php here i have used ripcord for this task.
$existing_prodid = 59;
$existing_attribute_id = 2;
$existing_value_id = 4;
$product_attribute_line = $models->execute($db, $uid, $password,
'product.attribute.line','create',
array('product_tmpl_id' => $existing_prodid;,
'attribute_id'=>$existing_attribute_id,
'value_ids'=>array(array(6,0,array($existing_value_id)))
))
Here the product.attribute.line have have Many2many relation with product.attribute.value
So this is how i associated a records for value_ids ['value_ids'=>array(array(6,0,array($existing_value_id)))].
In python i have used xmlrpclib for this task.
attibute_line = models.execute_kw(dbname, uid, password,
'product.attribute.line', 'create',
[{'product_tmpl_id':59,'attribute_id':2,'value_ids':[(6,0,[4])]}] )
I hope this may help in your case

Yii2 - Connect to database inside Controller Action

Greetings,
Facts:
Database named -> acastro
Table called -> contacto
Fields in table are -> id, nome, email
I making an Yii2 application, and need to connect a highcharts chart to a table field in my database.
How can i inside an action called actionAdmin connect to my database and then count the number of id's in my Contacto table stored inside acastro database.
In the old Yii1.xx i used to establish connection this way:
public function actionAdmin() {
$sql = Yii::app()->db->createCommand('
SELECT count(*) as total
FROM contacto
')->queryAll();
$total = array();
for ($i = 0; $i < sizeof($sql); $i++){
$total[] = (int) $sql[$i]["total"];
}
$this->render('admin', array('total' => $total));
}
}
The problem is that this syntax no longer works in Yii2, and i've tried the sintaxe explained in Yii2 api guide but it always give's me error of undefined variable. Here is the code that i'm using to connect acording to Yii2 api guide:
use yii\db\Command;
$total = $connection->createCommand('SELECT count (*) FROM contacto')->queryAll();
What am i doing wrong ? Any solutions ?
Many thanks in advance.
I am not very sure that it will solve ur problem.
But in yii2 this the syntax
use app\models\Contacto; //look your Contacto Model namespace
$query = (new Query())->from('contacto');
$count = $query->count('column_name');
I hope this will help
The easiest syntax in Yii2 is:
$count=(new \yii\db\Query)->from('TBL_NAME')->count('*');
It just returns the count. For example: 500

how can i use hibernate to loging in a jsp page

im using hibernate with my jsp page and mySQL , i know just how to save a session like that :
<%Session hibernateSession = MyDB.HibernateUtil.currentSession(); Transaction tx = hibernateSession.beginTransaction();
Student std = new Student();
std.setUserName("David");
hibernateSession.save(std);%>
, but how can i selecte from a table and print it like in mysql select * from student wher userName = *** and how can i update ?
finaly can i use hibernate in Login ?
Refer this for complete HQL help: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html

Inserting data using Linq

I have a linq query to insert data in table. but its not working. I saw some example on internet tried to do like that but doesn't seems to work.
Tablename: login has 3 columns userid, username and password. I set userid as autoincrementing in database. So I have to insert only username and password everytime.Here's my code.
linq_testDataContext db = new linq_testDataContext();
login insert = new login();
insert.username = userNameString;
insert.Password = pwdString;
db.logins.Attach(insert);// tried to use Add but my intellisence is not showing me Add.I saw attach but dosent seems to work.
db.SubmitChanges();
have a look on http://www.codeproject.com/KB/linq/LINQToSQLBaseCRUDClass.aspx
linq_testDataContext db = new linq_testDataContext();
login insert = new login();
insert.username = userNameString;
insert.Password = pwdString;
db.logins. InsertOnSubmit(insert);
db.SubmitChanges();
If you Attach - It should attach to the particular object Context .But it wont reflect in database .If you want to insert any values try with InsertOnSubmit(object) and do
SubmitChanges() to save it in database
Attach() is the wrong method, you need to call InsertOnSubmit() to let Linq-To-Sql generate an insert statement for you. Attach() is for distributed scenarios, where your entity has not been retrieved via the same data-context that is used for submitting changes.
linq_testDataContext db = new linq_testDataContext();
login insert = new login();
insert.username = userNameString;
insert.Password = pwdString;
db.logins.InsertOnSubmit(insert);// tried to use Add but my intellisence is not showing me Add.I saw attach but dosent seems to work.
db.SubmitChanges();
Method to save employee details into Database.
Insert, Update & Delete in LINQ C#
Employee objEmp = new Employee();
// fields to be insert
objEmp.EmployeeName = "John";
objEmp.EmployeeAge = 21;
objEmp.EmployeeDesc = "Designer";
objEmp.EmployeeAddress = "Northampton";
objDataContext.Employees.InsertOnSubmit(objEmp);
// executes the commands to implement the changes to the database
objDataContext.SubmitChanges();