Exemplo n.º 1
0
 public function registraceAction()
 {
     if (!isset($this->logged->nick)) {
         $form = new RegisterForm();
         $request = $this->getRequest();
         if ($request->isPost()) {
             $register = new User();
             $register->setInputs(['nick', 'heslo', 'email']);
             $form->setInputFilter($register->getInputFilter());
             $form->setData($request->getPost());
             if ($form->isValid()) {
                 if ($form->getData()['heslo'] == $form->getData()['heslo_repeat']) {
                     $table = $this->getUserTable();
                     $data = array('nick' => $form->getData()['nick'], 'heslo' => $form->getData()['heslo'], 'email' => $form->getData()['email']);
                     $register->exchangeArray($data);
                     $bool = $table->register($register);
                     if ($bool === true) {
                         $this->logged->nick = $register->nick;
                         $this->logged->admin = 0;
                         // redirect
                     } else {
                         if ($bool == 'nick') {
                             $error = $this->msg->get('login.error.nickUsed', ['nick' => $data['nick']]);
                         } else {
                             if ($bool == 'email') {
                                 $error = $this->msg->get('login.error.emailUsed', ['email' => $data['email']]);
                             } else {
                                 $error = $this->msg->get('other.error.unknownError');
                             }
                         }
                     }
                 } else {
                     $error = $this->msg->get('login.error.passwordsNotMatching');
                 }
             } else {
                 $error = $this->msg->get('form.error.invalidData');
             }
         }
         return array('form' => $form, 'error' => isset($error) ? $error : null, 'menu' => new Menu($this->url()->fromRoute("application"), array("login", "registrace", "obnovit" => "zapomenuté heslo"), "registrace"));
     } else {
         return $this->redirect()->toRoute('application/default', array('controller' => 'profil'));
     }
 }
Exemplo n.º 2
0
 public function indexAction()
 {
     $this->getServiceLocator()->get('ViewHelperManager')->get('HeadTitle')->set('Encontre Barato: Tenha chances de ganhar um Iphone todo mês');
     $form = new UserForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $data = $request->getPost();
         $form->setData($data);
         if ($form->isValid()) {
             try {
                 $user = new User();
                 $user->exchangeArray($data);
                 $this->getUserTable()->saveUser($user);
                 return new ViewModel(['form' => $form, 'success' => 'Cadastro efetuado com sucesso']);
             } catch (Exception $ex) {
                 return new ViewModel(['form' => $form, 'error' => $ex->getMessage()]);
             }
         }
     }
     return new ViewModel(['form' => $form]);
 }
    public function indexAction()
    {
        $form = new RegisterForm();
        $request = $this->getRequest();
        if ($request->isPost()) {
            // Initializing User Model
            $user = new User();
            // Getting Data Posted
            $data = $request->getPost();
            $form->setInputFilter($user->getInputFilter());
            $form->setData($data);
            $sm = $this->getServiceLocator();
            $appArray = $sm->get('Config')['app'];
            $appId = base64_decode($data->appId);
            //var_dump($form->isValid());
            if (array_key_exists($appId, $appArray)) {
                if ($form->isValid()) {
                    if ($this->getUserTable()->isUniqueEmail($data->email)) {
                        $crypt = new Crypt();
                        $output = $crypt->encryptArrayResponse($data->email);
                        $from = '*****@*****.**';
                        $email = $data->email;
                        $assunto = 'Ativação Conta MarkSend';
                        $activationLink = $appArray[$appId]['url'] . 'user/activate/' . urlencode(base64_encode($output));
                        $mensagem = <<<EOD
                            <a href='{$activationLink}'>{$activationLink}</a>
EOD;
                        $ses = new SimpleEmailService('AKIAIX32JUETXGGVTYGA', '1/D6IFvP6VAs3yKsqTsh7l179nj7m5PBogwAYc23');
                        //cria uma nova instancia
                        $m = new SimpleEmailServiceMessage();
                        //seta valores definidos nas variaveis acima
                        $m->addTo($email);
                        $m->setFrom($from);
                        $m->setSubjectCharset('ISO-8859-1');
                        $m->setMessageCharset('ISO-8859-1');
                        $m->setSubject('=?UTF-8?B?' . base64_encode($assunto) . '?= ');
                        $m->setMessageFromString(NULL, $mensagem);
                        //envia email
                        $ses->sendEmail($m);
                        $user->exchangeArray($data);
                        $saveUser = $this->getUserTable()->saveUser($user);
                        if ($saveUser > 0) {
                            //Salvou
                            $response = array('success' => true);
                        } else {
                            //Deu algo errado e nao salvou =/
                            $response = array('success' => false, 'errorCode' => '1', 'message' => 'Not saved');
                        }
                    } else {
                        //Email ja Cadastrado
                        $response = array('success' => false, 'errorCode' => '2', 'message' => 'Email already register');
                    }
                } else {
                    // Form Invalido
                    $response = array('success' => false, 'errorCode' => '3', 'message' => 'Invalid Form');
                }
                $crypt = new Crypt();
                $output = $crypt->encryptArrayResponse($response);
            } else {
                //throw new \Exception('Invalid AppId');
                $crypt = new Crypt();
                $output = $crypt->encryptArrayResponse('deu ruim hein');
            }
        }
        $url = $appArray[$appId]['url'] . 'register/?q=' . $output;
        return $this->redirect()->toUrl($url);
    }