Example #1
0
    function registerAction()
    {
        $user = new Application_Model_User();
        $this->view->form = new Application_Form_Register();
        if ($this->_request->isPost()) {
            Zend_Loader::loadClass('Zend_Filter_StripTags');
            $filter = new Zend_Filter_StripTags();
            $name = trim($filter->filter($this->_request->getPost('name')));
            $pass = trim($filter->filter($this->_request->getPost('pass')));
            $email = trim($filter->filter($this->_request->getPost('email')));
            $pass = md5($pass);
            $userRow = $user->fetchRow($user->select()->where('name = ?', $name));
            //$userArray = $userRow->toArray();
            if ($userRow != '') {
                echo "User name already exist";
            } else {
                $userRow = $user->fetchRow($user->select()->where('email = ?', $email));
                //$userArray = $userRow->toArray();
                if ($userRow != '') {
                    echo "Email already exist";
                } else {
                    if ($this->view->form->isValid($this->getRequest()->getPost())) {
                        $hash = md5(microtime());
                        $mail = new Zend_Mail();
                        $mail->setBodyText('Hello 
						Your email regisrated on website spitfire.mydev.org.ua 
						to confirm your account click link bellow
						http://spitfire.mydev.org.ua/register/confirmuser/&hash=<');
                        $mail->setFrom('*****@*****.**', 'Some Sender');
                        $mail->addTo('*****@*****.**', 'Some Sender');
                        $mail->setSubject('TestSubject');
                        $mail->send();
                        if ($name != '' && $pass != '') {
                            $data = array('name' => $name, 'email' => $email, 'pass' => $pass);
                            $user->insert($data);
                            $this->_redirect('/');
                            return;
                        }
                    } else {
                        echo "Captcha wrong";
                    }
                }
            }
        }
    }
Example #2
0
 function changepermissionAction()
 {
     $this->view->title = "Change user permission";
     $user = new Application_Model_User();
     $id = (int) $this->_request->getParam('id');
     $userRow = $user->fetchRow($user->select()->where('id = ?', $id));
     $userArray = $userRow->toArray();
     if ($userArray['permission'] == 0) {
         $insertValue = "1";
     }
     if ($userArray['permission'] == 1) {
         $insertValue = "0";
     }
     $data = array('permission' => $insertValue);
     $where = 'id = ' . $id;
     $user->update($data, $where);
     $this->_redirect('/users');
     return;
 }
Example #3
0
 function adminLoginAction()
 {
     $this->view->title = "Login";
     $form = new Application_Form_UserLoginForm();
     $this->view->form = $form;
     // Post and validation section
     if (!$this->_request->isPost()) {
         return;
     }
     $formData = $this->_request->getPost();
     if (!$form->isValid($formData)) {
         return;
     }
     $email = $formData['email'];
     $password = $formData['password'];
     //$password  = md5($formData['password']);
     $this->authAdapter->setTableName('users')->setIdentityColumn('email')->setCredentialColumn('pwd')->setIdentity($email)->setCredential($password);
     $auth = Zend_Auth::getInstance();
     $result = $this->authAdapter->authenticate();
     if ($result->isValid()) {
         $data = $this->authAdapter->getResultRowObject(null, 'pwd');
         $auth->getStorage()->write($data);
         //fetch user info
         $user = new Application_Model_User();
         $select = $user->select(array('user_id', 'user_name'))->where('email = ?', $email);
         $row = $user->fetchRow($select);
         $this->user_session = new Zend_Session_Namespace('user_session');
         // default namespace
         $this->user_session->user_name = $row->user_name;
         $this->user_session->user_id = $row->user_id;
         $this->_redirect('/admin/index');
     } else {
         $this->view->msg = "<div class='alert alert-danger'> Invalid User Name or Passowrd </div>";
         $this->view->form = $form;
     }
 }