public function registerAction()
 {
     $request = $this->getRequest();
     $data = $this->getFormFields('register');
     if ($request->isMethod('POST')) {
         $data = $request->all();
         $userModel = new UserModel($this->getDatabase());
         $user = $userModel->findByName($request->getPost('username'));
         if ($user) {
             // the username is taken
             $data['error'] = 'The username has been taken, please choose different one';
         } else {
             // the username is available, register a new user
             $user = $request->all();
             $user['id'] = $userModel->addUser($user);
             $this->getSession()->set('user', $user);
             $this->redirect('/welcome');
         }
     }
     return $this->render('register', $data);
 }