예제 #1
0
파일: LoginAction.php 프로젝트: EpykOS/eelh
 public function logout(Request $request, Response $response, $args)
 {
     $this->logger->info("Login page action dispatched");
     $uri = $request->getUri();
     try {
         $this->userRepository->logOut();
         $this->currentUser = $this->userRepository->getCurrentUser();
         ParseClient::getStorage()->set('company', null);
     } catch (ParseException $e) {
         ParseErrorHandler::handleParseError($e);
     }
     return $response->withStatus(302)->withHeader('Location', $uri->withPath('login'));
 }
예제 #2
0
 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);
 }