public function store(Request $request) { //get the email and password from the input $email = ""; $password = ""; if ($request->get('email') && $request->get('password')) { $password = $request->get('password'); if (Libraries\InputValidator::isEmailValid($request->get('email'))) { $email = $request->get('email'); } else { \App::abort(400, 'The contract of the api was not met'); } } else { \App::abort(400, 'The contract of the api was not met'); } //get the user based on the email $userRepo = new UserRepository(new User()); $user = $userRepo->getUserBasedOnEmail($email)->toArray(); //fill the information of the user //if the user didn't exist $userInfo = []; if ($user == []) { $userInfo = ["email" => $email, "password" => sha1($password), "uuid" => \Rhumsaa\Uuid\Uuid::uuid4()->toString()]; } else { \App::abort(409, 'The email is already in use'); } //update the information of the user $user = $userRepo->updateUserInfo($userInfo); $userRepo->setUserLevel(1); $userRepo->logSignUp(); //send the results back to the user return json_encode(["status" => ["points" => $userRepo->getUserPoints(), "level" => $userRepo->getUserLevel()->id], "user_id" => $user->uuid, "email" => $email, "password" => sha1($password)]); }
public function update(Request $request, $user) { $userRepo = new UserRepository(); if ($user == -1) { \App::abort(404, 'The API doesn\'t exist'); } else { if ($user == -2) { \App::abort(500, 'cluster point didn\'t reply'); } } $result = []; if ($request->get('full_name') && $request->get('about') && $request->get('languages')) { $user["full_name"] = $request->get('full_name'); $user["about"] = $request->get('about'); $languages = json_decode($request->get('languages')); $result = $userRepo->updateUserInfo($user, $languages); } else { \App::abort(400, 'The contract of the api was not met'); } return json_encode($result); }