public function signUp(Request $request, Response $response, $args) { $this->logger->info("SignUp page action dispatched"); $uri = $request->getUri(); if ($request->getMethod() == 'POST') { $data = $request->getParsedBody(); $v = new $this->validator($data); $v->lang('es'); $v->rule('required', array('email', 'username', 'password', 'company')); if ($v->validate()) { try { $this->logger->info("Signup with parameters: " . $data['email'] . " - " . $data['username'] . " - " . $data['password'] . " - " . $data['company']); $newUser = new User(); $newUser->setUsername($data['username']); $newUser->setEmail($data['email']); $newUser->setPassword($data['password']); $newUser->signUp(); if ($newUser != null && $newUser->isAuthenticated()) { $result = ParseCloud::run('addUserToRole', ['roleName' => 'Manager'], false); $this->logger->info("User added to Manager Role? " . $result); $company = new Company(); $company->setName($data['company']); $company->save(); $this->flash->addMessage('info', 'Sample flash message'); return $response->withStatus(302)->withHeader('Location', $uri->withPath('')); } } catch (ParseException $e) { ParseErrorHandler::handleParseError($e); $this->flash->addMessage('error', $e->getMessage()); return $response->withStatus(302)->withHeader('Location', $uri->withPath('signup')); } } foreach ($v->errors() as $field => $errors) { foreach ($errors as $error) { $this->flash->addMessage('error', $error); } } return $response->withStatus(302)->withHeader('Location', $uri->withPath('signup')); } // Get Messages $messages = $this->flash->getMessages(); // Fetch Template $body = $this->view->fetch('login/signup.twig', ['flash' => $messages]); // Write Response return $response->write($body); }
public function storeCompany() { if (Input::has('companyId')) { $rules = ['companyName' => 'required']; } else { $rules = ['companyName' => 'required |unique:company']; } $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } else { if (Input::has('companyId')) { $companyId = Input::get('companyId'); $company = CompanyModel::find($companyId); $company->companyName = Input::get('companyName'); $company->typeId = Input::get('type'); $company->phone = Input::get('phone'); $company->email = Input::get('email'); $company->website = Input::get('website'); $company->mainPeopleId = Input::get('mainPeople'); $company->save(); $alert['type'] = 'success'; $alert['msg'] = "Company has been updated successfully"; return Redirect::route('user.company.editCompany', $companyId)->with('alert', $alert); } else { $company = new CompanyModel(); $company->companyName = Input::get('companyName'); $company->typeId = Input::get('type'); $company->phone = Input::get('phone'); $company->email = Input::get('email'); $company->website = Input::get('website'); $company->mainPeopleId = Input::get('mainPeople'); $company->save(); $alert['type'] = 'success'; $alert['msg'] = "Company has been saved successfully"; return Redirect::route('user.company.addCompany')->with('alert', $alert); } } }