public function processAction()
 {
     if (!$this->request->isPost()) {
         return $this->redirect()->toRoute(NULL, array('controller' => 'user-manager', 'action' => 'index'));
     }
     // Get User ID from POST
     $post = $this->request->getPost();
     $id = $this->params()->fromRoute('id');
     if ($id) {
         $userTable = $this->getServiceLocator()->get('UserTable');
         // Load User entity
         $userData = $userTable->getUser($id);
         // Bind User entity to Form
         $form = $this->getServiceLocator()->get('UserEditForm');
         //ovde postavlja stare podatke user
         $form->bind($userData);
         //ovde zamazuje stare tj.difoltne koje smopodeili u prethodnom korakuiz post
         //var_dump($post->users_password);exit;
         $form->setData($post);
     }
     //unset($post->users_password);
     // Save user
     $user = new User();
     $user->exchangeArray($post);
     if ($id) {
         $user->password = $post->users_password;
     }
     $this->getServiceLocator()->get('UserTable')->saveUser($user);
     return $this->redirect()->toRoute('user-manager/default', array('controller' => 'user-manager', 'action' => 'index'));
 }
 protected function createUser(array $data)
 {
     $user = new User();
     $user->exchangeArray($data);
     $userTable = $this->getServiceLocator()->get('UserTable');
     $userTable->save($user);
     return true;
 }
 protected function createUser(array $data)
 {
     $sm = $this->getServiceLocator();
     $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
     $resultSetPrototype = new \Zend\Db\ResultSet\ResultSet();
     $resultSetPrototype->setArrayObjectPrototype(new \Users\Model\User());
     $tableGateway = new \Zend\Db\TableGateway\TableGateway('user', $dbAdapter, null, $resultSetPrototype);
     $user = new User();
     $user->exchangeArray($data);
     $userTable = new UserTable($tableGateway);
     $userTable->saveUser($user);
     return true;
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  *
  * Convert an array into a User object
  */
 public function hydrate($value)
 {
     var_dump($value);
     if (is_string($value)) {
         $value = json_decode($value, true);
     }
     $value = (array) $value;
     if (is_array($value)) {
         $keyword = new User();
         $keyword->setId($value['id']);
         $keyword->setUsername($value['username']);
         $keyword->setRole($value['role']);
     }
     return $keyword;
 }
 public function addAction()
 {
     $error = false;
     $form = $this->getServiceLocator()->get('UserAddForm');
     if ($this->request->isPost()) {
         $post = $this->request->getPost();
         $userTable = $this->getServiceLocator()->get('UserTable');
         $form->bind($post);
         $form->setData($post);
         if ($form->isValid()) {
             $user = new User();
             $user->exchangeArray($post);
             $userTable->saveUser($user);
             $this->_redirectTo('index');
             return true;
         } else {
             $error = true;
         }
     }
     return new ViewModel(array('form' => $form, 'error' => $error));
 }
Beispiel #6
0
 public static function update_password($password, $user_id)
 {
     $user = null;
     if (ctype_digit($user_id)) {
         $user = \Users\Model\User::find($user_id);
     }
     if (!is_null($user) and !empty($user)) {
         $hashed_password = \Users\Helper::hash_password($password);
         $user->hash = $hashed_password['hash'];
         $user->salt = $hashed_password['salt'];
         $user->password = \Hash::make($password);
         $user->save();
         \Event::fire('users.updated', array($user));
         return true;
     }
     return false;
 }
 public function adduserAction()
 {
     $this->userTable = $this->getServiceLocator()->get('UserTable');
     $authResponse = $this->getAuthService()->getStorage()->read();
     $this->layout()->setVariable('auth', $authResponse);
     $Config = $this->getServiceLocator()->get('Config');
     $this->layout('layout/dashboard');
     $AddUserForm = new AddUserForm();
     $AddUserForm->get('permission')->setValueOptions($Config["user_permission"]);
     $this->layout()->setVariable('auth', $authResponse);
     // get form request methord.
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = $this->request->getPost();
         $email = $post["email"];
         $usersDetail = $this->userTable->getActiveUserByEmail($email);
         $inputFilter = new AddUserFilter();
         $AddUserForm->setInputFilter($inputFilter);
         $AddUserForm->setData($post);
         if (!$AddUserForm->isValid() || isset($usersDetail->user_id)) {
             if (isset($usersDetail->user_id)) {
                 $AddUserForm->setMessages(array('email' => array("This email is already registered with us.")));
             }
             if ($post->password !== $post->confirm_password) {
                 $AddUserForm->setMessages(array('confirm_password' => array("Password not matched.")));
             }
         } else {
             $user = new User();
             $FormUserData = $AddUserForm->getData();
             $result = array_merge($FormUserData, array("client_id" => $authResponse["user_id"]));
             $user->exchangeArray($result);
             $this->userTable->addUser($user);
             $lastInsertUserID = $this->userTable->lastInsertValue;
             $this->userTable->userPermissionSet($lastInsertUserID, $post["permission"]);
             //insert user permission table
             $this->renderer = $this->getServiceLocator()->get('ViewRenderer');
             $mailcontent = $this->renderer->render('mails/AddUser', null);
             $encryptedresetlink = base64_encode("{$lastInsertUserID}|" . time());
             $this->userTable->usertokeninsert($lastInsertUserID, $encryptedresetlink);
             //insert into token table  encryped data
             $ResetLink = "http://{$_SERVER["SERVER_NAME"]}/user/activate/{$encryptedresetlink}";
             $tokenKeyValues = array('#USERNAME#' => $user->fname, "#CREATELINK#" => $ResetLink);
             $msgSubject = "Create Account successfully please follow the instruction to activate account";
             $this->SendMail()->SendMailSmtp($user->email, $msgSubject, $mailcontent, $tokenKeyValues);
             $this->flashMessenger()->setNamespace('info')->addMessage('Email is send to your email id for activation');
             return $this->redirect()->toRoute("manageuser", array('controller' => 'users', 'action' => 'adduser'));
         }
     }
     $model = new ViewModel(array('form' => $AddUserForm));
     return $model;
 }
Beispiel #8
0
 public function resetAction()
 {
     $this->userTable = $this->getServiceLocator()->get('UserTable');
     $this->layout('layout/register');
     $ResetForm = new ResetForm();
     $token = $this->params()->fromRoute('param') ? $this->params()->fromRoute('param') : '';
     list($user_id, $datetime) = explode("|", base64_decode(trim($token)));
     $isValidinterval = $this->UsersCommonFuncions()->CheckDatetimeRange($datetime);
     if (!$isValidinterval) {
         $this->flashMessenger()->setNamespace('info')->addMessage('Your link get expired');
         return $this->redirect()->toRoute(NULL, array('controller' => 'users', 'action' => 'login'));
     }
     $request = $this->getRequest();
     $resultToken = $this->userTable->IsTokenAvalibleForUser($token, $user_id);
     if (!$resultToken->user_id) {
         $this->flashMessenger()->setNamespace('warning')->addMessage("Invalid token");
         return $this->redirect()->toRoute(NULL, array('controller' => 'users', 'action' => 'login'));
     }
     if ($resultToken->status == 0) {
         $this->flashMessenger()->setNamespace('info')->addMessage("User is not activated, So you can not reset password");
         return $this->redirect()->toRoute(NULL, array('controller' => 'users', 'action' => 'login'));
     }
     if ($request->isPost()) {
         $post = $this->request->getPost();
         $password = $post->password;
         $confirm_password = $post->confirm_password;
         $post = $this->request->getPost();
         $inputFilter = new ResetFilter();
         $ResetForm->setInputFilter($inputFilter);
         $ResetForm->setData($post);
         if (!$ResetForm->isValid()) {
         } else {
             $post->user_id = $user_id;
             $user = new User();
             $user->exchangeArray($post);
             // Update user Password
             $this->getUserTable()->resetpassword($user);
             $this->flashMessenger()->setNamespace('info')->addMessage("Your password is updated successfully");
             return $this->redirect()->toRoute(NULL, array('controller' => 'users', 'action' => 'login'));
         }
     }
     $view = new ViewModel(array("form" => $ResetForm, "param" => $token));
     $view->setTemplate('users/users/resetpassword');
     return $view;
 }
Beispiel #9
0
 public function validate_send_email($attribute, $value, $parameters)
 {
     $this->language = ADM_LANG;
     $this->messages['send_email'] = '';
     $this->attributes['email_list'] = array();
     // check for specific users
     if (!isset($this->attributes['only_emails']) or empty($this->attributes['only_emails'])) {
         // there is no specific user selected
         // lets get all user using the filter
         $status = $this->attributes['status'];
         $group = $this->attributes['group'];
         //  if not isset group or status
         //  lets get all users
         $users = \Users\Model\User::select('*');
         if (isset($group) and $group != '0' and !empty($group)) {
             $users->where('group_id', '=', $group);
         }
         if (isset($status) and $status != '0' and !empty($status)) {
             $users->where('status', '=', $status);
         }
         $users = $users->get(array('email', 'avatar_first_name', 'avatar_last_name'));
         if (isset($users) and !empty($users)) {
             foreach ($users as $user) {
                 $this->attributes['email_list'][] = $user->email;
             }
         }
     } else {
         //we got some users selected
         foreach ($this->attributes['only_emails'] as $email) {
             $this->attributes['email_list'][] = $email;
         }
     }
     // check for custom emails
     $custom_emails = $this->attributes['alt_emails'];
     if (isset($custom_emails) and !empty($custom_emails)) {
         $email_tmp_list = explode(',', $custom_emails);
         if (is_array($email_tmp_list) and !empty($email_tmp_list)) {
             foreach ($email_tmp_list as $email) {
                 $email = trim($email);
                 if (!empty($email)) {
                     $this->attributes['email_list'][] = $email;
                 }
             }
         }
     }
     //keep just unique values
     $this->attributes['email_list'] = array_unique($this->attributes['email_list']);
     if (!empty($this->attributes['email_list'])) {
         //validate if all emails are valid
         foreach ($this->attributes['email_list'] as $email) {
             $passed = $this->validate_email($this->attributes['subject'], $email);
             if (!$passed) {
                 \Session::flash('message', __('email::lang.The email :email is invalid', array('email' => $email))->get(ADM_LANG));
                 \Session::flash('message_type', 'error');
                 return false;
             }
         }
     } else {
         // we dont have any email to send
         \Session::flash('message', __('email::lang.Please provide at least one email as recepient for this message')->get(ADM_LANG));
         \Session::flash('message_type', 'error');
         return false;
     }
     $template_id = $this->attributes['template'];
     if ($template_id == 0) {
         // This is a custom message
         //
         //check subject
         $passed = $this->validate_required($this->attributes['subject'], $this->attributes['subject']);
         if (!$passed) {
             $this->errors->add('subject', __('validation.required', array('attribute' => __('email::lang.Subject')->get(ADM_LANG)))->get(ADM_LANG));
             return false;
         }
         //check email type
         $passed = $this->validate_required($this->attributes['email_type'], $this->attributes['email_type']);
         if (!$passed) {
             $this->errors->add('email_type', __('validation.required', array('attribute' => __('email::lang.Email Type')->get(ADM_LANG)))->get(ADM_LANG));
             return false;
         }
         // check for email body
         $passed = $this->validate_required($this->attributes['email_body'], $this->attributes['email_body']);
         if (!$passed) {
             $this->errors->add('email_body', __('validation.required', array('attribute' => __('email::lang.Body')->get(ADM_LANG)))->get(ADM_LANG));
             return false;
         }
         return true;
         // $passed;
     } else {
         // This message is using template
         //
         $template = \Email\Model\Template::find($template_id);
         if (!isset($template) or empty($template)) {
             \Session::flash('message', __('email::lang.Selected email template is invalid')->get(ADM_LANG));
             \Session::flash('message_type', 'false');
             return false;
         }
         // All templates should have this information
         $this->attributes['subject'] = $template->subject;
         $this->attributes['email_type'] = $template->type;
         $this->attributes['email_body'] = $template->body;
         return true;
     }
     return false;
 }