public function postSendReport() { $error = ReportForm::onSendReport(true); if (!empty($error)) { return Response::json(response_message(400, $error), 400); } return Response::json(response_message(200)); }
public function getTest() { //if (!Auth::check()) //return null; $result = null; var_dump(Cache::get('messages_unread_count2')); die; return Response::json(response_message(200, $result)); }
public function postRead() { if (!Auth::check()) { return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'require_signin')), 500); } $data = post(); $valid['ids'] = isset($data['ids']) ? str_replace(',', '', $data['ids']) : ''; $rules = ['ids' => 'required|numeric']; $validation = Validator::make($valid, $rules); if ($validation->fails()) { return Response::json(response_message(400, $validation->messages()->first()), 400); } $user = Auth::getUser(); $ntfs = Notification::has_read($user, $data['ids']); return Response::json(response_message(200, $ntfs)); }
public function postSession() { $data = post(); $rules = ['password' => 'required|min:2']; $loginAttribute = UserSettings::get('login_attribute', UserSettings::LOGIN_EMAIL); if ($loginAttribute == UserSettings::LOGIN_USERNAME) { $rules['login'] = '******'; } else { $rules['login'] = '******'; } if (!in_array('login', $data)) { $data['login'] = post('username', post('email')); } $validation = Validator::make($data, $rules); if ($validation->fails()) { throw new ValidationException($validation); } /* * Authenticate user */ $user = Auth::authenticate(['login' => array_get($data, 'login'), 'password' => array_get($data, 'password')], true); return Response::json(response_message(200, $user)); }
public function putActiveAd($ad_id = 0) { try { $data = post(); $default = array('ad_id' => '', 'day' => ''); $merge = array_merge($default, $data); $merge = \DLNLab\Classified\Classes\HelperClassified::trim_value($merge); extract($merge); if (intval($ad_id) || intval($day)) { return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'not_valid')), 500); } // Get user_id $user = Auth::getUser(); $user_id = $user->id; // Check user money $user_money = Money::get_user_charge_money($user_id); $money = AdActive::calc_money($day); if ($user_money - $money < 0) { // No active ad when user not enough money return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'user_not_enough_money')), 500); } // Get Ad $ad = Ad::whereRaw('id = ? AND user_id = ? AND status != ?', array($id, $user_id, 0))->first(); if (empty($ad)) { return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'user_not_perm')), 500); } DB::beginTransaction(); try { // Minus money $o_money = Money::minus_money_user($user_id, $money); // Active ad $ad->status = 1; $ad->published_at = time(); $ad->save(); // Update add has activated to DB $now = \Carbon\Carbon::now(); $record = new self(); $record->ad_id = $ad_id; $record->money = $money; $record->start_date = $now->toDateTimeString(); $record->end_date = $now->addDays($day)->toDateTimeString(); $record->status = 1; $record->save(); $user->money_spent = $user->money_spent + $money; $user->save(); } catch (Exception $ex) { DB::rollback(); return $ex->getMessage(); } DB::commit(); return true; $message = AdActive::active_ad($data, null, $user_id); $message = $message ? $message : 'fail'; } catch (Exception $ex) { $code = 403; $message = $ex->getMessage(); } return Response::json(response_message($code, $message), $code); }
private static function valid($rules) { $response = null; $messages = array('between' => ':attribute phải nằm trong khoảng :min - :max số.', 'numeric' => ':attribute phải dùng dạng số', 'alpha_num' => ':attribute không được có ký tự đặc biệt', 'size' => ':attribute bị giới hạn :size ký tự'); $valid = Validator::make(Input::all(), $rules, $messages); if ($valid->fails()) { $response = response_message(1006, $valid->messages()->first()); } return $response; }