This commit is contained in:
antv
2026-07-02 17:02:02 +07:00
parent 89790539b7
commit f594a45e84
17 changed files with 200 additions and 122 deletions
@@ -42,13 +42,15 @@ class AdminController extends Controller
public function store(Request $request)
{
$request->validate([
'msnv' => 'required|unique:user,msnv',
'mail' => 'required|email|unique:user,mail',
'password' => 'required|min:6',
'role' => 'required|in:' . User::ROLE_MEMBER . ',' . User::ROLE_ADMIN,
'msnv' => 'required|integer|unique:user,msnv',
'name' => 'required|string|max:255',
'mail' => 'required|email|unique:user,mail',
'departments' => 'required|integer|min:1|max:5',
'password' => 'required|string',
'role' => 'required|in:' . User::ROLE_MEMBER . ',' . User::ROLE_ADMIN,
]);
$this->adminService->createUser($request->only('msnv', 'mail', 'password', 'role'));
$this->adminService->createUser($request->only('msnv', 'name', 'mail', 'departments', 'password', 'role'));
return redirect()->route('admin.users.index')->with('success', __('messages.user_create_success'));
}
+4 -1
View File
@@ -34,7 +34,10 @@ class UserController extends Controller
public function storeThankcards(Request $request)
{
$request->validate([
'receiver' => 'required|exists:user,msnv',
'receiver' => [
'required',
\Illuminate\Validation\Rule::exists('user', 'msnv')->where('status', \App\Models\User::STATUS_ACTIVE)
],
'amount' => 'required|integer|min:1|max:' . Administration::MAX_SEND_CARD_PER_MONTH,
]);
+1 -2
View File
@@ -11,8 +11,7 @@ class AddCard extends Model
protected $table = 'add_card';
public $timestamps = false;
protected $primaryKey = null;
public $incrementing = false;
protected $primaryKey = 'id';
protected $fillable = [
'buyer',
+4 -3
View File
@@ -25,14 +25,15 @@ class User extends Authenticatable
protected $table = 'user';
public $timestamps = false;
protected $primaryKey = 'msnv';
public $incrementing = false;
protected $keyType = 'string';
protected $primaryKey = 'id';
protected $fillable = [
'msnv',
'name',
'mail',
'pass',
'departments',
'avatar',
'role',
'status',
'card',
+4 -2
View File
@@ -66,8 +66,10 @@ class AdminService implements AdminServiceInterface
{
User::create([
'msnv' => $data['msnv'],
'name' => $data['name'],
'mail' => $data['mail'],
'pass' => Hash::make($data['password']),
'departments' => $data['departments'],
'role' => $data['role'],
'status' => User::STATUS_ACTIVE,
'card' => 0,
@@ -83,9 +85,9 @@ class AdminService implements AdminServiceInterface
DB::transaction(function () use ($data, $user) {
if (!empty($data['num_card'])) {
AddCard::create([
'buyer' => abs(crc32($user->msnv)) % 1000000,
'buyer' => $user->msnv,
'num_card' => $data['num_card'],
'seller' => abs(crc32(Auth::user()->msnv)) % 1000000,
'seller' => Auth::user()->msnv,
'date' => Carbon::today(),
]);
$user->card += $data['num_card'];
+5 -4
View File
@@ -11,14 +11,15 @@ class AuthService implements AuthServiceInterface
{
public function attemptLogin(array $credentials, Request $request): array
{
if (!Auth::attempt(['mail' => $credentials['mail'], 'password' => $credentials['password']])) {
// Manual MD5 password check
$user = User::where('mail', $credentials['mail'])->first();
if (!$user || $user->pass !== md5($credentials['password'])) {
return ['success' => false, 'error_key' => 'mail', 'error_msg' => __('auth.failed')];
}
// Log the user in manually
Auth::login($user);
$request->session()->regenerate();
$user = Auth::user();
if ($user->status != User::STATUS_ACTIVE) {
Auth::logout();
return ['success' => false, 'error_key' => 'mail', 'error_msg' => __('auth.inactive')];
+5
View File
@@ -38,6 +38,11 @@ class UserService implements UserServiceInterface
throw new \RuntimeException(__('messages.error.no_send_permission'));
}
$receiver = User::where('msnv', $receiverMsnv)->first();
if (!$receiver || $receiver->status != User::STATUS_ACTIVE) {
throw new \RuntimeException(__('messages.error.receiver_invalid'));
}
$startOfMonth = Carbon::now()->startOfMonth();
$endOfMonth = Carbon::now()->endOfMonth();