public function testGetDisplayNameConcatsFirstAndLastNameIfNotSet()
 {
     $user = new User();
     $user->setFirstName('test');
     $user->setLastName('user');
     $this->assertEquals('test user', $user->getDisplayName());
 }
 public function addUser(\auth\model\User $newUser)
 {
     try {
         $userName = $newUser->getUserName();
         $passwordHash = $newUser->getPasswordHash();
         $isAdmin = $newUser->getIsAdmin();
         $sql = "INSERT INTO " . $this->table . "(user_name, password_hash, is_admin) VALUES( :userName, :passwordHash, :isAdmin)";
         $params = array(":userName" => $userName, ":passwordHash" => $passwordHash, ":isAdmin" => $isAdmin);
         return $this->query($sql, $params, true);
     } catch (\Exception $e) {
         throw $e;
     }
 }
 public function addUserAction()
 {
     $this->auth();
     $userTable = new UserTable($this->getServiceLocator()->get('dbAdapter'));
     $request = $this->getRequest();
     $form = new UserForm();
     $form->setInputFilter(new UserFilter());
     $form->setData($request->getPost());
     if (!$form->isValid()) {
         $users = $userTable->fetchAll();
         $model = new ViewModel(array('error' => true, 'form' => $form, 'users' => $users));
         $model->setTemplate('admin/admin/users');
         return $model;
     }
     $data = $form->getData();
     $user = new User();
     $user->exchangeArray($data);
     $userTable->saveUser($user);
     return $this->redirect()->toUrl('/admin/users');
 }
 public function signupAction()
 {
     $request = $this->getRequest();
     $view = new ViewModel();
     $signUpForm = new SignUpForm('signupForm');
     $signUpForm->setInputFilter(new SignUpFilter());
     if ($request->isPost()) {
         $user = new User();
         $data = $request->getPost();
         $signUpForm->setData($data);
         if ($signUpForm->isValid()) {
             $userPassword = new UserPassword();
             $encyptPass = $userPassword->create($data['password']);
             $user->exchangeArray($signUpForm->getData());
             $user->password = $encyptPass;
             //Debug::dump($user);
             $this->getUserTable()->saveUser($user);
             $this->getAuthService()->getAdapter()->setIdentity($data['email'])->setCredential($encyptPass);
             $result = $this->getAuthService()->authenticate();
             if ($result->isValid()) {
                 $session = new Container('User');
                 $session->offsetSet('email', $data['email']);
                 $this->flashMessenger()->addMessage(array('success' => 'Login Success.'));
                 // Redirect to page after successful login
             } else {
                 $this->flashMessenger()->addMessage(array('error' => 'invalid credentials.'));
                 // Redirect to page after login failure
             }
             return $this->redirect()->tourl('/TPWeb/public/album');
             // Logic for login authentication
         } else {
             $errors = $signUpForm->getMessages();
             //prx($errors);
         }
     }
     $view->setVariable('signupForm', $signUpForm);
     return $view;
 }
 public function testSaveWithOutIdDoesInsertId()
 {
     $modelData = array('email' => '', 'firstName' => '', 'lastName' => '', 'displayName' => '');
     $mapper = new Mapper();
     $mapper->setCollection(new MongoCollectionMock($modelData));
     $model = new User();
     $model->setData($modelData);
     $mapper->save($model);
     $this->assertEquals('testId', $model->getId());
 }