public function postApproveDream(Request $req) { $dream = $req->input('dream'); $status = $req->input('approve'); $model = Dream::find($dream); $model->approved = $status ? 1 : 0; $model->approved_at = $status ? \Carbon\Carbon::now() : null; $model->save(); return response()->json(['status' => 'OK', 'data' => $model->approved_at, 'message' => 'Vis actualizat.']); }
public function postVoteDream(Request $req) { $dream = $req->input('dream'); if (Vote::where('id_dream', $dream)->where('cookie', $this->userService->cookie())->count() > 0) { return response()->json(['status' => 'ERROR', 'data' => '', 'messages' => 'Ati votat deja.']); } $vote = new Vote(); $vote->id_dream = $dream; $vote->cookie = $this->userService->cookie(); $vote->save(); $dream = Dream::find($dream); $dream->votes += 1; $dream->save(); return response()->json(['status' => 'OK', 'data' => $dream->votes, 'messages' => 'Proiect votat.']); }
public function postCode(Request $request) { $validationMessages = ['name.required' => 'Numele este obligatoriu.', 'name.max' => 'Numele trebuie sa aiba sub 255 de caractere.', 'email.required' => 'Email-ul este obligatoriu.', 'phone.required' => 'Telefonul este obligatoriu.', 'phone.regex' => 'Telefonul continue caractere care nu sunt cifre.', 'phone.size' => 'Telefonul nu are numarul corespunzator de cifre.', 'code.unique' => 'Codul a fost deja folosit.', 'dream.max' => 'Visul trebuie sa aiba maxim 500 de caractere.']; $validator = \Validator::make($request->all(), ['name' => 'required|max:255', 'email' => 'required', 'phone' => 'required|string|size:10|regex:/[0-9]/', 'code' => 'unique:codes', 'dream' => 'max:500'], $validationMessages); $validCode = false; $validDream = false; if ($validator->passes()) { $user_cookie = $this->userService->cookie(); if ($this->userService->user() == null || $this->userService->user()->email != $request->email) { $new_user = new User(); $new_user->name = $request->input("name"); $new_user->phone = $request->input("phone"); $new_user->email = $request->input("email"); $new_user->cookie = $this->userService->getCookie(); $new_user->save(); } if ($request->input('code') != null) { $api_response = $this->codeService->checkCode($request->input('code'), $request->input('phone'), $request->has('dream') ? 1 : 0); // $api_response = "CORRECT"; $status = true; switch ($api_response) { case "INVALIDPARAMS": $status = false; $messages = "INVALID PARAMS"; break; case "TIMEOUT": $status = false; $messages = "Serviciu este momentan indisponibil. Va rugam incercati din nou in cateva minute."; break; case "DUBLA": $status = false; $messages = "Codul inserat a fost deja inregistrat."; break; case "CORECT": break; case "INCORECT": $status = false; $messages = "Codul inserat nu este valid."; break; case "PREMIU": break; case "ACCESDENIED": $status = false; $messages = "Serviciu indisponibil."; } if ($status == false) { return response()->json(['status' => "ERROR", 'data' => "", 'messages' => $messages]); } $code = new Code(); $code->id_user = $this->userService->user()->id; $code->code = $request->input('code'); $code->save(); $validCode = true; } if ($request->input('dream') != null) { $dream = new Dream(); $dream->id_user = $this->userService->user()->id; $dream->content = $request->input('dream'); $dream->save(); $validDream = true; } } else { $messages = $validator->messages()->all(); return response()->json(['status' => "ERROR", 'data' => "", 'messages' => $messages]); } if ($validCode) { $message = "Cod validat."; } elseif ($validDream) { $message = "Vis salvat."; } \Mail::send('emails.validCode', ['validDream' => $validDream, 'validCode' => $validCode, 'user' => $this->userService->user()], function ($message) { $message->from('*****@*****.**', 'Avon'); $message->to($this->userService->user()->email, $this->userService->user()->email)->subject('Competitie Avon!'); }); return response()->json(['status' => "OK", 'data' => "", 'messages' => $message]); }