public static function map(User $user, array $properties) { if (array_key_exists('userId', $properties)) { $user->setUserId($properties['userId']); } if (array_key_exists('password', $properties)) { $user->setPassword($properties['password']); } if (array_key_exists('name', $properties)) { $user->setName($properties['name']); } if (array_key_exists('gender', $properties)) { $user->setGender($properties['gender']); } if (array_key_exists('telephone', $properties)) { $user->setTelephone($properties['telephone']); } if (array_key_exists('email', $properties)) { $user->setEmail($properties['email']); } if (array_key_exists('avatar', $properties)) { $user->setAvatar($properties['avatar']); } if (array_key_exists('slogan', $properties)) { $user->setSlogan($properties['slogan']); } if (array_key_exists('birthday', $properties)) { $user->setBirthday($properties['birthday']); } if (array_key_exists('createdAt', $properties)) { $tempCreatedAt = DateTransform::createDate($properties['createdAt']); if ($tempCreatedAt) { $user->setCreatedAt($tempCreatedAt); } } if (array_key_exists('character', $properties)) { $user->setCharacter($properties['character']); } }
}); //GET route $app->get('/setup', function () use($app) { disable_cache($app); if (DatawrapperSession::getUser()->isLoggedIn() || UserQuery::create()->filterByRole(array('admin', 'sysadmin'))->count() > 0) { $app->redirect('/'); } $page = array('title' => 'Datawrapper', 'pageClass' => 'setup', 'noHeader' => true, 'noFooter' => true, 'noSignup' => true, 'auth_salt' => DW_AUTH_SALT); add_header_vars($page, ''); $app->render('setup.twig', $page); }); /* * endpoint for final setup script */ $app->post('/setup', function () use($app) { $data = json_decode($app->request()->getBody()); // check that there is no admin user yet (only true right after setup) if (UserQuery::create()->count() == 0) { $user = new User(); $user->setCreatedAt(time()); $user->setEmail($data->email); $user->setRole('admin'); $user->setPwd(secure_password($data->pwd)); $user->setLanguage(DatawrapperSession::getLanguage()); $user->save(); DatawrapperSession::login($user); $app->redirect('/'); } else { print json_encode(array('status' => 'fail')); } });
public function testGetAndSetCreatedAt() { $now = time(); $this->user->setCreatedAt($now); $this->assertEquals($now, $this->user->getCreatedAt()); }
public function insert(User $user) { $user->setCreatedAt(new DateTime()); $sql = 'insert into user(userId, password, name, gender, telephone, email, avatar, slogan, birthday, createdAt, character)' . ' values(:userId, :password, :name, :gender, :telephone, :email, :avatar, :slogan, :birthday, :createdAt, :character)'; return $this->execute($sql, $user); }