kernel update

This commit is contained in:
2024-12-16 14:26:13 +03:00
parent 589cf81e49
commit f5ad07c04a
77 changed files with 2067 additions and 251 deletions

View File

@ -3,6 +3,7 @@
namespace kernel\modules\user\service;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\modules\user\models\User;
class UserService
@ -25,7 +26,9 @@ class UserService
{
$user->username = $form_model->getItem('username');
$user->email = $form_model->getItem('email');
$user->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
if ($form_model->getItem('password')) {
$user->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
}
if ($user->save()){
return $user;
}
@ -38,7 +41,7 @@ class UserService
* @param string $value
* @return mixed
*/
public function getByField(string $field, string $value)
public static function getByField(string $field, string $value): mixed
{
return User::where($field, $value)->first();
}
@ -82,4 +85,13 @@ class UserService
return $this->getByField("access_token", $token);
}
public static function createUserByEmailAndPassword(string $email, string $password): void
{
$user = new User();
$user->email = $email;
$user->username = $email;
$user->password_hash = password_hash($password, PASSWORD_DEFAULT);
$user->save();
}
}